Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Type-Safe i18n on RN

Type-Safe i18n on RN

@hotchemi

June 22, 2018
Tweet

More Decks by @hotchemi

Other Decks in Programming

Transcript

  1. • It’s OK, but... • key name can be long

    and nested • gotta move around definition and code • can’t detect an error in compile time • “missing [key name] translation”
  2. • quipper/react-native-i18n-ts • paired with TypeScript • inspired by R.java

    mechanism • strong IDE support • compile time check
  3. declare module "react-native-i18n" { var fallbacks: boolean; var translations: {

    [keys: string]: any; }; function t(key: "common.cancel", opts: { value: any; }): string; function t(key: "common.ok"): string; } // for json loading declare module "*.json" { const value: any; export default value; }
  4. • Installation • yarn add -D react-native-i18n-ts • set “model”

    and “outputDir” in package.json • tweak filesGlob in tsconfig.json • execute “yarn i18n-ts” command