Skip to content

Commit 291c0ea

Browse files
committed
Merge branch 'release/0.14.2' into npm
2 parents 3dcc53b + a210c07 commit 291c0ea

File tree

4 files changed

+112
-11
lines changed

4 files changed

+112
-11
lines changed

i18n.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ const i18n = function I18n(_OPTS = false) {
10251025
' retrying in ' +
10261026
defaultLocale
10271027
)
1028-
mutator(translate(defaultLocale, singular, plural))
1028+
mutator(translate(defaultLocale, singular, plural, true))
10291029
} else {
10301030
mutator({
10311031
one: defaultSingular || singular,
@@ -1047,7 +1047,7 @@ const i18n = function I18n(_OPTS = false) {
10471047
' retrying in ' +
10481048
defaultLocale
10491049
)
1050-
mutator(translate(defaultLocale, singular, plural))
1050+
mutator(translate(defaultLocale, singular, plural, true))
10511051
} else {
10521052
mutator(defaultSingular || singular)
10531053
}

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "i18n",
33
"description": "lightweight translation module with dynamic json storage",
4-
"version": "0.14.1",
4+
"version": "0.14.2",
55
"homepage": "http://github.com/mashpie/i18n-node",
66
"repository": {
77
"type": "git",
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const { I18n } = require('..')
2+
const should = require('should')
3+
const fs = require('fs')
4+
5+
describe('retryInDefaultLocaleWithSync', () => {
6+
const DIRECTORY = './locales_in_sync'
7+
const CONFIG = {
8+
locales: ['en', 'de'],
9+
directory: DIRECTORY,
10+
defaultLocale: 'en',
11+
retryInDefaultLocale: true,
12+
syncFiles: true
13+
}
14+
15+
const readJson = (locale) => {
16+
return JSON.parse(fs.readFileSync(`${DIRECTORY}/${locale}.json`))
17+
}
18+
19+
const writeJson = (locale, data) => {
20+
fs.writeFileSync(
21+
`${DIRECTORY}/${locale}.json`,
22+
JSON.stringify(data, null, '\t')
23+
)
24+
}
25+
26+
describe('writing', () => {
27+
const i18n = new I18n(CONFIG)
28+
const req = {}
29+
i18n.init(req)
30+
after(() => {
31+
try {
32+
fs.unlinkSync(`${DIRECTORY}/de.json`)
33+
fs.unlinkSync(`${DIRECTORY}/en.json`)
34+
fs.rmdirSync(DIRECTORY)
35+
} catch (e) {}
36+
})
37+
38+
it('should not throw', () => {
39+
req.setLocale('en')
40+
should.equal(req.__('test'), 'test')
41+
42+
req.setLocale('de')
43+
should.equal(req.__('test'), 'test')
44+
45+
req.setLocale('fr')
46+
should.equal(req.__('test'), 'test')
47+
})
48+
49+
it('should have written all files', () => {
50+
const statsen = fs.lstatSync(`${DIRECTORY}/en.json`)
51+
const statsde = fs.lstatSync(`${DIRECTORY}/de.json`)
52+
should.exist(statsen)
53+
should.exist(statsde)
54+
})
55+
56+
it('should not have written unsupported locale files', () => {
57+
let statsfr
58+
try {
59+
statsfr = fs.lstatSync(`${DIRECTORY}/fr.json`)
60+
} catch (e) {
61+
should.equal(e.code, 'ENOENT')
62+
}
63+
should.not.exist(statsfr)
64+
})
65+
66+
it('should have written same data to all files', () => {
67+
const dataEn = readJson('en')
68+
const dataDe = readJson('de')
69+
should.deepEqual(dataEn, dataDe)
70+
})
71+
})
72+
73+
describe('reading', () => {
74+
writeJson('en', { test: 'test', welcome: 'welcome' })
75+
writeJson('de', { test: 'test', welcome: 'Willkommen' })
76+
const i18n = new I18n(CONFIG)
77+
const req = {}
78+
i18n.init(req)
79+
after(() => {
80+
try {
81+
fs.unlinkSync(`${DIRECTORY}/de.json`)
82+
fs.unlinkSync(`${DIRECTORY}/en.json`)
83+
fs.rmdirSync(DIRECTORY)
84+
} catch (e) {}
85+
})
86+
87+
it('should still return default locales value', () => {
88+
req.setLocale('en')
89+
should.equal(req.__('test'), 'test')
90+
should.equal(req.__('welcome'), 'welcome')
91+
92+
req.setLocale('de')
93+
should.equal(req.__('test'), 'test')
94+
should.equal(req.__('welcome'), 'Willkommen')
95+
96+
req.setLocale('fr')
97+
should.equal(req.__('test'), 'test')
98+
should.equal(req.__('welcome'), 'welcome')
99+
})
100+
})
101+
})

0 commit comments

Comments
 (0)