37 lines
752 B
JavaScript
Raw Normal View History

2021-01-26 10:56:33 +01:00
'use strict';
2022-08-08 23:33:39 +02:00
const isoLocales = require('./iso-locales.json');
2021-01-26 10:56:33 +01:00
/**
* Returns the default locale based either on env var or english
* @returns {string}
*/
const getInitLocale = () => {
const envLocaleCode = process.env.STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE;
if (envLocaleCode) {
const matchingLocale = isoLocales.find(({ code }) => code === envLocaleCode);
if (!matchingLocale) {
throw new Error(
2021-04-20 10:52:22 +02:00
'Unknown locale code provided in the environment variable STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE'
);
}
return { ...matchingLocale };
}
return {
code: 'en',
name: 'English (en)',
};
};
const DEFAULT_LOCALE = getInitLocale();
2021-01-26 10:56:33 +01:00
module.exports = {
isoLocales,
DEFAULT_LOCALE,
getInitLocale,
2021-01-26 10:56:33 +01:00
};