1.1.12 • Published 4 years ago

@joaofranciscosantos/babel-plugin-i18n v1.1.12

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Install Size Npm Version License Dependencies Status Known Vulnerabilities

babel-plugin-i18n

Multi language builds with Babel. Setup a different build for each language.

:sparkles: Provide translations during compile time.

:sparkles: No need to include MB translations files in your bundle.

:sparkles: End of repetitive http request with translations.

API

i18n(text: string, language?: string) : string
  • text original text.
  • language (optional) overrides the language set by the plugin.

Setup

npm install --save-dev @joaofranciscosantos/babel-plugin-i18n

and add to .babelrc.js:

module.exports = api => ({
  plugins: [["@joaofranciscosantos/babel-plugin-i18n"]]
});

to override options:

module.exports = api => ({
  plugins: [["@joaofranciscosantos/babel-plugin-i18n", {
    source: ["translations.json", "translations/canada.json", "yo.json"],
    target: "i18n",
    language: "pt"
  }]]
});
  • source (array) the path with translations files. They will be all merged during resolution. Defaults to .dictionary.json.
  • target (string) function that will apply the translation. Defaults to i18n.
  • language (string) set the translation language. Defaults to en.

Examples

  • i18n("dog", "es") transpiles to "perro"
  • i18n("dog") transpiles to "doggy"
  • i18n("none", "?") transpiles to "none" (returns the original text because no translation was provided)

and translations files must have a similar structure:

{
  "keyword": {
    "language": "translation"
  },
  "dog": {
    "en": "doggy",
    "pt": "cão",
    "es": "perro",
    "it": "cane"
  }
}

FAQ

ReferenceError: i18n is not defined

Check your build folder. You should not see the 'i18n' function. Review your babel configuration.

TS2304: Cannot find name 'i18n'

You should declare var i18n: any;

1.1.12

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago