1 import i18n from 'i18next';
2 import LanguageDetector from 'i18next-browser-languagedetector';
3 import moment from 'moment';
4 import numeral from 'numeral';
5 import { initReactI18next } from 'react-i18next';
9 import 'numeral/locales/de';
10 import 'moment/locale/de';
12 const supportedLocales = [
17 const resolveLocale = (loc) => {
18 if (supportedLocales.includes(loc)) return loc;
19 const sub = loc.substr(0, 2);
20 if (supportedLocales.includes(sub)) return sub;
25 .use(LanguageDetector)
26 .use(initReactI18next)
27 .on('languageChanged', (lng) => {
28 const loc = resolveLocale(lng);
36 format: (value, format) => {
37 if (value instanceof Date) return moment(value).format(format);
45 supportedLngs: supportedLocales,
48 i18n.number = (value, options) => {
49 const num = numeral(value);
50 if (Number.isNaN(num.value())) {
53 const format = options && Object.prototype.hasOwnProperty.call(options, 'decimals')
54 ? `0,0.${'0'.repeat(options.decimals)}`
56 return num.format(format);