mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
Merge branch 'master' into close-asset-now
This commit is contained in:
@@ -9,6 +9,8 @@ import 'moment/locale/es';
|
|||||||
import 'moment/locale/fr';
|
import 'moment/locale/fr';
|
||||||
import 'moment/locale/pt-br';
|
import 'moment/locale/pt-br';
|
||||||
|
|
||||||
|
import { createStorage } from 'coral-framework/services/storage';
|
||||||
|
|
||||||
import daTA from 'timeago.js/locales/da';
|
import daTA from 'timeago.js/locales/da';
|
||||||
import esTA from 'timeago.js/locales/es';
|
import esTA from 'timeago.js/locales/es';
|
||||||
import frTA from 'timeago.js/locales/fr';
|
import frTA from 'timeago.js/locales/fr';
|
||||||
@@ -38,25 +40,35 @@ const translations = {
|
|||||||
let lang;
|
let lang;
|
||||||
let timeagoInstance;
|
let timeagoInstance;
|
||||||
|
|
||||||
function setLocale(locale) {
|
function setLocale(storage, locale) {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem('locale', locale);
|
if (storage) {
|
||||||
|
storage.setItem('locale', locale);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLocale() {
|
function getLocale(storage) {
|
||||||
return (
|
try {
|
||||||
localStorage.getItem('locale') ||
|
return (
|
||||||
navigator.language ||
|
(storage && storage.getItem('locale')) ||
|
||||||
defaultLanguage
|
navigator.language ||
|
||||||
).split('-')[0];
|
defaultLanguage
|
||||||
|
).split('-')[0];
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
export function setupTranslations() {
|
||||||
const locale = getLocale();
|
// Setup the translation framework with the storage.
|
||||||
setLocale(locale);
|
const storage = createStorage();
|
||||||
|
|
||||||
|
const locale = getLocale(storage);
|
||||||
|
setLocale(storage, locale);
|
||||||
|
|
||||||
// Setting moment
|
// Setting moment
|
||||||
moment.locale(locale);
|
moment.locale(locale);
|
||||||
@@ -114,4 +126,5 @@ export function t(key, ...replacements) {
|
|||||||
|
|
||||||
export default t;
|
export default t;
|
||||||
|
|
||||||
init();
|
// Setup the translations globally as soon as this module runs.
|
||||||
|
setupTranslations();
|
||||||
|
|||||||
Reference in New Issue
Block a user