mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Add i18n default locale as a configurable item
Adds 'defaultLocale' configurable item to the i18n plugin configuration. The default locale is used for translations if the locale specified by user is not supported. This commit satisfies the review comment: - https://github.com/elastic/kibana/pull/7545#discussion-diff-74669970
This commit is contained in:
parent
da669da2e5
commit
9064e8a7e6
3 changed files with 19 additions and 5 deletions
|
@ -97,3 +97,7 @@
|
|||
# Set the interval in milliseconds to sample system and process performance
|
||||
# metrics. Minimum is 100ms. Defaults to 5000.
|
||||
#ops.interval: 5000
|
||||
|
||||
# The default locale to use for translations if the locale specified by user
|
||||
# is not supported
|
||||
# i18n.locale: "en"
|
||||
|
|
|
@ -2,6 +2,14 @@ import i18n from './server/i18n/i18n';
|
|||
|
||||
export default function (kibana) {
|
||||
return new kibana.Plugin({
|
||||
id: 'i18n',
|
||||
config: function (Joi) {
|
||||
return Joi.object({
|
||||
enabled: Joi.boolean().default(true),
|
||||
locale: Joi.string().default('en')
|
||||
}).default();
|
||||
},
|
||||
|
||||
init(server, options) {
|
||||
server.expose('getRegisteredLocaleTranslations', i18n.getRegisteredLocaleTranslations);
|
||||
server.expose('getRegisteredTranslationLocales', i18n.getRegisteredTranslationLocales);
|
||||
|
|
|
@ -45,6 +45,8 @@ export default async (kbnServer, server, config) => {
|
|||
if (bundle) bundles.add(bundle);
|
||||
}
|
||||
|
||||
const defaultLocale = config.get('i18n.locale');
|
||||
|
||||
// render all views from the ui/views directory
|
||||
server.setupViews(resolve(__dirname, 'views'));
|
||||
|
||||
|
@ -141,18 +143,18 @@ function translate(key) {
|
|||
return kibanaTranslations[key];
|
||||
}
|
||||
|
||||
function getTranslationLocale(acceptLanguages, server) {
|
||||
function getTranslationLocale(acceptLanguages, defaultLocale, server) {
|
||||
let localeStr = '';
|
||||
|
||||
if (acceptLanguages === null || acceptLanguages.length <= 0) {
|
||||
return DEFAULT_LOCALE;
|
||||
return defaultLocale;
|
||||
}
|
||||
const registeredLocales = server.plugins.i18n.getRegisteredTranslationLocales();
|
||||
localeStr = getTranslationLocaleExactMatch(acceptLanguages, registeredLocales);
|
||||
if (localeStr != null) {
|
||||
return localeStr;
|
||||
}
|
||||
localeStr = getTranslationLocaleBestCaseMatch(acceptLanguages, registeredLocales);
|
||||
localeStr = getTranslationLocaleBestCaseMatch(acceptLanguages, registeredLocales, defaultLocale);
|
||||
}
|
||||
|
||||
function getTranslationLocaleExactMatch(acceptLanguages, registeredLocales) {
|
||||
|
@ -173,7 +175,7 @@ function getTranslationLocaleExactMatch(acceptLanguages, registeredLocales) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function getTranslationLocaleBestCaseMatch(acceptLanguages, registeredLocales) {
|
||||
function getTranslationLocaleBestCaseMatch(acceptLanguages, registeredLocales, defaultLocale) {
|
||||
let localeStr = '';
|
||||
|
||||
const acceptLangsLen = acceptLanguages.length;
|
||||
|
@ -188,5 +190,5 @@ function getTranslationLocaleBestCaseMatch(acceptLanguages, registeredLocales) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return DEFAULT_LOCALE;
|
||||
return defaultLocale;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue