mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
'use strict';
|
|
|
|
const countries = require('i18n-iso-countries')
|
|
, countryNamesMap = countries.getNames('en')
|
|
, extraCountryCodes = ['EU', 'XX', 'T1']
|
|
, anonymizerCountryCodes = ['TOR', 'LOKI']
|
|
, anonymizerCountryCodesSet = new Set(anonymizerCountryCodes)
|
|
, countryCodes = Object.keys(countryNamesMap).concat(extraCountryCodes, anonymizerCountryCodes)
|
|
, i18n = require(__dirname+'/../locale/locale.js')
|
|
, extraCountryNames = Object.seal(Object.freeze(Object.preventExtensions({
|
|
'EU': 'Europe',
|
|
'XX': 'Unknown',
|
|
'T1': 'Tor Exit Node',
|
|
'TOR': 'Tor Hidden Service',
|
|
'LOKI': 'Lokinet SNApp',
|
|
})));
|
|
|
|
i18n.getLocales()
|
|
.forEach(locale => {
|
|
const localeExtraCodesMap = { ...extraCountryNames };
|
|
for (let code in localeExtraCodesMap) {
|
|
localeExtraCodesMap[code] = i18n.__({
|
|
phrase: localeExtraCodesMap[code],
|
|
locale: locale,
|
|
});
|
|
}
|
|
/* We are basically overwriting the existing locales in countries,
|
|
but with translated extra codes added */
|
|
countries.registerLocale({
|
|
locale,
|
|
countries: {
|
|
...countries.getNames(locale, { select: 'official' }),
|
|
...localeExtraCodesMap,
|
|
},
|
|
});
|
|
});
|
|
|
|
module.exports = {
|
|
countryCodes,
|
|
countryCodesSet: new Set(countryCodes),
|
|
getCountryNames: countries.getNames,
|
|
getCountryName: countries.getName,
|
|
isAnonymizer: (code) => {
|
|
return anonymizerCountryCodesSet.has(code);
|
|
},
|
|
};
|
|
|