2021-01-26 10:56:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const isoLocales = require('./iso-locales');
|
|
|
|
|
2021-04-20 09:41:23 +02: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'
|
2021-04-20 09:41:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...matchingLocale };
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
code: 'en',
|
|
|
|
name: 'English (en)',
|
|
|
|
};
|
2021-03-02 18:32:07 +01:00
|
|
|
};
|
|
|
|
|
2021-04-20 09:41:23 +02:00
|
|
|
const DEFAULT_LOCALE = getInitLocale();
|
|
|
|
|
2021-01-26 10:56:33 +01:00
|
|
|
module.exports = {
|
|
|
|
isoLocales,
|
2021-03-02 18:32:07 +01:00
|
|
|
DEFAULT_LOCALE,
|
2021-04-20 09:41:23 +02:00
|
|
|
getInitLocale,
|
2021-01-26 10:56:33 +01:00
|
|
|
};
|