import 'moment/locale/zh-cn';
import 'moment/locale/fr';
import 'moment/locale/sv';
-import { getLanguage } from '../utils';
+import { getMomentLanguage } from '../utils';
import { i18n } from '../i18next';
interface MomentTimeProps {
constructor(props: any, context: any) {
super(props, context);
- // Moment doesnt have zh, only zh-cn
- let lang = getLanguage();
- if (lang == 'zh') {
- lang = 'zh-cn';
- }
+ let lang = getMomentLanguage();
moment.locale(lang);
}
}
}
-export function getLanguage() {
+export function getLanguage(): string {
return (navigator.language || navigator.userLanguage);
}
+
+export function getMomentLanguage(): string {
+ let lang = getLanguage();
+ if (lang.startsWith('zh')) {
+ lang = 'zh-cn';
+ } else if (lang.startsWith('sv')) {
+ lang = 'sv';
+ } else if (lang.startsWith('fr')) {
+ lang = 'fr';
+ } else {
+ lang = 'en';
+ }
+ return lang;
+}