From 1ba91a57f0331778f2abae975e88e27cdfd4c5e1 Mon Sep 17 00:00:00 2001
From: Steffen Kolmer i18n-tag-schema can also be used to export translation keys into a simple json format (See Additional Features). This can be useful if you want to import your translation keys into a 3rd party tool. (Other export formats might be added later. Pull requests are welcome!) This module does include a JSON validator that helps you keep track of missing or invalid keys in your translation files and shows you the current translation coverage of your project. A translation file is considered valid if it covers 100% of the translation keys defined in the JSON schema. This feature can be integrated into an automated build pipeline to check the translation coverage of a build. It can also be used to write unit tests that fail if your modules are not fully translated. /* example 2 **/
- import i18n from 'es2015-i18n-tag'
- const groupName = 'common'
- const example2 = i18n(groupName) /* example 3 */
- import { i18nGroup } from 'es2015-i18n-tag'
- const groupName = 'common'
- @i18nGroup(groupName) // ⚠️ will not be detected. variables as groupName params are currently not supported.
- class example3 {
- }
- @i18nGroup('common') // ✔️ this group name will be detected by i18n-tag-schema.
- class example3b {
- } You cannot use variables for grouping. If you are using Some IDEs can also provide auto completion for translation keys and groups This library has support for custom preprocessors. It ships with a typescript preprocessor out of the box. Please make sure Custom preprocessors can be added as npm packages📄 Table of Contents
+
🗂 Overview
⚠️ Known Limitations
-
-
- ``js
-/***** example 1 ******/
-import _i18n from 'es2015-i18n-tag'
-const i18n = _i18n('common')
-const example1 = i18n
test` // ⚠️ i18n-tag-schema will not detect the "common" group.test
// ⚠️ will not be detected. variables as groupName params are currently not supported.
- const example2b = i18n('common')test
// ✔️ this group name will be detected by i18n-tag-schema.* you have to use `i18n` as name for your `es2015-i18n-tag` import
-```js
-/***** example 1 ******/
-import t from 'es2015-i18n-tag'
-const example1 = t`test` // ⚠️ will not be detected. i18n as a tag name is currently required.
+
`test` // ✔️ this will be detected by i18n-tag-schema.
-/***** example 1 ******/
+import _i18n from 'es2015-i18n-tag'
+const i18n = _i18n('common')
+const example1 = i18n`test` // ⚠️ i18n-tag-schema will not detect the "common" group.
/***** example 2 ******/
import i18n from 'es2015-i18n-tag'
-const example2 = i18n
📦 Installation
+const groupName = 'common'
+const example2 = i18n(groupName)`test` // ⚠️ will not be detected. variables as groupName params are currently not supported.
+const example2b = i18n('common')`test` // ✔️ this group name will be detected by i18n-tag-schema.
+
+/***** example 3 *****/
+import { i18nGroup } from 'es2015-i18n-tag'
+const groupName = 'common'
+@i18nGroup(groupName) // ⚠️ will not be detected. variables as groupName params are currently not supported.
+class example3 {
+}
+@i18nGroup('common') // ✔️ this group name will be detected by i18n-tag-schema.
+class example3b {
+}
+
+ 📦 Installation
$ npm install i18n-tag-schema --save-dev
💻 Examples
@@ -155,6 +147,12 @@ 💻 Examples
🎩 Key detection for i18n.translate()
+ i18n.translate()
to translate variables you can add comments telling i18n-tag-schema the possible values of your variables.
+ The comment should be a string
or string[]
in valid JSON syntax.i18n.translate(myVariable1 /* "possible value ${0}" */, 'expression value')
+i18n.translate(myVariable2 /* ["possible value 1", "another value"] */)
+
📒 Usage
import { generateTranslationSchema } from 'i18n-tag-schema'
@@ -249,7 +247,7 @@
✔️ Validation Rules
⚙ Preprocessors
typescript
npm package is installed if you want to parse typescript code.$ i18n-tag-schema ./src -e ./typescript.ts -p ./preprocessors/typescript -f \.ts
+
$ i18n-tag-schema ./src -e ./typescript.ts -p ./preprocessors/typescript -f \.ts
$ npm install my-preprocessor --save-dev
$ i18n-tag-schema ./src -e ./file.myext -p my-preprocessor -f \.myext
@@ -257,10 +255,10 @@
⚙ Preprocessors
An example can be found at ./lib/preprocessors/typescript.js
This library has support for custom postprocessors that can be used to transform the export file format. It ships with a PO file format postprocessor out of the box.
-$ i18n-tag-schema ./src -e . -o ./postprocessors/po -t ./translation.po
+ $ i18n-tag-schema ./src -e . -o ./postprocessors/po -t ./translation.po
Custom postprocessors can be added as npm packages
- $ npm install my-postprocessor --save-dev
-$ i18n-tag-schema ./src -e . -o my-postprocessor -t ./translation.myext
+ $ npm install my-postprocessor --save-dev
+$ i18n-tag-schema ./src -e . -o my-postprocessor -t ./translation.myext
A postprocessor is a function that receives an array of translation keys and groups as an argument and returns the processed output.
An example can be found at ./lib/postprocessors/po.js
⌨ IDE Integration