MobX Translate
Installation:
npm install mobx-translate --save
Usage
First, create interface for your translations:
widget: HELLO BYE }
Then, define your strings. With code completion for keys, and full Mustache template support in values:
; const EN:TranslationKeys = list: HEADING: 'Available jobs' MORE: 'More' widget: HELLO: 'Hello {{name}}' BYE: 'Bye {{name}}' const DE:TranslationKeys = list: HEADING: "Verfügbare Berufe" MORE: "Mehr" widget: HELLO: "Gutten tag {{name}}" BYE: "Auf wiedersehn {{name}}"
Initialize MobxTranslate, pass your translations interface as a generic:
;; ;; const translateInstance = <TranslationKeys>; translateInstance;translateInstance;translateInstance; const trans = translateInstance;
And then easily switch languages and translate strings in React components. Again, with code completion for translation keys!:
;; ; @observerComponent<{} {}> { return <div className="container"> <h1>transkeywidget</h1> <button onClick=transsetLanguage>EN</button> <button onClick=transsetLanguage>DE</button> <h1>transkeylist</h1> </div> }