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';
8 import 'numeral/locales/de';
9 import 'moment/locale/de';
11 const supportedLocales = [
15 const resolveLocale = (loc) => {
16 if (supportedLocales.includes(loc)) return loc;
17 const sub = loc.substr(0, 2);
18 if (supportedLocales.includes(sub)) return sub;
23 .use(LanguageDetector)
24 .use(initReactI18next)
25 .on('languageChanged', (lng) => {
26 const loc = resolveLocale(lng);
34 format: (value, format) => {
35 if (value instanceof Date) return moment(value).format(format);
42 supportedLngs: supportedLocales,
45 i18n.number = (value, options) => {
46 const num = numeral(value);
47 if (Number.isNaN(num.value())) {
50 const format = options && Object.prototype.hasOwnProperty.call(options, 'decimals')
51 ? `0,0.${'0'.repeat(options.decimals)}`
53 return num.format(format);