Skip to content

Instantly share code, notes, and snippets.

@wyqydsyq
Last active July 26, 2016 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyqydsyq/e7e98bb19ca31021a70c7d192ed80123 to your computer and use it in GitHub Desktop.
Save wyqydsyq/e7e98bb19ca31021a70c7d192ed80123 to your computer and use it in GitHub Desktop.
Translate
// assuming your render component recieves a stream called selectedTargets$ that emits an object of the source/target languages you're translating
const vtree$ = sources.translate$.debug().map(translation =>
div('#registrationScreeenPage.panel.contentTop.active', [
div(translation('foo'))
]);
);
import {MemoryStream} from 'xstream';
import {HTTPSource} from '@cycle/http';
export type Sources = {
HTTP: HTTPSource
};
export type Sinks = {
translate$: MemoryStream<(key: string) => string>
};
export function translations(sources: Sources): Sinks {
const translate$ = sources.HTTP
.select('translations')
.flatten()
.startWith({body: 'nada'})
.map((res: any) => (key) => (typeof res.body[key] != 'undefined') ? res.body[key] : res.body);
return {
translate$: translate$
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment