i18n: add flow + some cleanup

This commit is contained in:
infinite-persistence 2021-12-31 08:37:06 +08:00
parent 49c6559049
commit 2e50497bc1
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -1,11 +1,9 @@
// @flow
import { isLocalStorageAvailable } from 'util/storage';
const isProduction = process.env.NODE_ENV === 'production';
let knownMessages = null;
let localStorageAvailable;
try {
localStorageAvailable = Boolean(window.localStorage);
} catch (e) {
localStorageAvailable = false;
}
const localStorageAvailable = isLocalStorageAvailable();
window.i18n_messages = window.i18n_messages || {};
@ -45,7 +43,7 @@ function removeContextMetadata(message) {
return message;
}
export function __(message, tokens) {
export function __(message: string, tokens: { [string]: string }) {
if (!message) {
return '';
}
@ -53,6 +51,7 @@ export function __(message, tokens) {
const language = localStorageAvailable
? window.localStorage.getItem('language') || 'en'
: window.navigator.language.slice(0, 2) || 'en';
if (!isProduction) {
saveMessageWeb(message);
}