Lens app source code (#119)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2020-03-15 09:52:02 +02:00
1 parent 936cbd53d4
commit 1d0815abd2
797 files changed
+73714 -215

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
import { observable, reaction } from "mobx";
import { setupI18n } from "@lingui/core";
import { autobind, createStorage } from "./utils";
import orderBy from "lodash/orderBy"
import moment from "moment";
import "moment/locale/ru";
import "moment/locale/fi";
export interface ILanguage {
code: string;
title: string;
nativeTitle: string;
}
export const _i18n = setupI18n({
missing: (message, id) => {
console.warn('Missing localization:', message, id);
return id;
}
});
@autobind()
export class LocalizationStore {
readonly defaultLocale = "en"
@observable activeLang = this.defaultLocale;
public languages: ILanguage[] = orderBy<ILanguage>([
{ code: "en", title: "English", nativeTitle: "English" },
{ code: "ru", title: "Russian", nativeTitle: "Русский" },
// { code: "fi", title: "Finnish", nativeTitle: "Suomi" },
], "title");
constructor() {
const storage = createStorage("lang_ui", this.defaultLocale);
this.activeLang = storage.get();
reaction(() => this.activeLang, lang => storage.set(lang));
}
async init() {
await this.setLocale(this.activeLang);
}
async load(locale: string) {
const catalog = await import(
/* webpackMode: "lazy", webpackChunkName: "locale/[request]" */
`@lingui/loader!../locales/${locale}/messages.po`
);
return _i18n.load(locale, catalog);
}
async setLocale(locale: string) {
await this.load(locale);
await _i18n.activate(locale);
// set moment's locale before activeLang for proper next render() in app
moment.locale(locale);
this.activeLang = locale;
}
}
export const i18nStore = new LocalizationStore();