@umituz/react-native-localization 3.5.0 → 3.5.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/package.json +5 -6
- package/src/infrastructure/hooks/useTranslation.ts +6 -5
- package/src/scripts/prepublish.ts +1 -1
- package/{scripts/translate-missing.js → src/scripts/translate-missing.ts} +9 -2
- package/scripts/prepublish.js +0 -48
- /package/{scripts/setup-languages.js → src/scripts/setup-languages.ts} +0 -0
- /package/{scripts/sync-translations.js → src/scripts/sync-translations.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-localization",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "Generic localization system for React Native apps with i18n support",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"test:watch": "jest --watch",
|
|
12
12
|
"test:coverage": "jest --coverage",
|
|
13
|
-
"prepublishOnly": "node scripts/prepublish.
|
|
13
|
+
"prepublishOnly": "ts-node src/scripts/prepublish.ts",
|
|
14
14
|
"version:patch": "npm version patch -m 'chore: release v%s'",
|
|
15
15
|
"version:minor": "npm version minor -m 'chore: release v%s'",
|
|
16
16
|
"version:major": "npm version major -m 'chore: release v%s'",
|
|
17
|
-
"i18n:setup": "node scripts/setup-languages.
|
|
18
|
-
"i18n:sync": "node scripts/sync-translations.
|
|
19
|
-
"i18n:translate": "node scripts/translate-missing.
|
|
17
|
+
"i18n:setup": "ts-node src/scripts/setup-languages.ts",
|
|
18
|
+
"i18n:sync": "ts-node src/scripts/sync-translations.ts",
|
|
19
|
+
"i18n:translate": "ts-node src/scripts/translate-missing.ts"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"react-native",
|
|
@@ -90,7 +90,6 @@
|
|
|
90
90
|
},
|
|
91
91
|
"files": [
|
|
92
92
|
"src",
|
|
93
|
-
"scripts",
|
|
94
93
|
"README.md",
|
|
95
94
|
"LICENSE"
|
|
96
95
|
]
|
|
@@ -15,7 +15,7 @@ export interface TranslationOptions {
|
|
|
15
15
|
count?: number;
|
|
16
16
|
ns?: string | string[];
|
|
17
17
|
defaultValue?: string;
|
|
18
|
-
[key: string]:
|
|
18
|
+
[key: string]: unknown;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -29,11 +29,12 @@ export interface TranslationOptions {
|
|
|
29
29
|
export const useTranslationFunction = () => {
|
|
30
30
|
const { t: i18nextT, ready } = useTranslation(undefined, { i18n });
|
|
31
31
|
|
|
32
|
-
const translate = useCallback((key: string,
|
|
32
|
+
const translate = useCallback((key: string, defaultValueOrOptions?: string | TranslationOptions): string => {
|
|
33
|
+
const options: TranslationOptions = typeof defaultValueOrOptions === 'string'
|
|
34
|
+
? { defaultValue: defaultValueOrOptions }
|
|
35
|
+
: defaultValueOrOptions || {};
|
|
36
|
+
|
|
33
37
|
if (!ready || !i18n.isInitialized) {
|
|
34
|
-
if (__DEV__) {
|
|
35
|
-
console.warn(`[Localization] i18n not ready, returning key: ${key}`);
|
|
36
|
-
}
|
|
37
38
|
return options.defaultValue || key;
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -13,7 +13,7 @@ import { fileURLToPath } from 'url';
|
|
|
13
13
|
|
|
14
14
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
15
|
const __dirname = path.dirname(__filename);
|
|
16
|
-
const PACKAGE_ROOT = path.resolve(__dirname, '..');
|
|
16
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
17
17
|
const SRC_DIR = path.join(PACKAGE_ROOT, 'src');
|
|
18
18
|
|
|
19
19
|
console.log('🔍 Pre-publish checks...\n');
|
|
@@ -117,15 +117,22 @@ function generateTypeScriptContent(obj, langCode) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
if (typeof value === 'object' && value !== null) {
|
|
120
|
+
const entries = Object.entries(value);
|
|
121
|
+
|
|
122
|
+
// Handle empty objects
|
|
123
|
+
if (entries.length === 0) {
|
|
124
|
+
return '{}';
|
|
125
|
+
}
|
|
126
|
+
|
|
120
127
|
const spaces = ' '.repeat(indent);
|
|
121
128
|
const innerSpaces = ' '.repeat(indent + 2);
|
|
122
|
-
const
|
|
129
|
+
const entriesStr = entries
|
|
123
130
|
.map(([k, v]) => {
|
|
124
131
|
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(k) ? k : `"${k}"`;
|
|
125
132
|
return `${innerSpaces}${key}: ${stringifyValue(v, indent + 2)}`;
|
|
126
133
|
})
|
|
127
134
|
.join(',\n');
|
|
128
|
-
return `{\n${
|
|
135
|
+
return `{\n${entriesStr},\n${spaces}}`;
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
return String(value);
|
package/scripts/prepublish.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Pre-Publish Script - Generic Package Version
|
|
6
|
-
*
|
|
7
|
-
* Basic checks before publishing for generic localization package
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import { fileURLToPath } from 'url';
|
|
13
|
-
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = path.dirname(__filename);
|
|
16
|
-
const PACKAGE_ROOT = path.resolve(__dirname, '..');
|
|
17
|
-
const SRC_DIR = path.join(PACKAGE_ROOT, 'src');
|
|
18
|
-
|
|
19
|
-
console.log('🔍 Pre-publish checks...\n');
|
|
20
|
-
|
|
21
|
-
// Check if src directory exists
|
|
22
|
-
if (!fs.existsSync(SRC_DIR)) {
|
|
23
|
-
console.error('❌ src directory not found!');
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Check if main files exist
|
|
28
|
-
const mainFiles = [
|
|
29
|
-
'src/index.ts',
|
|
30
|
-
'src/infrastructure/config/i18n.ts',
|
|
31
|
-
'src/infrastructure/storage/LocalizationStore.ts',
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
let allFilesExist = true;
|
|
35
|
-
for (const file of mainFiles) {
|
|
36
|
-
const filePath = path.join(PACKAGE_ROOT, file);
|
|
37
|
-
if (!fs.existsSync(filePath)) {
|
|
38
|
-
console.error(`❌ Required file not found: ${file}`);
|
|
39
|
-
allFilesExist = false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!allFilesExist) {
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
console.log('✅ All required files found');
|
|
48
|
-
console.log('✅ Pre-publish checks passed!\n');
|
|
File without changes
|
|
File without changes
|