File tree 1 file changed +19
-5
lines changed
1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Gettext translator
2
+
2
3
Javascript gettext translator. Use [ gettext/gettext] ( https://github.com/oscarotero/Gettext ) PHP library to generate and modify the messages.
3
4
4
5
Supports:
@@ -7,35 +8,48 @@ Supports:
7
8
* CommonJS
8
9
* Global js
9
10
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
+
10
25
## Usage
11
26
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 :
13
28
14
29
``` php
15
30
use Gettext\Translations;
16
31
17
- //Scan the po file with the translations
32
+ //Load the po file with the translations
18
33
$translations = Translations::fromPoFile('locales/gl.po');
19
34
20
35
//Export to a json file
21
36
$translations->toJsonFile('locales/gl.json');
22
37
```
23
38
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
25
40
26
41
``` js
27
42
var Translator = require (' gettext-translator' );
28
43
var translations = require (' locales/gl.json' );
29
44
30
45
var i18n = new Translator (translations);
31
46
32
-
33
47
console .log (i18n .gettext (' hello world' )); // ola mundo
34
48
```
35
49
36
50
## Sprintf
37
51
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... :
39
53
40
54
``` js
41
55
i18n .__ (' Hello %s' , ' world' ); // Hello world
You can’t perform that action at this time.
0 commit comments