Commit bed3b650 by Andrey Golubov

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

parent d76b1caf
import * as eff from '~/common/eff';
import { Ctx as TranslationCtx, Translations } from '~/common/gettext';
import { Cache as LocalStorage } from '~/common/persistent';
import * as bcp47 from '~/common/utils/bcp47';
import { defaultLocale, localeCacheKey, localeDecoder, localePath, locales } from '~/config';
import { defaultLocale, localeCacheKey, localeDecoder, locales } from '../../../config';
import * as eff from '../../eff';
import { Ctx as TranslationCtx, Translations } from '../../gettext';
import { Cache as LocalStorage } from '../../persistent';
import * as bcp47 from '../../utils/bcp47';
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 Locales = Locale[];
......@@ -14,8 +15,12 @@ export const cache = new LocalStorage<Locale>(localeCacheKey, localeDecoder);
* @param locale вариант перевода из `Locales`
*/
export function loadTranslations(locale: Locale): Async<Translations> {
const translations: Translations | undefined = require(`${localePath('~')}${locale}.po`);
return translations ? eff.success(translations) : eff.failure(TranslationLoadError(locale));
try {
const translations: Translations | undefined = require(`../../../i18n/${locale}.po`);
return translations ? eff.success(translations) : eff.failure(TranslationLoadError(locale));
} catch(e) {
return eff.of(defaultTranslations);
}
}
/**
* Возвращает подходящую локаль из `window.navigator.languages` или `defaultLocale`
......
import * as Rx from 'rxjs';
import { defaultRoute, parser } from '~/config';
import { defaultRoute, parser } from '../../../config';
import * as eff from '../../eff';
import { IO } from '../../types';
......@@ -28,7 +28,9 @@ export function print(route: RouteIn): string {
*/
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> {
window.history.pushState(null, title, print(route));
......
......@@ -8,7 +8,7 @@ import { combineAll } from 'rxjs/internal/operators/combineAll';
import { Expr } from '../types';
/**
/**
* Тайп-алиасы для удобства
*/
export type Eff<Error, Success> = Observable<Either<Error, Success>>;
......@@ -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(): Cmd<any> {
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:
export function concat<array extends Cmd<any>[]>(signals: array): Cmd<array[number]['_T']['_R']>;
export function concat(): Cmd<any> {
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