File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed
Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 11# Gettext translator
2+
23Javascript gettext translator. Use [ gettext/gettext] ( https://github.com/oscarotero/Gettext ) PHP library to generate and modify the messages.
34
45Supports:
@@ -7,35 +8,48 @@ Supports:
78* CommonJS
89* Global js
910
11+ ## Installation
12+
13+ Using bower:
14+
15+ ```
16+ bower install gettext-translator
17+ ```
18+
19+ Using npm:
20+
21+ ```
22+ npm install gettext-translator
23+ ```
24+
1025## Usage
1126
12- Use the Json generator of the [ gettext/gettext] ( https://github.com/oscarotero/Gettext ) library:
27+ Use the Json generator of the [ gettext/gettext] ( https://github.com/oscarotero/Gettext ) library to export the translations to json :
1328
1429``` php
1530use Gettext\Translations;
1631
17- //Scan the po file with the translations
32+ //Load the po file with the translations
1833$translations = Translations::fromPoFile('locales/gl.po');
1934
2035//Export to a json file
2136$translations->toJsonFile('locales/gl.json');
2237```
2338
24- Load the json file in your javascript (for example, using webpack) and use it
39+ Load the json file in your browser (for example, using webpack) and use it
2540
2641``` js
2742var Translator = require (' gettext-translator' );
2843var translations = require (' locales/gl.json' );
2944
3045var i18n = new Translator (translations);
3146
32-
3347console .log (i18n .gettext (' hello world' )); // ola mundo
3448```
3549
3650## Sprintf
3751
38- This library includes [ sprintf] ( https://github.com/alexei/sprintf.js ) dependency implemented in the short methods:
52+ This library includes [ sprintf] ( https://github.com/alexei/sprintf.js ) dependency implemented in the short methods like ` __ ` , ` n__ ` , etc... :
3953
4054``` js
4155i18n .__ (' Hello %s' , ' world' ); // Hello world
You can’t perform that action at this time.
0 commit comments