handlebars-i18n 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/readme.md +25 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handlebars-i18n",
|
|
3
|
-
"version": "1.6.
|
|
4
|
-
"description": "handlebars-i18n adds
|
|
3
|
+
"version": "1.6.4",
|
|
4
|
+
"description": "handlebars-i18n adds internationalization to handlebars.js using i18next and Intl",
|
|
5
5
|
"main": "dist/handlebars-i18n.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "nyc mocha",
|
|
@@ -17,16 +17,15 @@
|
|
|
17
17
|
"url": "https://github.com/aller-couleur/handlebars-i18n.git"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
|
-
"
|
|
20
|
+
"Translation",
|
|
21
|
+
"Multi-language",
|
|
21
22
|
"Internationalization",
|
|
22
23
|
"Localization",
|
|
23
24
|
"Globalization",
|
|
24
|
-
"Translation",
|
|
25
25
|
"Date Formatting",
|
|
26
26
|
"Currency Formatting",
|
|
27
27
|
"Number Formatting",
|
|
28
28
|
"Handlebars",
|
|
29
|
-
"Handlebars.js",
|
|
30
29
|
"i18next",
|
|
31
30
|
"i18n",
|
|
32
31
|
"Intl",
|
package/readme.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# handlebars-i18n
|
|
2
2
|
|
|
3
|
-
`handlebars-i18n` adds the internationalization features of [i18next](https://www.i18next.com/) to [handlebars.js](https://handlebarsjs.com/). It also provides **date**, **number**, and **currency formatting** via [Intl](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl). Use as node module or in the web browser.
|
|
3
|
+
`handlebars-i18n` adds the internationalization features of [i18next](https://www.i18next.com/) to [handlebars.js](https://handlebarsjs.com/). It also provides **date**, **number**, and **currency formatting** via [Intl](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl). Use as node module or in the web browser. Supports Typescript.
|
|
4
4
|
|
|
5
|
-
Handlebars-i18n is listed amongst i18next’s [framework helpers](https://www.i18next.com/overview/supported-frameworks).
|
|
5
|
+
Handlebars-i18n is listed amongst i18next’s [framework helpers](https://www.i18next.com/overview/supported-frameworks).
|
|
6
6
|
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|

|
|
@@ -10,14 +10,19 @@ Handlebars-i18n is listed amongst i18next’s [framework helpers](https://www.i1
|
|
|
10
10
|
[](https://coveralls.io/github/fwalzel/handlebars-i18next?branch=master)
|
|
11
11
|
[](https://codeclimate.com/github/Aller-Couleur/handlebars-i18n)
|
|
12
12
|
[](https://snyk.io/test/github/Aller-Couleur/handlebars-i18n/badge.svg)
|
|
13
|
+

|
|
13
14
|

|
|
14
15
|
|
|
15
|
-
|
|
16
16
|
## License
|
|
17
17
|
|
|
18
|
-
Copyright (c) 2020 Florian Walzel,
|
|
18
|
+
Copyright (c) 2020–24 Florian Walzel,
|
|
19
|
+
|
|
19
20
|
MIT License
|
|
20
21
|
|
|
22
|
+
If you use handlebars-i18n in a professional context, you could
|
|
23
|
+
|
|
24
|
+
[](https://www.buymeacoffee.com/fwalzel)
|
|
25
|
+
|
|
21
26
|
## Install
|
|
22
27
|
|
|
23
28
|
If you use version npm >= 7:
|
|
@@ -117,43 +122,48 @@ Finally use in template:
|
|
|
117
122
|
```
|
|
118
123
|
<p> {{__ "phrase1"}} </p>
|
|
119
124
|
```
|
|
125
|
+
|
|
120
126
|
* returns for "en" → **What is good?**
|
|
121
127
|
|
|
122
128
|
```
|
|
123
129
|
<p> {{__ "phrase2" thing=myItem}} </p>
|
|
124
130
|
```
|
|
131
|
+
|
|
125
132
|
* returns for "en" → **handlebars-i18n is good.**
|
|
126
133
|
|
|
127
134
|
```
|
|
128
135
|
<p> {{_date myDate}} </p>
|
|
129
136
|
```
|
|
137
|
+
|
|
130
138
|
* returns for "en" → **March 11, 2020, 4:24 AM**
|
|
131
139
|
|
|
132
140
|
```
|
|
133
141
|
<p> {{_price myPrice}} </p>
|
|
134
142
|
```
|
|
143
|
+
|
|
135
144
|
* returns for "en" → **$1,200.99**
|
|
136
145
|
|
|
137
146
|
## Further examples
|
|
138
147
|
|
|
139
148
|
:point_right: See the *examples folder* in the repo for more use cases and details.
|
|
140
149
|
|
|
150
|
+
- Open `examples/browser-example/index.html` in your Web browser to see an implementation with a simple UI
|
|
151
|
+
- Run `$ npm run example:js` in the console to get a very basic node example logged
|
|
152
|
+
- Run `$ npm run example:ts` to compile and log a typescript example
|
|
141
153
|
|
|
142
|
-
##
|
|
154
|
+
## Additional CLI Helper for Handlebars-i18n available :metal:
|
|
143
155
|
|
|
144
|
-
Handlebars-i18n has its own command line interface [handlebars-i18n-cli](https://www.npmjs.com/package/handlebars-i18n-cli)
|
|
156
|
+
Handlebars-i18n has its own command line interface [handlebars-i18n-cli](https://www.npmjs.com/package/handlebars-i18n-cli).
|
|
145
157
|
|
|
146
158
|
```bash
|
|
147
159
|
$ npm i handlebars-i18n-cli --save-dev
|
|
148
160
|
```
|
|
149
161
|
|
|
150
162
|
Automatically extract translation strings from handlebars templates and generate i18next conform json files from it.
|
|
151
|
-
Handlebars-i18n-cli also helps to keep your translations up to date when changes are made in the templates over time.
|
|
152
|
-
|
|
163
|
+
Handlebars-i18n-cli also helps to keep[](https://) your translations up to date when changes are made in the templates over time.
|
|
153
164
|
|
|
154
165
|
## API
|
|
155
166
|
|
|
156
|
-
|
|
157
167
|
### __
|
|
158
168
|
|
|
159
169
|
Returns the phrase associated with the given key for the selected language. __ will take all options i18next’s [t-function](https://www.i18next.com/overview/api#t) would take.
|
|
@@ -162,6 +172,7 @@ The primary key can be passed hard encoded in the template when written in quote
|
|
|
162
172
|
```
|
|
163
173
|
{{__ "keyToTranslationPhrase"}}
|
|
164
174
|
```
|
|
175
|
+
|
|
165
176
|
… or it can be referenced via a handlebars variable:
|
|
166
177
|
|
|
167
178
|
```
|
|
@@ -211,8 +222,6 @@ Will output the contents for "**de**" even though other language is selected.
|
|
|
211
222
|
|
|
212
223
|
---
|
|
213
224
|
|
|
214
|
-
|
|
215
|
-
|
|
216
225
|
### _locale
|
|
217
226
|
|
|
218
227
|
Returns the shortcode of i18next’s currently selected language such as "**en**", "**de**", "**fr**", "**fi**" … etc.
|
|
@@ -220,6 +229,7 @@ Returns the shortcode of i18next’s currently selected language such as "**en**
|
|
|
220
229
|
```
|
|
221
230
|
{{_locale}}
|
|
222
231
|
```
|
|
232
|
+
|
|
223
233
|
---
|
|
224
234
|
|
|
225
235
|
### localeIs
|
|
@@ -229,6 +239,7 @@ Checks a string against i18next’s currently selected language. Returns **true*
|
|
|
229
239
|
```
|
|
230
240
|
{{#if (localeIs "en")}} ... {{/if}}
|
|
231
241
|
```
|
|
242
|
+
|
|
232
243
|
---
|
|
233
244
|
|
|
234
245
|
### _date
|
|
@@ -272,6 +283,7 @@ You can add multiple arguments for individual formatting. See [Intl DateTimeForm
|
|
|
272
283
|
```
|
|
273
284
|
{{_date 1583922952743 year="2-digit" day="2-digit" timeZone="America/Los_Angeles"}}
|
|
274
285
|
```
|
|
286
|
+
|
|
275
287
|
---
|
|
276
288
|
|
|
277
289
|
### _num
|
|
@@ -289,6 +301,7 @@ You can add multiple arguments for individual formatting. See [Intl NumberFormat
|
|
|
289
301
|
```
|
|
290
302
|
{{_num 3.14159 maximumFractionDigits=2}}
|
|
291
303
|
```
|
|
304
|
+
|
|
292
305
|
Will output **3.14** for "**en**", but **3,14** for "**de**".
|
|
293
306
|
|
|
294
307
|
---
|
|
@@ -297,7 +310,6 @@ Will output **3.14** for "**en**", but **3,14** for "**de**".
|
|
|
297
310
|
|
|
298
311
|
Outputs a formatted currency string according to the language specific conventions of price representation, e.g. **€9,999.99** for "**en**", but **9.999,99 €** for "**de**".
|
|
299
312
|
|
|
300
|
-
|
|
301
313
|
```
|
|
302
314
|
{{_price 9999.99}}
|
|
303
315
|
```
|
|
@@ -417,4 +429,4 @@ For your contribution, I would like to thank [@MickL](https://github.com/MickL),
|
|
|
417
429
|
|
|
418
430
|
## Note
|
|
419
431
|
|
|
420
|
-
There is a *different* package named [handlebars-i18next](https://www.npmjs.com/package/handlebars-i18next) by [
|
|
432
|
+
There is a *different* package named [handlebars-i18next](https://www.npmjs.com/package/handlebars-i18next) by [@jgonggrijp](https://github.com/jgonggrijp) which might also suit your needs. Cheers!
|