handlebars-i18n 1.7.0 → 1.8.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/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "handlebars-i18n",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
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
- "test": "NODE_ENV=TEST nyc mocha",
8
- "coveralls": "NODE_ENV=TEST istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
7
+ "test": "NODE_ENV=TEST c8 mocha",
8
+ "test:coverage": "npm run test && NODE_ENV=TEST c8 report --reporter=text-lcov > coverage/lcov.info",
9
9
  "compress": "gulp compress",
10
10
  "example:js": "cd examples/node-example && node simple-example.js",
11
11
  "example:ts": "cd examples/typescript && tsc && node index.js"
@@ -48,16 +48,17 @@
48
48
  "@commitlint/config-conventional": "16.2.1",
49
49
  "@types/intl": "^1.2.0",
50
50
  "@types/node": "^18.13.0",
51
+ "c8": "^10.1.2",
51
52
  "chai": "4.3.6",
52
- "coveralls": "3.1.1",
53
- "gulp": "4.0.2",
53
+ "coveralls-next": "^4.2.1",
54
+ "gulp": "5.0.0",
54
55
  "gulp-rename": "2.0.0",
55
56
  "gulp-uglify": "3.0.2",
56
57
  "gulp-uglify-es": "3.0.0",
57
58
  "html-entities": "^2.5.2",
58
59
  "husky": "7.0.4",
59
- "istanbul": "0.4.5",
60
- "mocha": "9.2.2",
60
+ "mocha": "10.7.3",
61
+ "mocha-lcov-reporter": "^1.3.0",
61
62
  "nyc": "15.1.0",
62
63
  "typescript": "^4.9.5"
63
64
  },
package/readme.md CHANGED
@@ -10,7 +10,7 @@ Handlebars-i18n is listed amongst i18next’s [framework helpers](https://www.i1
10
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
11
11
  ![Node.js Version](https://img.shields.io/badge/Node.js-14.x-green)
12
12
  [![Build](https://github.com/fwalzel/handlebars-i18n/actions/workflows/node.js.yml/badge.svg)](https://github.com/fwalzel/handlebars-i18n/actions/workflows/node.js.yml/badge.svg)
13
- [![Coverage Status](https://coveralls.io/repos/github/fwalzel/handlebars-i18next/badge.svg?branch=master)](https://coveralls.io/github/fwalzel/handlebars-i18next?branch=master)
13
+ [![Coverage Status](https://coveralls.io/repos/github/Aller-Couleur/handlebars-i18n/badge.svg?branch=master)](https://coveralls.io/github/Aller-Couleur/handlebars-i18n?branch=master)
14
14
  [![Code Climate](https://codeclimate.com/github/Aller-Couleur/handlebars-i18n/badges/gpa.svg)](https://codeclimate.com/github/Aller-Couleur/handlebars-i18n)
15
15
  [![Known Vulnerabilities](https://snyk.io/test/github/Aller-Couleur/handlebars-i18n/badge.svg)](https://snyk.io/test/github/Aller-Couleur/handlebars-i18n/badge.svg)
16
16
  ![npm](https://img.shields.io/npm/dt/handlebars-i18n)
@@ -28,16 +28,8 @@ If you use handlebars-i18n in a professional context, you could
28
28
 
29
29
  ## Install
30
30
 
31
- If you use version npm >= 7:
32
-
33
- ```bash
34
- $ npm i handlebars-i18n
35
- ```
36
-
37
- For older versions do:
38
-
39
31
  ```bash
40
- $ npm i handlebars-i18n handlebars@4.7.6 i18next@20.2.1 intl@1.2.5
32
+ npm i handlebars-i18n
41
33
  ```
42
34
 
43
35
  ## Usage
@@ -147,7 +139,7 @@ Finally use in template:
147
139
 
148
140
  * returns for "en" → **$1,200.99**
149
141
 
150
- ## Further examples
142
+ ## Detailed examples
151
143
 
152
144
  :point_right: See the *examples folder* in the repo for more use cases and details.
153
145
 
@@ -197,13 +189,9 @@ Template usage:
197
189
  The i18next resource:
198
190
 
199
191
  ```javascript
200
- "en"
201
- :
202
- {
192
+ "en" : {
203
193
  translation : {
204
- "whatIsWhat"
205
- :
206
- "{{a}} is {{b}}."
194
+ "whatIsWhat" : "{{a}} is {{b}}."
207
195
  }
208
196
  }
209
197
  ```
@@ -215,19 +203,12 @@ The i18next resource:
215
203
  ```
216
204
 
217
205
  ```javascript
218
- "en"
219
- :
220
- {
206
+ "en" : {
221
207
  translation : {
222
- "keyWithCount"
223
- :
224
- "{{count}} item",
225
- "keyWithCount_plural"
226
- :
227
- "{{count}} items"
208
+ "keyWithCount" : "{{count}} item",
209
+ "keyWithCount_plural" : "{{count}} items"
228
210
  }
229
- }
230
- , ...
211
+ },
231
212
  ```
232
213
 
233
214
  **Override globally selected language**
@@ -311,51 +292,67 @@ in [handlebars-i18n.d.ts](./dist/handlebars-i18n.d.ts).
311
292
 
312
293
  ---
313
294
 
314
- ### _dateRel :tada: new in 1.7
295
+ ### _dateAdd :tada: new in 1.8
315
296
 
316
- Outputs a string with a relative date statement, formatted according to the language specific conventions.
297
+ Adds a time offset in a given unit to a date, returns the modified date.
317
298
 
318
299
  ```
319
- {{_dateRel 7 unit="hour"}}
300
+ {{_dateAdd "1996-12-17" 24 unit="hour"}}
320
301
  ```
321
302
 
322
- Will output for "en" → **in 7 hours**
303
+ Will output for "en" → **12/18/1996**
304
+
305
+ The first argument is a date (see function **_date** for valid date inputs). The second argument is a time amount given
306
+ as number. The option **unit** specifies the time amount. Possible units
307
+ are `"second"` | `"minute"` | `"hour"` | `"day"` | `"week"` | `"month"` | `"quarter"` |`"year"` (default is `"hour"`).
308
+ Further options as for function **_date** can be applied.
309
+
310
+ ---
311
+
312
+ ### _dateDiff
313
+
314
+ Outputs the relative time difference between two given dates.
323
315
 
324
316
  ```
325
- {{_dateRel -7 unit="hour"}}
317
+ {{_dateDiff "1996-12-17T00:00:00" "1995-12-17T00:00:00" unit="year"}}
326
318
  ```
327
319
 
328
- Will output for "en" → **7 hours ago**
320
+ Will output for "en" → **in 1 year**
329
321
 
330
- A positive number argument leads to a future event statement, a negative refers to a past date. Possible units
331
- are `"second"` | `"minute"` | `"hour"` | `"day"` | `"week"` | `"month"` | `"year"` (default is `"hour"`). For a complete
332
- set of options (such as `numberingSystem` or `localeMatcher`)
333
- see [Intl.RelativeTimeFormat Constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
334
- Alternatively check this repo’s TS types
335
- in [handlebars-i18n.d.ts](./dist/handlebars-i18n.d.ts).
322
+ The second date argument is subtracted from the first. If the difference is a positive value, a future event statement
323
+ is made. A negative value refers to a past date. (If no second argument is given, the default date is the present moment).
324
+ Allowed date input formats are similar to **_date**, options equal **_dateRel**. Default unit is `"hour"`.
336
325
 
337
326
  ---
338
327
 
339
- ### _dateDiff :tada: new in 1.7
328
+ ### _dateRel
340
329
 
341
- Outputs the time difference between two given dates.
330
+ Outputs a string with a relative date statement, formatted according to the language specific conventions.
342
331
 
343
332
  ```
344
- {{_dateDiff "1996-12-17T00:00:00", "1995-12-17T00:00:00" unit="year"}}
333
+ {{_dateRel 7 unit="hour"}}
345
334
  ```
346
335
 
347
- Will output for "en" → **in 1 year**
336
+ Will output for "en" → **in 7 hours**
348
337
 
349
- The second date argument is subtracted from the first. If the difference is a positive value, a future event statement
350
- is made. A negative value refers to a past date. Allowed date input formats are similar to *_date*, options equal
351
- **_dateRel**.
338
+ ```
339
+ {{_dateRel -7 unit="hour"}}
340
+ ```
341
+
342
+ Will output for "en" → **7 hours ago**
343
+
344
+ A positive number argument leads to a future event statement, a negative refers to a past date. Possible units
345
+ are `"second"` | `"minute"` | `"hour"` | `"day"` | `"week"` | `"month"` | `"quarter"` |`"year"` (default is `"hour"`).
346
+ For a complete set of options (such as `numberingSystem` or `localeMatcher`)
347
+ see [Intl.RelativeTimeFormat Constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
348
+ Alternatively check this repo’s TS types in [handlebars-i18n.d.ts](./dist/handlebars-i18n.d.ts).
352
349
 
353
350
  ---
354
351
 
355
352
  ### _num
356
353
 
357
- Outputs a formatted number according to the language specific conventions of number representation, e.g. *
358
- *4,100,000.8314** for "**en**", but **4.100.000,8314** for "**de**".
354
+ Outputs a formatted number according to the language specific conventions of number representation, e.g.
355
+ **4,100,000.8314** for "**en**", but **4.100.000,8314** for "**de**".
359
356
 
360
357
  ```
361
358
  {{_num 4100000.8314 }}
@@ -378,8 +375,8 @@ Will output **3.14** for "**en**", but **3,14** for "**de**".
378
375
 
379
376
  ### _price
380
377
 
381
- Outputs a formatted currency string according to the language specific conventions of price representation, e.g. *
382
- *€9,999.99** for "**en**", but **9.999,99 €** for "**de**".
378
+ Outputs a formatted currency string according to the language specific conventions of price representation, e.g.
379
+ **€9,999.99** for "**en**", but **9.999,99 €** for "**de**".
383
380
 
384
381
  ```
385
382
  {{_price 9999.99}}
@@ -451,6 +448,8 @@ Call a subset in template with the parameter format="custom-name", like:
451
448
  {{_date myDate format="year-only"}}
452
449
  ```
453
450
 
451
+ Subsets must be defined per language, a subset for "all" is invalid.
452
+
454
453
  ### The lookup cascade
455
454
 
456
455
  The general lookup cascade is: