@umituz/react-native-settings 5.2.27 → 5.2.29

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-settings",
3
- "version": "5.2.27",
3
+ "version": "5.2.29",
4
4
  "description": "Complete settings hub for React Native apps - consolidated package with settings, localization, about, legal, appearance, feedback, FAQs, rating, and gamification",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * Translation Hook
3
3
  *
4
- * Provides translation function with proper language change reactivity
5
- * - React i18next integration for automatic language change detection
6
- * - Auto-namespace detection from dot notation
7
- * - Type-safe translation function
4
+ * Provides translation function with proper language change reactivity.
5
+ * Keys use dot notation only: "namespace.key.subkey"
6
+ * The first segment before the dot is the i18next namespace.
8
7
  */
9
8
 
10
9
  import { useCallback } from 'react';
11
10
  import { useTranslation } from 'react-i18next';
12
11
  import i18n from '../config/i18n';
12
+ import { devWarn } from '../../../../utils/devUtils';
13
13
 
14
14
  export interface TranslationOptions {
15
15
  count?: number;
@@ -19,12 +19,11 @@ export interface TranslationOptions {
19
19
  }
20
20
 
21
21
  /**
22
- * Hook for translation functionality
23
- * Uses react-i18next for automatic language change reactivity
22
+ * Hook for translation functionality.
23
+ * Uses react-i18next for automatic language change reactivity.
24
24
  *
25
- * Supports both formats:
26
- * - t('namespace:key.subkey') - explicit namespace
27
- * - t('namespace.key.subkey') - auto-detected namespace (first segment before dot)
25
+ * Keys must use dot notation: t('namespace.key.subkey')
26
+ * The first segment is the i18next namespace: t('common.ok'), t('settings.title')
28
27
  */
29
28
  export const useTranslationFunction = () => {
30
29
  const { t: i18nextT, ready } = useTranslation(undefined, { i18n });
@@ -38,44 +37,20 @@ export const useTranslationFunction = () => {
38
37
  return options.defaultValue || key;
39
38
  }
40
39
 
41
- let finalResult: string;
40
+ // Convert dot notation to i18next namespace:key format
41
+ // "namespace.key.subkey" → i18next "namespace:key.subkey"
42
+ const firstDotIndex = key.indexOf('.');
43
+ const i18nextKey = firstDotIndex > 0
44
+ ? `${key.substring(0, firstDotIndex)}:${key.substring(firstDotIndex + 1)}`
45
+ : key;
42
46
 
43
- // If key already has namespace separator (:), use as-is
44
- if (key.includes(':')) {
45
- const result = i18nextT(key, options);
46
- finalResult = typeof result === 'string' ? result : key;
47
- } else {
48
- // Auto-detect namespace from first dot segment
49
- const firstDotIndex = key.indexOf('.');
50
- if (firstDotIndex > 0) {
51
- const potentialNamespace = key.substring(0, firstDotIndex);
52
- const restOfKey = key.substring(firstDotIndex + 1);
53
- const hasNamespace = i18n.hasResourceBundle(i18n.language, potentialNamespace);
54
-
55
- if (hasNamespace) {
56
- const namespacedKey = `${potentialNamespace}:${restOfKey}`;
57
- const namespacedResult = i18nextT(namespacedKey, options);
58
-
59
- if (namespacedResult !== namespacedKey && namespacedResult !== restOfKey) {
60
- finalResult = typeof namespacedResult === 'string' ? namespacedResult : key;
61
- } else {
62
- // Fallback to original key
63
- const result = i18nextT(key, options);
64
- finalResult = typeof result === 'string' ? result : key;
65
- }
66
- } else {
67
- // Fallback to original key
68
- const result = i18nextT(key, options);
69
- finalResult = typeof result === 'string' ? result : key;
70
- }
71
- } else {
72
- // Fallback to original key
73
- const result = i18nextT(key, options);
74
- finalResult = typeof result === 'string' ? result : key;
75
- }
47
+ // Missing translation is a critical issue warn in development
48
+ if (!i18n.exists(i18nextKey)) {
49
+ devWarn(`[i18n] Missing translation: "${key}"`);
76
50
  }
77
51
 
78
- return finalResult;
52
+ const result = i18nextT(i18nextKey, options);
53
+ return typeof result === 'string' ? result : (options.defaultValue ?? key);
79
54
  }, [i18nextT, ready]);
80
55
 
81
56
  return {