locon 1.4.0 → 1.4.2

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  ## locon
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/locon.svg)](https://www.npmjs.com/package/locon)
4
+ [![GitHub release](https://img.shields.io/github/v/release/loconapp/locon?display_name=tag)](https://github.com/loconapp/locon/releases)
5
+ [![Release workflow](https://github.com/loconapp/locon/actions/workflows/release.yml/badge.svg)](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:
@@ -45,9 +57,22 @@ cd ios && pod install
45
57
 
46
58
  - `react >= 19.0.0`
47
59
  - `react-native >= 0.70.0`
48
- - `react-native-localize >= 3.0.0` (installed automatically)
60
+ - `react-native-localize >= 3.0.0` (optional, but recommended for accurate device language detection)
49
61
 
50
62
  `react-native-localize` is used for accurate device language detection on iOS and Android.
63
+ It is not installed automatically — add it to your app if you want native locale detection:
64
+
65
+ ```bash
66
+ yarn add react-native-localize
67
+ # or
68
+ npm install react-native-localize
69
+ ```
70
+
71
+ Then run iOS pods:
72
+
73
+ ```bash
74
+ cd ios && pod install
75
+ ```
51
76
 
52
77
  ---
53
78
 
@@ -113,11 +138,13 @@ export default App
113
138
  If `currentLocale` is not provided and `autodetect` is `true` (default),
114
139
  `locon` will:
115
140
 
116
- 1. Use `react-native-localize` to detect device locale on iOS/Android
141
+ 1. Use `react-native-localize` (if installed) to detect device locale on iOS/Android
117
142
  2. Match the detected locale (including region) or just language code against your `assets`
118
143
  3. If a match is found, use it as initial locale
119
144
  4. Otherwise, fall back to `defaultLocale`
120
145
 
146
+ If `react-native-localize` is not installed, `locon` falls back to the Intl API.
147
+
121
148
  #### 3. Use the `useLocon()` hook
122
149
 
123
150
  ```tsx
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 = projectLocale) => {
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, projectLocale]
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 = projectLocale) => {
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, projectLocale]
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.0",
3
+ "version": "1.4.2",
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",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "tsup",
13
13
  "test": "jest",
14
- "publish": "npm publish"
14
+ "publish": "npm publish",
15
+ "release": "semantic-release"
15
16
  },
16
17
  "keywords": [
17
18
  "i18n",
@@ -41,10 +42,13 @@
41
42
  "devDependencies": {
42
43
  "@babel/preset-react": "^7.24.7",
43
44
  "@eslint/js": "^9.10.0",
45
+ "@semantic-release/commit-analyzer": "^10.0.1",
44
46
  "@semantic-release/exec": "^6.0.3",
45
47
  "@semantic-release/git": "^10.0.1",
46
48
  "@semantic-release/github": "11.0.1",
47
49
  "@semantic-release/npm": "^12.0.1",
50
+ "@semantic-release/release-notes-generator": "^10.0.1",
51
+ "semantic-release": "^22.0.0",
48
52
  "@testing-library/jest-dom": "^6.5.0",
49
53
  "@testing-library/react": "^16.0.1",
50
54
  "@types/jest": "^29.5.12",