Side effect middleware idea
parent
aa1bde57bd
commit
d00d7fbd98
|
@ -18,7 +18,10 @@ export function getUserLang(langCode = "en_us") {
|
|||
|
||||
export function generateI18nConfig(lang: string): InitOptions {
|
||||
// NOTE: Some users prefer English over i18nized version.
|
||||
const choice = Session.deprecatedGetBool(BooleanSetting.disable_i18n) ? "en" : lang;
|
||||
console.log("Change this back!");
|
||||
// const choice = Session.deprecatedGetBool(BooleanSetting.disable_i18n) ? "en" : lang;
|
||||
const choice =
|
||||
Session.deprecatedGetBool(BooleanSetting.disable_i18n) ? "en" : "es";
|
||||
const langi = require("../public/app-resources/languages/" + choice + ".js");
|
||||
|
||||
return {
|
||||
|
@ -30,4 +33,4 @@ export function generateI18nConfig(lang: string): InitOptions {
|
|||
}
|
||||
|
||||
export const detectLanguage =
|
||||
() => getUserLang(navigator.language).then(generateI18nConfig);
|
||||
(lang = navigator.language) => getUserLang(lang).then(generateI18nConfig);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import { Middleware } from "redux";
|
||||
import { Actions } from "../constants";
|
||||
|
||||
const fn: Middleware = (store) => (next) => (action: any) {
|
||||
if (action.type === Actions.RESOURCE_READY) {
|
||||
console.log("HMMMM " + action.payload.name);
|
||||
}
|
||||
return next(action);
|
||||
};
|
||||
|
||||
export const idea = { fn, env: "*" };
|
|
@ -0,0 +1,9 @@
|
|||
import { detectLanguage } from "./i18n";
|
||||
import * as I18n from "i18next";
|
||||
|
||||
function revertToEnglish() {
|
||||
detectLanguage("en").then(x => {
|
||||
x.lng = "en";
|
||||
I18n.init(x, () => console.log("Should be in Russian now."));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue