mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 11:27:19 +08:00
introduced some locale fixes
This commit is contained in:
+5
-1
@@ -5,7 +5,7 @@ import EventEmitter from 'eventemitter2';
|
||||
import { createReduxEmitter } from './events';
|
||||
import { createRestClient } from './rest';
|
||||
import thunk from 'redux-thunk';
|
||||
import { loadTranslations } from './i18n';
|
||||
import { setupTranslations, loadTranslations } from './i18n';
|
||||
import bowser from 'bowser';
|
||||
import noop from 'lodash/noop';
|
||||
import { BASE_PATH } from 'coral-framework/constants/url';
|
||||
@@ -88,6 +88,10 @@ export async function createContext({
|
||||
const pymStorage = createPymStorage(pym);
|
||||
const history = createHistory(BASE_PATH);
|
||||
const introspection = createIntrospection(introspectionData);
|
||||
|
||||
// Setup the translation framework with the storage.
|
||||
setupTranslations(storage);
|
||||
|
||||
let store = null;
|
||||
const token = () => {
|
||||
// Try to get the token from localStorage. If it isn't here, it may
|
||||
|
||||
@@ -3,6 +3,8 @@ import has from 'lodash/has';
|
||||
import get from 'lodash/get';
|
||||
import merge from 'lodash/merge';
|
||||
|
||||
import { createStorage } from 'coral-framework/services/storage';
|
||||
|
||||
import moment from 'moment';
|
||||
import 'moment/locale/da';
|
||||
import 'moment/locale/es';
|
||||
@@ -38,25 +40,34 @@ const translations = {
|
||||
let lang;
|
||||
let timeagoInstance;
|
||||
|
||||
function setLocale(locale) {
|
||||
function setLocale(storage, locale) {
|
||||
try {
|
||||
localStorage.setItem('locale', locale);
|
||||
if (storage) {
|
||||
storage.setItem('locale', locale);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
function getLocale() {
|
||||
return (
|
||||
localStorage.getItem('locale') ||
|
||||
navigator.language ||
|
||||
defaultLanguage
|
||||
).split('-')[0];
|
||||
function getLocale(storage) {
|
||||
try {
|
||||
const locale = (
|
||||
(storage && storage.getItem('locale')) ||
|
||||
navigator.language ||
|
||||
defaultLanguage
|
||||
).split('-')[0];
|
||||
|
||||
return locale;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
const locale = getLocale();
|
||||
setLocale(locale);
|
||||
export function setupTranslations(storage) {
|
||||
const locale = getLocale(storage);
|
||||
setLocale(storage, locale);
|
||||
|
||||
// Setting moment
|
||||
moment.locale(locale);
|
||||
@@ -113,5 +124,3 @@ export function t(key, ...replacements) {
|
||||
}
|
||||
|
||||
export default t;
|
||||
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user