locon 1.4.1 → 1.4.3
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/README.md +12 -0
- package/dist/index.js +8 -2
- package/dist/index.mjs +9 -3
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## locon
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/locon)
|
|
4
|
+
[](https://github.com/loconapp/locon/tags)
|
|
5
|
+
[](https://github.com/loconapp/locon/actions/workflows/release.yml)
|
|
6
|
+
|
|
3
7
|
`locon` is a small, typed i18n helper for React Native.
|
|
4
8
|
It provides a context provider, a hook, and a simple text component to keep
|
|
5
9
|
your translations flat, explicit, and easy to use.
|
|
@@ -29,10 +33,18 @@ function Example() {
|
|
|
29
33
|
|
|
30
34
|
### Installation
|
|
31
35
|
|
|
36
|
+
Use your package manager of choice:
|
|
37
|
+
|
|
38
|
+
| npm | yarn | bun |
|
|
39
|
+
| ------------------- | ---------------- | --------------- |
|
|
40
|
+
| `npm install locon` | `yarn add locon` | `bun add locon` |
|
|
41
|
+
|
|
32
42
|
```bash
|
|
33
43
|
npm install locon
|
|
34
44
|
# or
|
|
35
45
|
yarn add locon
|
|
46
|
+
# or
|
|
47
|
+
bun add locon
|
|
36
48
|
```
|
|
37
49
|
|
|
38
50
|
**Important:** After installation, run pod install for iOS:
|
package/dist/index.js
CHANGED
|
@@ -58,6 +58,7 @@ function Locon({
|
|
|
58
58
|
projectLocale = "en",
|
|
59
59
|
autodetect = true
|
|
60
60
|
}) {
|
|
61
|
+
const resolvedProjectLocale = projectLocale || defaultLocale;
|
|
61
62
|
const [currentLocale, setCurrentLocale] = (0, import_react.useState)(() => {
|
|
62
63
|
if (currentLocaleProps) {
|
|
63
64
|
return currentLocaleProps;
|
|
@@ -92,7 +93,7 @@ function Locon({
|
|
|
92
93
|
[assets]
|
|
93
94
|
);
|
|
94
95
|
const getAssetByValue = (0, import_react.useCallback)(
|
|
95
|
-
(assetValue, locale =
|
|
96
|
+
(assetValue, locale = resolvedProjectLocale) => {
|
|
96
97
|
const currentAssets = assets[locale];
|
|
97
98
|
if (!currentAssets) {
|
|
98
99
|
return void 0;
|
|
@@ -100,7 +101,7 @@ function Locon({
|
|
|
100
101
|
const assetKey = Object.keys(currentAssets).find((key) => currentAssets[key] === assetValue);
|
|
101
102
|
return assetKey ? getAsset(assetKey) : void 0;
|
|
102
103
|
},
|
|
103
|
-
[assets, getAsset,
|
|
104
|
+
[assets, getAsset, resolvedProjectLocale]
|
|
104
105
|
);
|
|
105
106
|
const l = (0, import_react.useCallback)(
|
|
106
107
|
(assetKey) => {
|
|
@@ -112,6 +113,11 @@ function Locon({
|
|
|
112
113
|
},
|
|
113
114
|
[getAsset, getAssetByValue, defaultLocale]
|
|
114
115
|
);
|
|
116
|
+
(0, import_react.useEffect)(() => {
|
|
117
|
+
if (currentLocaleProps && currentLocaleProps !== currentLocale) {
|
|
118
|
+
setCurrentLocale(currentLocaleProps);
|
|
119
|
+
}
|
|
120
|
+
}, [currentLocaleProps, currentLocale]);
|
|
115
121
|
const value = (0, import_react.useMemo)(
|
|
116
122
|
() => ({
|
|
117
123
|
assets,
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { createContext, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import getSystemLanguage from "./utils/getSystemLanguage";
|
|
4
4
|
const LoconContext = createContext({
|
|
5
5
|
assets: {},
|
|
@@ -20,6 +20,7 @@ function Locon({
|
|
|
20
20
|
projectLocale = "en",
|
|
21
21
|
autodetect = true
|
|
22
22
|
}) {
|
|
23
|
+
const resolvedProjectLocale = projectLocale || defaultLocale;
|
|
23
24
|
const [currentLocale, setCurrentLocale] = useState(() => {
|
|
24
25
|
if (currentLocaleProps) {
|
|
25
26
|
return currentLocaleProps;
|
|
@@ -54,7 +55,7 @@ function Locon({
|
|
|
54
55
|
[assets]
|
|
55
56
|
);
|
|
56
57
|
const getAssetByValue = useCallback(
|
|
57
|
-
(assetValue, locale =
|
|
58
|
+
(assetValue, locale = resolvedProjectLocale) => {
|
|
58
59
|
const currentAssets = assets[locale];
|
|
59
60
|
if (!currentAssets) {
|
|
60
61
|
return void 0;
|
|
@@ -62,7 +63,7 @@ function Locon({
|
|
|
62
63
|
const assetKey = Object.keys(currentAssets).find((key) => currentAssets[key] === assetValue);
|
|
63
64
|
return assetKey ? getAsset(assetKey) : void 0;
|
|
64
65
|
},
|
|
65
|
-
[assets, getAsset,
|
|
66
|
+
[assets, getAsset, resolvedProjectLocale]
|
|
66
67
|
);
|
|
67
68
|
const l = useCallback(
|
|
68
69
|
(assetKey) => {
|
|
@@ -74,6 +75,11 @@ function Locon({
|
|
|
74
75
|
},
|
|
75
76
|
[getAsset, getAssetByValue, defaultLocale]
|
|
76
77
|
);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (currentLocaleProps && currentLocaleProps !== currentLocale) {
|
|
80
|
+
setCurrentLocale(currentLocaleProps);
|
|
81
|
+
}
|
|
82
|
+
}, [currentLocaleProps, currentLocale]);
|
|
77
83
|
const value = useMemo(
|
|
78
84
|
() => ({
|
|
79
85
|
assets,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locon",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "locon is a simple and lightweight library for React Native that provides a simple way to manage translations in your app.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -41,10 +41,6 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@babel/preset-react": "^7.24.7",
|
|
43
43
|
"@eslint/js": "^9.10.0",
|
|
44
|
-
"@semantic-release/exec": "^6.0.3",
|
|
45
|
-
"@semantic-release/git": "^10.0.1",
|
|
46
|
-
"@semantic-release/github": "11.0.1",
|
|
47
|
-
"@semantic-release/npm": "^12.0.1",
|
|
48
44
|
"@testing-library/jest-dom": "^6.5.0",
|
|
49
45
|
"@testing-library/react": "^16.0.1",
|
|
50
46
|
"@types/jest": "^29.5.12",
|