Skip to content

Commit

Permalink
Use country map json instead of the provided functions (#366)
Browse files Browse the repository at this point in the history
* Use country map json instead of the provided functions

* Fix error when langCode is not a valid alpha2
  • Loading branch information
Duddino authored May 7, 2024
1 parent ea2ade7 commit a13822b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './i18n.js';
import { Database } from './database.js';
import { getEventEmitter } from './event_bus.js';
import { getCurrencyByAlpha2 } from 'country-locale-map';
import countries from 'country-locale-map/countries.json';

// --- Default Settings
/** A mode that emits verbose console info for internal MPW operations */
Expand All @@ -34,7 +34,10 @@ export let strCurrency = getDefaultCurrency();
*/
function getDefaultCurrency() {
const langCode = navigator.languages[0]?.split('-')?.at(-1) || 'US';
return getCurrencyByAlpha2(langCode)?.toLowerCase() || 'usd';
return (
countries.find((c) => c.alpha2 === langCode)?.currency?.toLowerCase() ||
'usd'
);
}

/** The user-selected explorer, used for most of MPW's data synchronisation */
Expand Down

0 comments on commit a13822b

Please sign in to comment.