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 CHANGED
@@ -4,7 +4,7 @@
4
4
  },
5
5
  "name": "gettext-universal",
6
6
  "type": "module",
7
- "version": "1.0.4",
7
+ "version": "1.0.5",
8
8
  "main": "index.js",
9
9
  "scripts": {
10
10
  "gettext-universal": "node bin/gettext-universal.js",
package/src/translate.js CHANGED
@@ -1,6 +1,15 @@
1
1
  import config from "./config.js"
2
2
 
3
- const translate = (msgId, preferredLocales) => {
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) translation = msgId
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) => translate(msgId, preferredLocales), [preferredLocales])
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
  }