@umituz/react-native-localization 1.16.0 → 1.16.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "English-only localization system for React Native apps with i18n support",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -18,7 +18,33 @@ import { loadJsonModules } from '@umituz/react-native-filesystem';
18
18
  // eslint-disable-next-line @typescript-eslint/no-require-imports
19
19
  const translationContext = (require as any).context('./', false, /\.json$/);
20
20
 
21
+ /**
22
+ * Flatten nested objects with dot notation
23
+ */
24
+ const flattenObject = (
25
+ obj: Record<string, any>,
26
+ prefix = '',
27
+ ): Record<string, string> => {
28
+ const flattened: Record<string, string> = {};
29
+
30
+ Object.keys(obj).forEach((key) => {
31
+ const newKey = prefix ? `${prefix}.${key}` : key;
32
+
33
+ if (obj[key] && typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
34
+ Object.assign(flattened, flattenObject(obj[key], newKey));
35
+ } else {
36
+ flattened[newKey] = obj[key];
37
+ }
38
+ });
39
+
40
+ return flattened;
41
+ };
42
+
21
43
  // Load all JSON modules automatically using filesystem utility
22
- const translations = loadJsonModules(translationContext);
44
+ const modules = loadJsonModules(translationContext);
45
+
46
+ // Flatten all translations with dot notation
47
+ // Creates keys like: home.title, goals.title, progress.title
48
+ const translations = flattenObject(modules);
23
49
 
24
50
  export default translations;