@green-code-studio/internationalization
v1.2.8
Published
```bash npm install @green-code-studio/internationalization # OR yarn add @green-code-studio/internationalization ```
Downloads
164
Readme
This library provides ability to load translations of your application to different languages.
Instalaltion
npm install @green-code-studio/internationalization
# OR
yarn add @green-code-studio/internationalizationFeatures
- all texts in one file - you can see all versions of one text in one place
- language hierarchy - you can translate to some languages only partially, and then specify in which order lib shouyld search for
- tree structure of texts
- compatibility with the php library (the same xml file readed both on frontend and backend)
Examples
Text file
<?xml version="1.0" encoding="utf-8"?>
<root>
<node name="Documents">
<value lang="pl">Dokumenty</value>
<value lang="en">Documents</value>
<value lang="de">Dokumente</value>
<node name="Add">
<value lang="pl">Dodaj dokument</value>
<value lang="en">Add document</value>
<value lang="de">Dokument hinzufügen</value>
</node>
<node name="Edit">
<value lang="pl">Edytuj dokument</value>
<value lang="en">Edit document</value>
<value lang="de">Dokument bearbeiten</value>
</node>
</node>
</root>in webpack
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /i18n\.xml$/,
use: ["@green-code-studio/internationalization/i18nWebpackLoader"]
}
]
}
};and the you can use it like this:
import {node, translator, t} from "./path/to/i18n.xml"; //remember to confirure loader
console.log(t('Documents.Add')); // will print "Add document" or translation according to current languagein node.js
import {loadXmlFile} from "@green-code-studio/internationalization"
const {node, translator, t}= loadXmlFile("path/to/i18n.xml");
console.log(t('Documents.Add')); // will print "Add document" or translation according to current language