diff --git a/package.json b/package.json index ea8f7cd7b7ff3..b67921a571a98 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "dependencies": { "@elastic/datemath": "2.3.0", "@elastic/filesaver": "1.1.2", - "@elastic/numeral": "2.2.1", + "@elastic/numeral": "2.3.0", "@elastic/test-subj-selector": "0.2.1", "@elastic/ui-ace": "0.2.3", "JSONStream": "1.1.1", diff --git a/src/core_plugins/kibana/common/field_formats/types/_numeral.js b/src/core_plugins/kibana/common/field_formats/types/_numeral.js index a042c4a1c72af..5bc00eea28f6c 100644 --- a/src/core_plugins/kibana/common/field_formats/types/_numeral.js +++ b/src/core_plugins/kibana/common/field_formats/types/_numeral.js @@ -1,8 +1,13 @@ import _ from 'lodash'; import numeral from '@elastic/numeral'; +import numeralLanguages from '@elastic/numeral/languages'; const numeralInst = numeral(); +numeralLanguages.forEach(function (numeralLanguage) { + numeral.language(numeralLanguage.id, numeralLanguage.lang); +}); + export function createNumeralFormat(FieldFormat, opts) { class NumeralFormat extends FieldFormat { static id = opts.id; @@ -11,7 +16,6 @@ export function createNumeralFormat(FieldFormat, opts) { constructor(params, getConfig) { super(params); - this.getConfig = getConfig; } @@ -34,8 +38,14 @@ export function createNumeralFormat(FieldFormat, opts) { if (isNaN(val)) return ''; + const previousLocale = numeral.language(); + const defaultLocale = this.getConfig && this.getConfig('format:number:defaultLocale') || 'en'; + numeral.language(defaultLocale); + const formatted = numeralInst.set(val).format(this.param('pattern')); + numeral.language(previousLocale); + return opts.afterConvert ? opts.afterConvert.call(this, formatted) : formatted; diff --git a/src/core_plugins/kibana/ui_setting_defaults.js b/src/core_plugins/kibana/ui_setting_defaults.js index 46cd81f1a234c..783bd0e4696fa 100644 --- a/src/core_plugins/kibana/ui_setting_defaults.js +++ b/src/core_plugins/kibana/ui_setting_defaults.js @@ -1,8 +1,12 @@ import moment from 'moment-timezone'; +import numeralLanguages from '@elastic/numeral/languages'; export function getUiSettingDefaults() { const weekdays = moment.weekdays().slice(); const [defaultWeekday] = weekdays; + const numeralLanguageIds = numeralLanguages.map(function (numeralLanguage) { + return numeralLanguage.id; + }); // wrapped in provider so that a new instance is given to each app/test return { @@ -237,6 +241,12 @@ export function getUiSettingDefaults() { value: '($0,0.[00])', description: 'Default numeral format for the "currency" format' }, + 'format:number:defaultLocale': { + value: 'en', + type: 'select', + options: numeralLanguageIds, + description: 'numeral language' + }, 'savedObjects:perPage': { type: 'number', value: 5,