UNPKG

qwc2-lts

Version:
48 lines (47 loc) 1.57 kB
/** * Copyright 2015 GeoSolutions Sas * Copyright 2016-2024 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import StandardApp from '../components/StandardApp'; import ConfigUtils from './ConfigUtils'; var LocaleUtils = { tr: function tr(key) { var state = StandardApp.store.getState(); var text = key in state.locale.messages ? state.locale.messages[key] || state.locale.fallbackMessages[key] || key : key; var args = Array.prototype.slice.call(arguments, 1); if (args.length > 0) { return text.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] !== 'undefined' ? args[number] : match; }); } else { return text; } }, // Just a stub to make updateTranslations pick up the msgId trmsg: function trmsg(key) { return key; }, trWithFallback: function trWithFallback(key, fallback) { var state = StandardApp.store.getState(); return state.locale.messages[key] || fallback; }, lang: function lang() { var state = StandardApp.store.getState(); return state.locale.current; }, toLocaleFixed: function toLocaleFixed(number, decimals) { if (ConfigUtils.getConfigProp("localeAwareNumbers")) { return number.toLocaleString(LocaleUtils.lang(), { minimumFractionDigits: decimals, maximumFractionDigits: decimals }); } else { return number.toFixed(decimals); } } }; export default LocaleUtils;