handlebars-i18n 1.2.1 → 1.4.0
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/.github/workflows/ci.yml +8 -4
- package/.github/workflows/schedule.yml +10 -10
- package/CHANGELOG.md +28 -0
- package/dist/handlebars-i18n.js +44 -35
- package/dist/handlebars-i18n.min.js +1 -1
- package/examples/node-example/simple-example.js +1 -1
- package/package.json +14 -14
- package/readme.md +70 -47
- package/test/handlebars-i18n.test.js +10 -3
package/.github/workflows/ci.yml
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
name: CI
|
|
2
2
|
|
|
3
|
-
on:
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
release:
|
|
7
|
+
types: [published]
|
|
4
8
|
|
|
5
9
|
env:
|
|
6
10
|
IMAGE_ID: ${{ github.repository }}
|
|
@@ -17,16 +21,16 @@ jobs:
|
|
|
17
21
|
npm i
|
|
18
22
|
npm run test
|
|
19
23
|
semantic-release:
|
|
20
|
-
if: github.
|
|
24
|
+
if: github.ref == 'refs/heads/master'
|
|
21
25
|
name: Semantic Release
|
|
22
26
|
runs-on: ubuntu-latest
|
|
23
27
|
needs: build
|
|
24
28
|
steps:
|
|
25
|
-
- uses: actions/checkout@v2.
|
|
29
|
+
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
|
|
26
30
|
with:
|
|
27
31
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
28
32
|
- name: Semantic Release
|
|
29
|
-
uses: cycjimmy/semantic-release-action@v2.
|
|
33
|
+
uses: cycjimmy/semantic-release-action@5982a02995853159735cb838992248c4f0f16166 # renovate: tag=v2.7.0
|
|
30
34
|
with:
|
|
31
35
|
extra_plugins: |
|
|
32
36
|
@semantic-release/changelog
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
name: Scheduled
|
|
1
|
+
name: 'Release: Scheduled'
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
schedule:
|
|
5
|
-
- cron:
|
|
5
|
+
- cron: '0 0 * * 1' # Every Monday at 00:00 AM UTC on the default branch
|
|
6
6
|
|
|
7
7
|
jobs:
|
|
8
8
|
analyze-tags:
|
|
@@ -11,12 +11,12 @@ jobs:
|
|
|
11
11
|
previous-tag: ${{ steps.previoustag.outputs.tag }}
|
|
12
12
|
timestamp-diff: ${{ steps.diff.outputs.timestamp-diff }}
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@v2.
|
|
14
|
+
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
|
|
15
15
|
with:
|
|
16
16
|
fetch-depth: 0
|
|
17
17
|
- name: Get previous tag
|
|
18
18
|
id: previoustag
|
|
19
|
-
uses:
|
|
19
|
+
uses: WyriHaximus/github-action-get-previous-tag@v1.1.0
|
|
20
20
|
- name: Get seconds from previous tag to now
|
|
21
21
|
id: diff
|
|
22
22
|
shell: bash
|
|
@@ -30,20 +30,20 @@ jobs:
|
|
|
30
30
|
needs: analyze-tags
|
|
31
31
|
if: needs.analyze-tags.outputs.timestamp-diff > 604800 # 604800 equal one week.
|
|
32
32
|
steps:
|
|
33
|
-
- uses: actions/checkout@v2.
|
|
33
|
+
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
|
|
34
34
|
with:
|
|
35
35
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
36
36
|
- name: Get next minor version
|
|
37
37
|
id: semvers
|
|
38
|
-
uses:
|
|
38
|
+
uses: WyriHaximus/github-action-next-semvers@v1
|
|
39
39
|
with:
|
|
40
40
|
version: ${{ needs.analyze-tags.outputs.previous-tag }}
|
|
41
41
|
- name: manifest Version
|
|
42
|
-
uses: deef0000dragon1/json-edit-action
|
|
42
|
+
uses: deef0000dragon1/json-edit-action@cb3f7455e89d659879ab7e4a55cbc9b10c36a713 # renovate: tag=v1
|
|
43
43
|
env:
|
|
44
44
|
KEY: scheduleVersion
|
|
45
45
|
VALUE: ${{ steps.semvers.outputs.patch }}
|
|
46
|
-
FILE: package.json
|
|
47
|
-
- uses: stefanzweifel/git-auto-commit-action@v4.
|
|
46
|
+
FILE: ${{ inputs.PACKAGE_JSON_PATH || 'package.json' }}
|
|
47
|
+
- uses: stefanzweifel/git-auto-commit-action@5804e42f86b1891093b151b6c4e78e759c746c4d # renovate: tag=v4.13.1
|
|
48
48
|
with:
|
|
49
|
-
commit_message: 'fix(release): schedule release'
|
|
49
|
+
commit_message: 'fix(release): schedule release'
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/fwalzel/handlebars-i18n/compare/1.3.1...1.4.0) (2022-03-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **deps:** upgrade gulp-uglify-es to v3 ([9c918a5](https://github.com/fwalzel/handlebars-i18n/commit/9c918a5b2bb9d6575c106abff5b57922e208f9ac))
|
|
7
|
+
* **deps:** upgrade mocha to v9 ([2de5e75](https://github.com/fwalzel/handlebars-i18n/commit/2de5e75862467e32a2f5ce65ba520520844d3b53))
|
|
8
|
+
|
|
9
|
+
## [1.3.1](https://github.com/fwalzel/handlebars-i18n/compare/1.3.0...1.3.1) (2021-09-22)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* typo in readme.md ([41f554a](https://github.com/fwalzel/handlebars-i18n/commit/41f554a4aa1ed83b63a458dc1ef84b5692733d8b))
|
|
15
|
+
|
|
16
|
+
# [1.3.0](https://github.com/fwalzel/handlebars-i18n/compare/1.2.1...1.3.0) (2021-09-17)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* it() in line 72 in handlebars-i18n.test.js ([88049f9](https://github.com/fwalzel/handlebars-i18n/commit/88049f94c7dbf72ee58b713e0a3ab494a4cde28f))
|
|
22
|
+
* **release:** schedule release ([052f0e1](https://github.com/fwalzel/handlebars-i18n/commit/052f0e1e5cbae779060fe45c604fc97bf0b1c34f))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* compressed .min file ([ce8e28c](https://github.com/fwalzel/handlebars-i18n/commit/ce8e28cddbec9ee8e0e3188fbe24ff404eb8a63f))
|
|
28
|
+
|
|
1
29
|
## [1.2.1](https://github.com/fwalzel/handlebars-i18n/compare/1.2.0...1.2.1) (2021-05-28)
|
|
2
30
|
|
|
3
31
|
|
package/dist/handlebars-i18n.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* handlebars-i18n.js
|
|
3
3
|
*
|
|
4
4
|
* @author: Florian Walzel
|
|
5
|
-
* @
|
|
6
|
-
* @date: 2021-03
|
|
5
|
+
* @date: 2021-10
|
|
7
6
|
*
|
|
8
7
|
* handlebars-i18n adds features for localization/
|
|
9
8
|
* internationalization to handlebars.js
|
|
@@ -36,40 +35,40 @@
|
|
|
36
35
|
|
|
37
36
|
if (typeof exports === 'object' && typeof module === 'object') {
|
|
38
37
|
const Handlebars = require('handlebars'),
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
i18next = require('i18next'),
|
|
39
|
+
Intl = require('intl');
|
|
41
40
|
module.exports = factory(Handlebars, i18next, Intl);
|
|
42
41
|
}
|
|
43
42
|
else if (typeof define === 'function' && define.amd)
|
|
44
43
|
define(['Handlebars', 'i18next', 'Intl'], factory);
|
|
45
44
|
else if (typeof root.Handlebars === 'object'
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
&& typeof root.i18next === 'object'
|
|
46
|
+
&& typeof root.Intl === 'object')
|
|
48
47
|
root['HandlebarsI18n'] = factory(root.Handlebars, root.i18next, root.Intl);
|
|
49
48
|
else {
|
|
50
49
|
console.error('@ handlebars-i18n: One or more dependencies are missing. Check for Handlebars, i18next and Intl.');
|
|
51
50
|
return false;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
})(this, function(handlebars, i18next, Intl) {
|
|
53
|
+
})(this, function (handlebars, i18next, Intl) {
|
|
55
54
|
|
|
56
55
|
'use strict';
|
|
57
56
|
|
|
58
57
|
var defaultConf = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
DateTimeFormat: {
|
|
59
|
+
standard: {},
|
|
60
|
+
custom: {}
|
|
61
|
+
},
|
|
62
|
+
NumberFormat: {
|
|
63
|
+
standard: {},
|
|
64
|
+
custom: {}
|
|
65
|
+
},
|
|
66
|
+
PriceFormat: {
|
|
67
|
+
standard: {
|
|
68
|
+
all: {style: 'currency', currency: 'EUR'}
|
|
66
69
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
all: {style: 'currency', currency: 'EUR'}
|
|
70
|
-
},
|
|
71
|
-
custom: { }
|
|
72
|
-
}
|
|
70
|
+
custom: {}
|
|
71
|
+
}
|
|
73
72
|
};
|
|
74
73
|
|
|
75
74
|
// make a copy of default object
|
|
@@ -132,7 +131,7 @@
|
|
|
132
131
|
|
|
133
132
|
// no configuration delivered, fallback is Intl standard definition
|
|
134
133
|
else
|
|
135
|
-
return {
|
|
134
|
+
return {};
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
/**
|
|
@@ -146,7 +145,7 @@
|
|
|
146
145
|
function __validateArgs(lngShortcode, typeOfFormat, options, customFormat) {
|
|
147
146
|
|
|
148
147
|
if (typeof lngShortcode !== 'string') {
|
|
149
|
-
console.error('@ handlebars-i18n.configure(): Invalid argument <'+ lngShortcode +'> ' +
|
|
148
|
+
console.error('@ handlebars-i18n.configure(): Invalid argument <' + lngShortcode + '> ' +
|
|
150
149
|
'First argument must be a string with language code such as "en".');
|
|
151
150
|
return false;
|
|
152
151
|
}
|
|
@@ -154,21 +153,21 @@
|
|
|
154
153
|
if (typeOfFormat !== 'DateTimeFormat'
|
|
155
154
|
&& typeOfFormat !== 'NumberFormat'
|
|
156
155
|
&& typeOfFormat !== 'PriceFormat') {
|
|
157
|
-
console.error('@ handlebars-i18n.configure(): Invalid argument <'+ typeOfFormat +'>. ' +
|
|
156
|
+
console.error('@ handlebars-i18n.configure(): Invalid argument <' + typeOfFormat + '>. ' +
|
|
158
157
|
'Second argument must be a string with the options key. ' +
|
|
159
158
|
'Use either "DateTimeFormat", "NumberFormat" or "PriceFormat".');
|
|
160
159
|
return false;
|
|
161
160
|
}
|
|
162
161
|
|
|
163
162
|
if (typeof options !== 'object') {
|
|
164
|
-
console.error('@ handlebars-i18n.configure(): Invalid argument <'+ options +'> ' +
|
|
163
|
+
console.error('@ handlebars-i18n.configure(): Invalid argument <' + options + '> ' +
|
|
165
164
|
'Third argument must be an object containing the configuration parameters.');
|
|
166
165
|
return false;
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
if ((customFormat !== null && typeof customFormat !== 'undefined' && typeof customFormat !== 'string')
|
|
170
169
|
|| customFormat == '' || customFormat == ' ') {
|
|
171
|
-
console.error('@ handlebars-i18n.configure(): Invalid argument <'+ customFormat +'> ' +
|
|
170
|
+
console.error('@ handlebars-i18n.configure(): Invalid argument <' + customFormat + '> ' +
|
|
172
171
|
'Fourth argument (optional) must be a string naming your custom format configuration.');
|
|
173
172
|
return false;
|
|
174
173
|
}
|
|
@@ -214,10 +213,10 @@
|
|
|
214
213
|
* @param typeOfFormat : string - DateTimeFormat | NumberFormat | PriceFormat
|
|
215
214
|
* @param options : object - the options object
|
|
216
215
|
*/
|
|
217
|
-
configure
|
|
216
|
+
configure: function (langOrArr, typeOfFormat, options, customFormatname = null) {
|
|
218
217
|
|
|
219
218
|
if (typeof langOrArr !== 'string' && !Array.isArray(langOrArr)) {
|
|
220
|
-
console.error('@ handlebars-i18n.configure(): Invalid argument <'+ langOrArr +'> ' +
|
|
219
|
+
console.error('@ handlebars-i18n.configure(): Invalid argument <' + langOrArr + '> ' +
|
|
221
220
|
'First argument must be a string with language code such as "en" or an array with parameters.');
|
|
222
221
|
return false;
|
|
223
222
|
}
|
|
@@ -248,7 +247,7 @@
|
|
|
248
247
|
/**
|
|
249
248
|
* resets the configuration to default state like it is before configure() is called
|
|
250
249
|
*/
|
|
251
|
-
reset
|
|
250
|
+
reset: function () {
|
|
252
251
|
optionsConf = JSON.parse(JSON.stringify(defaultConf));
|
|
253
252
|
return true;
|
|
254
253
|
},
|
|
@@ -256,9 +255,19 @@
|
|
|
256
255
|
/**
|
|
257
256
|
* init all handlebars helpers
|
|
258
257
|
*
|
|
258
|
+
* @param overrideHndlbrs | optional: pass an individual instance of handlebars objec to the init() function
|
|
259
|
+
* to override the generic handlebars instance required in LINE 38
|
|
260
|
+
*
|
|
259
261
|
* @returns {*}
|
|
260
262
|
*/
|
|
261
|
-
init
|
|
263
|
+
init: function (overrideHndlbrs) {
|
|
264
|
+
|
|
265
|
+
if (typeof overrideHndlbrs === 'object')
|
|
266
|
+
handlebars = overrideHndlbrs;
|
|
267
|
+
else if (typeof overrideHndlbrs !== 'undefined' && overrideHndlbrs !== null)
|
|
268
|
+
console.error('@ handlebars-i18n.init(): Invalid Argument given for overrideHndlbrs. ' +
|
|
269
|
+
'Argument must be the Handlebars Object. Using previously required handlebars object instead.');
|
|
270
|
+
|
|
262
271
|
handlebars.registerHelper('__',
|
|
263
272
|
/**
|
|
264
273
|
* retrieves the translation phrase from a key given as string
|
|
@@ -280,7 +289,7 @@
|
|
|
280
289
|
*
|
|
281
290
|
* @returns {language|any|string|*|e}
|
|
282
291
|
*/
|
|
283
|
-
function() {
|
|
292
|
+
function () {
|
|
284
293
|
return i18next.language;
|
|
285
294
|
}
|
|
286
295
|
);
|
|
@@ -291,7 +300,7 @@
|
|
|
291
300
|
*
|
|
292
301
|
* @returns {language|any|string|*|e}
|
|
293
302
|
*/
|
|
294
|
-
function(language) {
|
|
303
|
+
function (language) {
|
|
295
304
|
return i18next.language === language;
|
|
296
305
|
}
|
|
297
306
|
);
|
|
@@ -321,7 +330,7 @@
|
|
|
321
330
|
* @param dateInput : string | number
|
|
322
331
|
* @param options
|
|
323
332
|
*/
|
|
324
|
-
function(dateInput, options) {
|
|
333
|
+
function (dateInput, options) {
|
|
325
334
|
|
|
326
335
|
var date;
|
|
327
336
|
|
|
@@ -333,7 +342,7 @@
|
|
|
333
342
|
|
|
334
343
|
if (dateInput.charAt(0) == '[' && dateInput.slice(-1) == ']') {
|
|
335
344
|
// input as array represented as string such as "[2020, 11]"
|
|
336
|
-
dateInput = dateInput.substring(1, dateInput.length-1).replace(/ /g,'');
|
|
345
|
+
dateInput = dateInput.substring(1, dateInput.length - 1).replace(/ /g, '');
|
|
337
346
|
var dateArr = dateInput.split(',');
|
|
338
347
|
var dateFactory = __applyToConstructor.bind(null, Date);
|
|
339
348
|
date = dateFactory(dateArr);
|
|
@@ -371,7 +380,7 @@
|
|
|
371
380
|
* @param options
|
|
372
381
|
* @returns {*}
|
|
373
382
|
*/
|
|
374
|
-
function(number, options) {
|
|
383
|
+
function (number, options) {
|
|
375
384
|
|
|
376
385
|
var opts = __configLookup(options, i18next.language, optionsConf.NumberFormat);
|
|
377
386
|
|
|
@@ -392,7 +401,7 @@
|
|
|
392
401
|
* @param options
|
|
393
402
|
* @returns {*}
|
|
394
403
|
*/
|
|
395
|
-
function(price, options) {
|
|
404
|
+
function (price, options) {
|
|
396
405
|
|
|
397
406
|
var opts = __configLookup(options, i18next.language, optionsConf.PriceFormat);
|
|
398
407
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,r){if("object"==typeof exports&&"object"==typeof module){const e=require("handlebars"),n=require("i18next"),t=require("intl");module.exports=r(e,n,t)}else if("function"==typeof define&&define.amd)define(["Handlebars","i18next","Intl"],r);else{if("object"!=typeof e.Handlebars||"object"!=typeof e.i18next||"object"!=typeof e.Intl)return console.error("@ handlebars-i18n: One or more dependencies are missing. Check for Handlebars, i18next and Intl."),!1;e.HandlebarsI18n=r(e.Handlebars,e.i18next,e.Intl)}}(this,(function(e,r,n){"use strict";var t={DateTimeFormat:{standard:{},custom:{}},NumberFormat:{standard:{},custom:{}},PriceFormat:{standard:{all:{style:"currency",currency:"EUR"}},custom:{}}},a=JSON.parse(JSON.stringify(t));function o(e,r){var n=[null].concat(r);return new(e.bind.apply(e,n))}function i(e,r,n){if("object"==typeof e&&"object"==typeof e.hash&&Object.keys(e.hash).length>0){var t=e.hash;if(void 0===t.format)return t;if(void 0!==n.custom[t.format]&&void 0!==n.custom[t.format][r])return n.custom[t.format][r]}return void 0!==n.standard[r]?n.standard[r]:void 0!==n.standard.all?n.standard.all:{}}function
|
|
1
|
+
!function(e,r){if("object"==typeof exports&&"object"==typeof module){const e=require("handlebars"),n=require("i18next"),t=require("intl");module.exports=r(e,n,t)}else if("function"==typeof define&&define.amd)define(["Handlebars","i18next","Intl"],r);else{if("object"!=typeof e.Handlebars||"object"!=typeof e.i18next||"object"!=typeof e.Intl)return console.error("@ handlebars-i18n: One or more dependencies are missing. Check for Handlebars, i18next and Intl."),!1;e.HandlebarsI18n=r(e.Handlebars,e.i18next,e.Intl)}}(this,(function(e,r,n){"use strict";var t={DateTimeFormat:{standard:{},custom:{}},NumberFormat:{standard:{},custom:{}},PriceFormat:{standard:{all:{style:"currency",currency:"EUR"}},custom:{}}},a=JSON.parse(JSON.stringify(t));function o(e,r){var n=[null].concat(r);return new(e.bind.apply(e,n))}function i(e,r,n){if("object"==typeof e&&"object"==typeof e.hash&&Object.keys(e.hash).length>0){var t=e.hash;if(void 0===t.format)return t;if(void 0!==n.custom[t.format]&&void 0!==n.custom[t.format][r])return n.custom[t.format][r]}return void 0!==n.standard[r]?n.standard[r]:void 0!==n.standard.all?n.standard.all:{}}function s(e,r,n,t){return"string"!=typeof e?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+e+'> First argument must be a string with language code such as "en".'),!1):"DateTimeFormat"!==r&&"NumberFormat"!==r&&"PriceFormat"!==r?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+r+'>. Second argument must be a string with the options key. Use either "DateTimeFormat", "NumberFormat" or "PriceFormat".'),!1):"object"!=typeof n?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+n+"> Third argument must be an object containing the configuration parameters."),!1):(null==t||"string"==typeof t)&&""!=t&&" "!=t||(console.error("@ handlebars-i18n.configure(): Invalid argument <"+t+"> Fourth argument (optional) must be a string naming your custom format configuration."),!1)}function u(e,r,n,t){return null!=t?(void 0===a[r].custom[t]&&(a[r].custom[t]={}),a[r].custom[t][e]=n):a[r].standard[e]=n,!0}return{configure:function(e,r,n,t=null){if("string"!=typeof e&&!Array.isArray(e))return console.error("@ handlebars-i18n.configure(): Invalid argument <"+e+'> First argument must be a string with language code such as "en" or an array with parameters.'),!1;if(Array.isArray(e)){if(e.length<1)return console.log("@ handlebars-i18n.configure(): You passed an empty array, no parameters taken."),!1;e.forEach(e=>{if(!s(e[0],e[1],e[2],e[3]))return!1;u(e[0],e[1],e[2],e[3])})}else{if(!s(e,r,n,t))return!1;u(e,r,n,t)}return!0},reset:function(){return a=JSON.parse(JSON.stringify(t)),!0},init:function(t){return"object"==typeof t?e=t:null!=t&&console.error("@ handlebars-i18n.init(): Invalid Argument given for overrideHndlbrs. Argument must be the Handlebars Object. Using previously required handlebars object instead."),e.registerHelper("__",(function(n,t){return new e.SafeString(void 0!==r?r.t(n,t.hash):n)})),e.registerHelper("_locale",(function(){return r.language})),e.registerHelper("localeIs",(function(e){return r.language===e})),e.registerHelper("_date",(function(e,t){var s;if("number"==typeof e)s=new Date(e);else if("string"==typeof e)if("["==e.charAt(0)&&"]"==e.slice(-1)){var u=(e=e.substring(1,e.length-1).replace(/ /g,"")).split(",");s=o.bind(null,Date)(u)}else s="now"==e.toLowerCase()||"today"==e.toLowerCase()?new Date:new Date(e);else s=new Date;var l=i(t,r.language,a.DateTimeFormat);return new n.DateTimeFormat(r.language,l).format(s)})),e.registerHelper("_num",(function(e,t){var o=i(t,r.language,a.NumberFormat);return new n.NumberFormat(r.language,o).format(e)})),e.registerHelper("_price",(function(e,t){var o=i(t,r.language,a.PriceFormat);"string"!=typeof o.style&&"string"==typeof o.currency&&(o.style="currency");return new n.NumberFormat(r.language,o).format(e)})),e}}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handlebars-i18n",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "handlebars-i18n adds internationlization to handlebars.js using i18next and Intl",
|
|
5
5
|
"main": "dist/handlebars-i18n.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,33 +35,33 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"homepage": "https://github.com/fwalzel/handlebars-i18n.git#readme",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"handlebars": "^4.7.
|
|
39
|
-
"i18next": "^
|
|
38
|
+
"handlebars": "^4.7.7",
|
|
39
|
+
"i18next": "^21.6.14",
|
|
40
40
|
"intl": "^1.2.5"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@commitlint/cli": "
|
|
44
|
-
"@commitlint/config-conventional": "
|
|
45
|
-
"chai": "4.3.
|
|
46
|
-
"coveralls": "3.1.
|
|
43
|
+
"@commitlint/cli": "16.2.3",
|
|
44
|
+
"@commitlint/config-conventional": "16.2.1",
|
|
45
|
+
"chai": "4.3.6",
|
|
46
|
+
"coveralls": "3.1.1",
|
|
47
47
|
"gulp": "4.0.2",
|
|
48
48
|
"gulp-rename": "2.0.0",
|
|
49
49
|
"gulp-uglify": "3.0.2",
|
|
50
|
-
"gulp-uglify-es": "
|
|
51
|
-
"husky": "
|
|
50
|
+
"gulp-uglify-es": "3.0.0",
|
|
51
|
+
"husky": "7.0.4",
|
|
52
52
|
"istanbul": "0.4.5",
|
|
53
|
-
"mocha": "
|
|
53
|
+
"mocha": "9.2.2",
|
|
54
54
|
"nyc": "15.1.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"handlebars": "
|
|
58
|
-
"i18next": "
|
|
59
|
-
"intl": "
|
|
57
|
+
"handlebars": "4.7.7",
|
|
58
|
+
"i18next": "21.6.14",
|
|
59
|
+
"intl": "1.2.5"
|
|
60
60
|
},
|
|
61
61
|
"husky": {
|
|
62
62
|
"hooks": {
|
|
63
63
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"scheduleVersion": "1.2.
|
|
66
|
+
"scheduleVersion": "1.2.2"
|
|
67
67
|
}
|
package/readme.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
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).
|
|
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.
|
|
4
4
|
|
|
5
5
|
Handlebars-i18n is listed amongst i18next’s [framework helpers](https://www.i18next.com/overview/supported-frameworks).
|
|
6
6
|
|
|
7
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://travis-ci.org/fwalzel/handlebars-i18n)
|
|
9
|
+
[](https://coveralls.io/github/fwalzel/handlebars-i18next?branch=master)
|
|
10
|
+
[](https://www.code-inspector.com/project/29087/score/svg)
|
|
11
|
+
[](https://snyk.io/test/github/Aller-Couleur/handlebars-i18n/badge.svg)
|
|
12
|
+
|
|
8
13
|
|
|
9
14
|
## License
|
|
10
15
|
|
|
@@ -13,23 +18,30 @@ MIT License
|
|
|
13
18
|
|
|
14
19
|
## Install
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
If you use version npm >= 7:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ npm i handlebars-i18n
|
|
18
25
|
```
|
|
19
26
|
|
|
27
|
+
For older versions do:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ npm i handlebars-i18n handlebars@4.7.6 i18next@20.2.1 intl@1.2.5
|
|
31
|
+
```
|
|
20
32
|
|
|
21
33
|
## Usage
|
|
22
34
|
|
|
23
35
|
Usage within node environment:
|
|
24
36
|
|
|
25
|
-
```
|
|
37
|
+
```javascript
|
|
26
38
|
const HandlebarsI18n = require("handlebars-i18n");
|
|
27
39
|
HandlebarsI18n.init();
|
|
28
40
|
```
|
|
29
41
|
|
|
30
42
|
Usage in web browser:
|
|
31
43
|
|
|
32
|
-
```
|
|
44
|
+
```javascript
|
|
33
45
|
<script src="handlebars.js"></script>
|
|
34
46
|
<script src="i18next.js"></script>
|
|
35
47
|
<script src="handlebars-i18n.js"></script>
|
|
@@ -43,7 +55,7 @@ Usage in web browser:
|
|
|
43
55
|
|
|
44
56
|
Initialize i18next with your language strings and default settings:
|
|
45
57
|
|
|
46
|
-
```
|
|
58
|
+
```javascript
|
|
47
59
|
const i18next = require('i18next');
|
|
48
60
|
|
|
49
61
|
i18next.init({
|
|
@@ -67,27 +79,27 @@ i18next.init({
|
|
|
67
79
|
|
|
68
80
|
Set your Handlebars.js data object:
|
|
69
81
|
|
|
70
|
-
```
|
|
82
|
+
```javascript
|
|
71
83
|
let data = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
myItem: "handlebars-i18n",
|
|
85
|
+
myPrice: 1200.99,
|
|
86
|
+
myDate: "2020-03-11T03:24:00"
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
```
|
|
78
90
|
|
|
79
91
|
Initialize handlebars-i18n:
|
|
80
92
|
|
|
81
|
-
```
|
|
93
|
+
```javascript
|
|
82
94
|
HandlebarsI18n.init();
|
|
83
95
|
```
|
|
84
96
|
|
|
85
97
|
Optionally configure your language specific number, currency, and date-time defaults:
|
|
86
98
|
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
```javascript
|
|
100
|
+
HandlebarsI18n.configure([
|
|
101
|
+
["en", "PriceFormat", {currency: "USD"}],
|
|
102
|
+
["de", "PriceFormat", {currency: "EUR"}]
|
|
91
103
|
]);
|
|
92
104
|
```
|
|
93
105
|
|
|
@@ -120,9 +132,8 @@ Finally use in template:
|
|
|
120
132
|
|
|
121
133
|
## Run tests
|
|
122
134
|
|
|
123
|
-
```
|
|
124
|
-
$
|
|
125
|
-
$ npm run test
|
|
135
|
+
```bash
|
|
136
|
+
$ npm test
|
|
126
137
|
```
|
|
127
138
|
|
|
128
139
|
|
|
@@ -167,12 +178,12 @@ The i18next resource:
|
|
|
167
178
|
{{__ "keyWithCount" count=8}}
|
|
168
179
|
```
|
|
169
180
|
|
|
170
|
-
```
|
|
181
|
+
```javascript
|
|
171
182
|
'en' : {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
183
|
+
translation : {
|
|
184
|
+
'keyWithCount': '{{count}} item',
|
|
185
|
+
'keyWithCount_plural': '{{count}} items',
|
|
186
|
+
}
|
|
176
187
|
},
|
|
177
188
|
```
|
|
178
189
|
|
|
@@ -291,8 +302,8 @@ You can add multiple arguments for individual currency formatting. See [Intl Num
|
|
|
291
302
|
|
|
292
303
|
Instead of defining the formatting options for each date, number or price anew, you can configure global settings for all languages or only for specific languages.
|
|
293
304
|
|
|
294
|
-
```
|
|
295
|
-
|
|
305
|
+
```javascript
|
|
306
|
+
HandlebarsI18n.configure("all", "DateTimeFormat", {timeZone: "America/Los_Angeles"});
|
|
296
307
|
```
|
|
297
308
|
|
|
298
309
|
First argument is the language shortcode or "**all**" for all languages. Second is the format option you want to address (DateTimeFormat, NumberFormat, or PriceFormat). Third argument ist the options object with the specific settings.
|
|
@@ -301,18 +312,18 @@ First argument is the language shortcode or "**all**" for all languages. Second
|
|
|
301
312
|
|
|
302
313
|
You can define specific subsets to be used in the template, i.e. if you want the date in different formatts such as:
|
|
303
314
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
315
|
+
- **2020** (year-only)
|
|
316
|
+
- **11.3.2020** (standard-date)
|
|
317
|
+
- **7:24:02** (time-only)
|
|
307
318
|
|
|
308
319
|
To do this define a 4th parameter with a custom name:
|
|
309
320
|
|
|
310
321
|
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
322
|
+
```javascript
|
|
323
|
+
HandlebarsI18n.configure([
|
|
324
|
+
["en", "DateTimeFormat", {year:'numeric'}, "year-only"],
|
|
325
|
+
["en", "DateTimeFormat", {year:'numeric', month:'numeric', day:'numeric'}, "standard-date"],
|
|
326
|
+
['en', 'DateTimeFormat', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false}, "time-only"]
|
|
316
327
|
]);
|
|
317
328
|
```
|
|
318
329
|
|
|
@@ -328,38 +339,50 @@ Call a subset in template wit the parameter "format", like:
|
|
|
328
339
|
|
|
329
340
|
The general lookup cascade is:
|
|
330
341
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
342
|
+
- **1st Priority**: The argument given in the template for custom configurations by the key "format", i.e. `{{_date format="my-custom-format"}}`
|
|
343
|
+
- **2nd Priority**: The extra argument(s) given in the template, e.g. `{{_date timeZone="America/Los_Angeles" year="2-digit"}}`
|
|
344
|
+
- **3rd Priority**: The global setting configured for the current language, such as "**en**"
|
|
345
|
+
- **4th Priority**: The global setting configured for **all** languages
|
|
346
|
+
- **Default**: The **Intl** default setting
|
|
336
347
|
|
|
337
348
|
**Example:**
|
|
338
349
|
|
|
339
350
|
This defines that all prices for all languages are represented as Dollar:
|
|
340
351
|
|
|
341
|
-
```
|
|
342
|
-
|
|
352
|
+
```javascript
|
|
353
|
+
HandlebarsI18n.configure("all", "PriceFormat", {currency: "USD"});
|
|
343
354
|
```
|
|
344
355
|
|
|
345
356
|
This defines that all prices for all languages are represented as Dollar, but that for language French the currency is Euro:
|
|
346
357
|
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
358
|
+
```javascript
|
|
359
|
+
HandlebarsI18n.configure([
|
|
360
|
+
["all", "PriceFormat", {currency: "USD"}],
|
|
361
|
+
["fr", "PriceFormat", {currency: "EUR"}]
|
|
351
362
|
]);
|
|
352
363
|
```
|
|
353
364
|
|
|
354
|
-
|
|
355
365
|
### Reset an existing configuration
|
|
356
366
|
|
|
357
367
|
Dismiss all existing configurations:
|
|
358
368
|
|
|
369
|
+
```javascript
|
|
370
|
+
HandlebarsI18n.reset();
|
|
359
371
|
```
|
|
360
|
-
|
|
372
|
+
|
|
373
|
+
## Using custom instances of Handlebars
|
|
374
|
+
|
|
375
|
+
Sometimes you may want to use a Handlebars Object you have already modified before, or you may want to use multiple discrete instances of Handlebars. In this case you can pass you custom Handlebars instance to the init function to use it instead of the generic Handlebars object like so:
|
|
376
|
+
|
|
377
|
+
```javascript
|
|
378
|
+
const HandlebarsModified = require('handlebars');
|
|
379
|
+
HandlebarsModified.registerHelper('foo', function() { return 'what you want' });
|
|
380
|
+
HandlebarsI18n.init(HandlebarsModified);
|
|
361
381
|
```
|
|
362
382
|
|
|
383
|
+
HandlebarsI18n will have your previously defined method **foo()** by now.
|
|
384
|
+
|
|
385
|
+
|
|
363
386
|
## Note
|
|
364
387
|
|
|
365
388
|
There is a *different* package named [handlebars-i18next](https://www.npmjs.com/package/handlebars-i18next) by [Julian Gonggrijp](https://github.com/jgonggrijp) which might also suit your needs. Cheers!
|
|
@@ -13,7 +13,6 @@ const Handlebars = require('handlebars');
|
|
|
13
13
|
const i18next = require('i18next');
|
|
14
14
|
const HandlebarsI18n = require('../dist/handlebars-i18n');
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
describe('handlebars-i18n Test', function() {
|
|
18
17
|
|
|
19
18
|
const i18nInitObj = {
|
|
@@ -36,7 +35,6 @@ describe('handlebars-i18n Test', function() {
|
|
|
36
35
|
|
|
37
36
|
const hI18n = HandlebarsI18n.init();
|
|
38
37
|
|
|
39
|
-
|
|
40
38
|
// -- Tests for method init() -- //
|
|
41
39
|
|
|
42
40
|
it('after method call init() should return an object (HandlebarsEnvironment)', function() {
|
|
@@ -67,6 +65,15 @@ describe('handlebars-i18n Test', function() {
|
|
|
67
65
|
assert.isFunction(hI18n.helpers._price);
|
|
68
66
|
});
|
|
69
67
|
|
|
68
|
+
// -- Tests for method init() with override Argument -- //
|
|
69
|
+
|
|
70
|
+
it('after method call init(overrideHndlbrs) with custom handlebars Object, HandlebarsEnvironment object should have custom function foo', function() {
|
|
71
|
+
const HandlebarsModified = require('handlebars');
|
|
72
|
+
HandlebarsModified.registerHelper('foo', function() { return true });
|
|
73
|
+
const hI18nMod = HandlebarsI18n.init(HandlebarsModified);
|
|
74
|
+
assert.isFunction(hI18nMod.helpers.foo);
|
|
75
|
+
});
|
|
76
|
+
|
|
70
77
|
|
|
71
78
|
// -- Tests for function _locale -- //
|
|
72
79
|
|
|
@@ -107,7 +114,7 @@ describe('handlebars-i18n Test', function() {
|
|
|
107
114
|
// -- Tests for function __ -- //
|
|
108
115
|
|
|
109
116
|
it('expecting __ to throw error when called with no parameter', function() {
|
|
110
|
-
expect(function() { hI18n.helpers.__() }).to.throw(
|
|
117
|
+
expect(function() { hI18n.helpers.__() }).to.throw();
|
|
111
118
|
});
|
|
112
119
|
|
|
113
120
|
it('function __ should return a SafeString object with property "string" where "string" returns the first argument given to __', function() {
|