Last active
July 26, 2016 01:29
-
-
Save wyqydsyq/e7e98bb19ca31021a70c7d192ed80123 to your computer and use it in GitHub Desktop.
Translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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')) | |
]); | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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