mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
i18n: locales support fixes
This commit is contained in:
1 parent
7efc54424a
commit
b4101d986c
10 files changed
+54
-22
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+11
-4
@@ -1,8 +1,10 @@
|
||||
import moment from "moment";
|
||||
import { observable, reaction } from "mobx";
|
||||
import { setupI18n } from "@lingui/core";
|
||||
import { autobind, createStorage } from "./utils";
|
||||
import orderBy from "lodash/orderBy"
|
||||
import { autobind, createStorage } from "./utils";
|
||||
|
||||
const plurals: Record<string, Function> = require('make-plural/plurals');
|
||||
|
||||
export interface ILanguage {
|
||||
code: string;
|
||||
@@ -40,17 +42,22 @@ export class LocalizationStore {
|
||||
}
|
||||
|
||||
async load(locale: string) {
|
||||
const catalog = await import(`../locales/${locale}/messages.po`);
|
||||
return _i18n.load(locale, catalog);
|
||||
const { messages } = await import(
|
||||
/* webpackChunkName: "i18n-[request]" */
|
||||
`@lingui/loader!../../locales/${locale}/messages.po`
|
||||
);
|
||||
_i18n.loadLocaleData(locale, { plurals: plurals[locale] });
|
||||
_i18n.load(locale, messages);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
await _i18n.activate(locale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,11 @@
|
||||
const path = require("path");
|
||||
|
||||
module.exports = function (config, env) {
|
||||
const {module, plugins} = config;
|
||||
const {module} = config;
|
||||
const {rules} = module;
|
||||
|
||||
// localization support
|
||||
// https://lingui.js.org/guides/typescript.html
|
||||
rules.push({
|
||||
test: /\.po$/,
|
||||
use: '@lingui/loader'
|
||||
});
|
||||
patchLoader(".tsx", "ts-loader", loader => {
|
||||
loader.options = Object.assign({}, loader.options, {
|
||||
compilerOptions: {
|
||||
@@ -43,7 +39,7 @@ module.exports = function (config, env) {
|
||||
let loader = typeof loaders[index] === "string" ? {loader: loaders[index]} : loaders[index];
|
||||
loaders[index] = updater(loader);
|
||||
rule.use = loaders.flat();
|
||||
console.info(`Patched renderer's webpack loader "${loaderName}"`, loader);
|
||||
console.info(`Patched webpack's renderer config for "${loaderName}" in ${__filename}`, loader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user