gettext-universal 1.0.7 → 1.0.8
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/config.js +3 -0
- package/src/events.js +5 -0
- package/src/use-translate-expo.js +5 -15
package/package.json
CHANGED
package/src/config.js
CHANGED
package/src/events.js
ADDED
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import config from "./config.js"
|
|
2
|
+
import events from "./events.js"
|
|
3
3
|
import translate from "./translate.js"
|
|
4
4
|
import {createContext, useCallback, useContext, useMemo, useState} from "react"
|
|
5
5
|
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter"
|
|
6
6
|
import {useLocales} from "expo-localization"
|
|
7
7
|
|
|
8
|
-
const eventEmitter = new EventEmitter()
|
|
9
8
|
const TranslateContext = createContext()
|
|
10
9
|
|
|
11
|
-
const shared = {
|
|
12
|
-
locale: null
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const setLocale = (locale) => {
|
|
16
|
-
shared.locale = locale
|
|
17
|
-
eventEmitter.emit("changeLocale", {locale})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
10
|
const WithTranslate = ({children, ...restProps}) => {
|
|
21
11
|
const locales = useLocales()
|
|
22
|
-
const [locale, setLocale] = useState(
|
|
12
|
+
const [locale, setLocale] = useState(config.getLocale())
|
|
23
13
|
|
|
24
14
|
const actualLocales = useMemo(() => {
|
|
25
15
|
const actualLocales = []
|
|
@@ -41,7 +31,7 @@ const WithTranslate = ({children, ...restProps}) => {
|
|
|
41
31
|
setLocale(locale)
|
|
42
32
|
}, [])
|
|
43
33
|
|
|
44
|
-
useEventEmitter(
|
|
34
|
+
useEventEmitter(events, "onLocaleChange", onChangeLocale)
|
|
45
35
|
|
|
46
36
|
const restPropsKeys = Object.keys(restProps)
|
|
47
37
|
|
|
@@ -85,5 +75,5 @@ const useTranslateExpo = () => {
|
|
|
85
75
|
return currentTranslation
|
|
86
76
|
}
|
|
87
77
|
|
|
88
|
-
export {
|
|
78
|
+
export {WithTranslate}
|
|
89
79
|
export default useTranslateExpo
|