i18n: add flow + some cleanup
This commit is contained in:
parent
49c6559049
commit
2e50497bc1
1 changed files with 6 additions and 7 deletions
13
ui/i18n.js
13
ui/i18n.js
|
@ -1,11 +1,9 @@
|
||||||
|
// @flow
|
||||||
|
import { isLocalStorageAvailable } from 'util/storage';
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
let knownMessages = null;
|
let knownMessages = null;
|
||||||
let localStorageAvailable;
|
const localStorageAvailable = isLocalStorageAvailable();
|
||||||
try {
|
|
||||||
localStorageAvailable = Boolean(window.localStorage);
|
|
||||||
} catch (e) {
|
|
||||||
localStorageAvailable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.i18n_messages = window.i18n_messages || {};
|
window.i18n_messages = window.i18n_messages || {};
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ function removeContextMetadata(message) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function __(message, tokens) {
|
export function __(message: string, tokens: { [string]: string }) {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -53,6 +51,7 @@ export function __(message, tokens) {
|
||||||
const language = localStorageAvailable
|
const language = localStorageAvailable
|
||||||
? window.localStorage.getItem('language') || 'en'
|
? window.localStorage.getItem('language') || 'en'
|
||||||
: window.navigator.language.slice(0, 2) || 'en';
|
: window.navigator.language.slice(0, 2) || 'en';
|
||||||
|
|
||||||
if (!isProduction) {
|
if (!isProduction) {
|
||||||
saveMessageWeb(message);
|
saveMessageWeb(message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue