parent
13a3ae85c2
commit
c69f1722ac
2 changed files with 17 additions and 7 deletions
|
@ -4,7 +4,7 @@ import * as moment from 'moment';
|
||||||
import 'moment/locale/zh-cn';
|
import 'moment/locale/zh-cn';
|
||||||
import 'moment/locale/fr';
|
import 'moment/locale/fr';
|
||||||
import 'moment/locale/sv';
|
import 'moment/locale/sv';
|
||||||
import { getLanguage } from '../utils';
|
import { getMomentLanguage } from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
|
||||||
interface MomentTimeProps {
|
interface MomentTimeProps {
|
||||||
|
@ -20,11 +20,7 @@ export class MomentTime extends Component<MomentTimeProps, any> {
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
|
||||||
// Moment doesnt have zh, only zh-cn
|
let lang = getMomentLanguage();
|
||||||
let lang = getLanguage();
|
|
||||||
if (lang == 'zh') {
|
|
||||||
lang = 'zh-cn';
|
|
||||||
}
|
|
||||||
|
|
||||||
moment.locale(lang);
|
moment.locale(lang);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,20 @@ export function debounce(func: any, wait: number = 500, immediate: boolean = fal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLanguage() {
|
export function getLanguage(): string {
|
||||||
return (navigator.language || navigator.userLanguage);
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue