@knowark/loggarkjs 0.3.8 → 0.3.9
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/lib/translator.js +3 -1
- package/lib/translator.test.js +14 -1
- package/package.json +1 -1
package/lib/translator.js
CHANGED
|
@@ -19,4 +19,6 @@ export class Translator {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const t = (key, options) => Translator.translate(key, options)
|
|
22
|
+
export const t = (key, options) => Translator.translate(key, options)
|
|
23
|
+
|
|
24
|
+
export const lt = (key, options) => () => Translator.translate(key, options)
|
package/lib/translator.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { it, expect } from '@jest/globals'
|
|
2
|
-
import { Translator, t } from './translator.js'
|
|
2
|
+
import { Translator, t, lt } from './translator.js'
|
|
3
3
|
|
|
4
4
|
it('can be instantiated', () => {
|
|
5
5
|
const translator = new Translator()
|
|
@@ -33,3 +33,16 @@ it('defines a global t shortcut translate', () => {
|
|
|
33
33
|
expect(result).toBe('translated:any.key')
|
|
34
34
|
Translator.translate = originalTranslate
|
|
35
35
|
})
|
|
36
|
+
|
|
37
|
+
it('defines a global lt lazy-translation function', () => {
|
|
38
|
+
const originalTranslate = Translator.translate
|
|
39
|
+
Translator.translate = (key, _options) => {
|
|
40
|
+
return `translated:${key}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = lt('any.key')
|
|
44
|
+
|
|
45
|
+
expect(result).toBeInstanceOf(Function)
|
|
46
|
+
expect(result()).toBe('translated:any.key')
|
|
47
|
+
Translator.translate = originalTranslate
|
|
48
|
+
})
|