Commit bed3b650 by Andrey Golubov

Правка путей и eff

parent d76b1caf
import * as eff from '~/common/eff'; import { defaultLocale, localeCacheKey, localeDecoder, locales } from '../../../config';
import { Ctx as TranslationCtx, Translations } from '~/common/gettext'; import * as eff from '../../eff';
import { Cache as LocalStorage } from '~/common/persistent'; import { Ctx as TranslationCtx, Translations } from '../../gettext';
import * as bcp47 from '~/common/utils/bcp47'; import { Cache as LocalStorage } from '../../persistent';
import { defaultLocale, localeCacheKey, localeDecoder, localePath, locales } from '~/config'; import * as bcp47 from '../../utils/bcp47';
import { Async, LocalStorageError, TranslationLoadError } from '../error'; import { Async, LocalStorageError, TranslationLoadError } from '../error';
export const defaultTranslations: Translations = { "locale_data" : { "messages" : { "" : { "domain": "messages", "lang": "en", "plural_forms" : "nplurals=2; plural=(n != 1);" } } }, "domain" : "messages", "debug" : false }
export type Locale = typeof localeDecoder['_A']; export type Locale = typeof localeDecoder['_A'];
export type Locales = Locale[]; export type Locales = Locale[];
...@@ -14,8 +15,12 @@ export const cache = new LocalStorage<Locale>(localeCacheKey, localeDecoder); ...@@ -14,8 +15,12 @@ export const cache = new LocalStorage<Locale>(localeCacheKey, localeDecoder);
* @param locale вариант перевода из `Locales` * @param locale вариант перевода из `Locales`
*/ */
export function loadTranslations(locale: Locale): Async<Translations> { export function loadTranslations(locale: Locale): Async<Translations> {
const translations: Translations | undefined = require(`${localePath('~')}${locale}.po`); try {
const translations: Translations | undefined = require(`../../../i18n/${locale}.po`);
return translations ? eff.success(translations) : eff.failure(TranslationLoadError(locale)); return translations ? eff.success(translations) : eff.failure(TranslationLoadError(locale));
} catch(e) {
return eff.of(defaultTranslations);
}
} }
/** /**
* Возвращает подходящую локаль из `window.navigator.languages` или `defaultLocale` * Возвращает подходящую локаль из `window.navigator.languages` или `defaultLocale`
......
import * as Rx from 'rxjs'; import * as Rx from 'rxjs';
import { defaultRoute, parser } from '~/config'; import { defaultRoute, parser } from '../../../config';
import * as eff from '../../eff'; import * as eff from '../../eff';
import { IO } from '../../types'; import { IO } from '../../types';
...@@ -28,7 +28,9 @@ export function print(route: RouteIn): string { ...@@ -28,7 +28,9 @@ export function print(route: RouteIn): string {
*/ */
export const routeStream = new Rx.Subject<RouteOut[]>(); export const routeStream = new Rx.Subject<RouteOut[]>();
window.onpopstate = (() => { routeStream.next(parseLocation(window.location)); }); try {
window.onpopstate = (() => { routeStream.next(parseLocation(window.location)); });
} catch(e) { console.warn('Run in node'); }
export function routePush(route: RouteIn, title: string = ''): IO<void> { export function routePush(route: RouteIn, title: string = ''): IO<void> {
window.history.pushState(null, title, print(route)); window.history.pushState(null, title, print(route));
......
...@@ -177,7 +177,7 @@ export function batch<A,B,C,D,E,F,G,H,I,J>(a: Cmd<A>, b: Cmd<B>, c: Cmd<C>, d: C ...@@ -177,7 +177,7 @@ export function batch<A,B,C,D,E,F,G,H,I,J>(a: Cmd<A>, b: Cmd<B>, c: Cmd<C>, d: C
export function batch<array extends Cmd<any>[]>(signals: array): Cmd<array[number]['_T']['_R']>; export function batch<array extends Cmd<any>[]>(signals: array): Cmd<array[number]['_T']['_R']>;
export function batch(): Cmd<any> { export function batch(): Cmd<any> {
const observables = Array.isArray(arguments[0]) ? arguments[0] : arguments; const observables = Array.isArray(arguments[0]) ? arguments[0] : arguments;
return Rx.merge.apply(undefined, observables); return Rx.merge.apply(undefined, observables) as any;
} }
...@@ -197,7 +197,7 @@ export function concat<A,B,C,D,E,F,G,H,I,J>(a: Cmd<A>, b: Cmd<B>, c: Cmd<C>, d: ...@@ -197,7 +197,7 @@ export function concat<A,B,C,D,E,F,G,H,I,J>(a: Cmd<A>, b: Cmd<B>, c: Cmd<C>, d:
export function concat<array extends Cmd<any>[]>(signals: array): Cmd<array[number]['_T']['_R']>; export function concat<array extends Cmd<any>[]>(signals: array): Cmd<array[number]['_T']['_R']>;
export function concat(): Cmd<any> { export function concat(): Cmd<any> {
const observables = Array.isArray(arguments[0]) ? arguments[0] : arguments; const observables = Array.isArray(arguments[0]) ? arguments[0] : arguments;
return Rx.concat.apply(undefined, observables); return Rx.concat.apply(undefined, observables) as any;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment