gettext-universal 1.0.4 → 1.0.5
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 -1
- package/src/translate.js +17 -2
- package/src/use-translate-expo.js +5 -1
package/package.json
CHANGED
package/src/translate.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import config from "./config.js"
|
|
2
2
|
|
|
3
|
-
const translate = (msgId,
|
|
3
|
+
const translate = (msgId, args) => {
|
|
4
|
+
let preferredLocales
|
|
5
|
+
|
|
6
|
+
if (Array.isArray(args)) {
|
|
7
|
+
preferredLocales = args
|
|
8
|
+
args = null
|
|
9
|
+
} else if (args?.locales) {
|
|
10
|
+
preferredLocales = args.locales
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
if (!preferredLocales) {
|
|
5
14
|
if (config.getLocale()) {
|
|
6
15
|
preferredLocales = [config.getLocale()]
|
|
@@ -41,7 +50,13 @@ const translate = (msgId, preferredLocales) => {
|
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
if (!translation)
|
|
53
|
+
if (!translation) {
|
|
54
|
+
if (args?.defaultValue) {
|
|
55
|
+
translation = args.defaultValue
|
|
56
|
+
} else {
|
|
57
|
+
translation = msgId
|
|
58
|
+
}
|
|
59
|
+
}
|
|
45
60
|
|
|
46
61
|
return translation
|
|
47
62
|
}
|
|
@@ -10,7 +10,11 @@ const useTranslateExpo = () => {
|
|
|
10
10
|
preferredLocales = locales?.map((localeData) => localeData.languageCode)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const currentTranslation = useCallback((msgId
|
|
13
|
+
const currentTranslation = useCallback((msgId, args = {}) => {
|
|
14
|
+
args.locales = preferredLocales
|
|
15
|
+
|
|
16
|
+
return translate(msgId, args)
|
|
17
|
+
}, [preferredLocales])
|
|
14
18
|
|
|
15
19
|
return currentTranslation
|
|
16
20
|
}
|