gettext-universal 1.0.10 → 1.0.11
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 +1 -4
- package/spec/gettext-universal.spec.js +13 -0
- package/src/translate.js +9 -9
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
},
|
|
5
5
|
"name": "gettext-universal",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.11",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"gettext-universal": "node bin/gettext-universal.js",
|
|
@@ -30,9 +30,6 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"diggerize": "^1.0.5"
|
|
32
32
|
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"expo-localization": "*"
|
|
35
|
-
},
|
|
36
33
|
"devDependencies": {
|
|
37
34
|
"jasmine": "^5.7.1"
|
|
38
35
|
}
|
|
@@ -25,4 +25,17 @@ describe("gettext-universal", () => {
|
|
|
25
25
|
|
|
26
26
|
expect(result).toEqual("Hello Kasper")
|
|
27
27
|
})
|
|
28
|
+
|
|
29
|
+
it("replaces placeholders with variables in defaults", () => {
|
|
30
|
+
config.setLocale(null)
|
|
31
|
+
config.locales = {
|
|
32
|
+
"en": {
|
|
33
|
+
"Hello world": "Hello world"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = translate("Hello %{name}", {name: "Kasper"})
|
|
38
|
+
|
|
39
|
+
expect(result).toEqual("Hello Kasper")
|
|
40
|
+
})
|
|
28
41
|
})
|
package/src/translate.js
CHANGED
|
@@ -15,23 +15,23 @@ const translate = (msgId, variables, args) => {
|
|
|
15
15
|
preferredLocales = [config.getLocale()]
|
|
16
16
|
} else {
|
|
17
17
|
console.error("No 'preferredLocales' was given and a locale wasn't set in the configuration either")
|
|
18
|
-
|
|
19
|
-
return msgId
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
let translation
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
const
|
|
23
|
+
if (preferredLocales) {
|
|
24
|
+
for (const preferredLocale of preferredLocales) {
|
|
25
|
+
const localeTranslations = config.getLocales()[preferredLocale]
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
if (!localeTranslations) continue
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
const localeTranslation = localeTranslations[msgId]
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (localeTranslation) {
|
|
32
|
+
translation = localeTranslation
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|