2021-01-26 10:56:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-02-05 15:39:11 +01:00
|
|
|
const { prop, isNil } = require('lodash/fp');
|
2021-01-26 10:56:33 +01:00
|
|
|
|
|
|
|
// retrieve a local service
|
|
|
|
const getService = name => {
|
|
|
|
return prop(`i18n.services.${name}`, strapi.plugins);
|
|
|
|
};
|
|
|
|
|
2021-02-08 15:42:38 +01:00
|
|
|
const setDefaultLocale = async locales => {
|
2021-02-05 15:39:11 +01:00
|
|
|
if (isNil(locales)) {
|
|
|
|
return locales;
|
|
|
|
}
|
|
|
|
|
|
|
|
const actualDefault = await strapi
|
|
|
|
.store({
|
|
|
|
environment: '',
|
|
|
|
type: 'plugin',
|
|
|
|
name: 'i18n',
|
|
|
|
})
|
|
|
|
.get({ key: 'default_locale' });
|
|
|
|
|
|
|
|
if (Array.isArray(locales)) {
|
|
|
|
return locales.map(locale => ({ ...locale, isDefault: actualDefault === locale.code }));
|
|
|
|
} else {
|
|
|
|
// single locale
|
|
|
|
return { ...locales, isDefault: actualDefault === locales.code };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-26 10:56:33 +01:00
|
|
|
module.exports = {
|
|
|
|
getService,
|
2021-02-08 15:42:38 +01:00
|
|
|
setDefaultLocale,
|
2021-01-26 10:56:33 +01:00
|
|
|
};
|