@umituz/react-native-localization 2.2.0 → 2.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
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",
@@ -14,24 +14,62 @@ import i18n from '../config/i18n';
14
14
  * Hook for translation functionality
15
15
  */
16
16
  export const useTranslationFunction = (): ((key: string, options?: any) => string) => {
17
- // Always call useTranslation hook (React hooks rules)
18
- const translationResult = useTranslation(undefined, { i18n });
17
+ // Ensure settings translations are loaded
18
+ if (i18n.isInitialized && typeof i18n.t === 'function') {
19
+ const existingTranslations = i18n.getResourceBundle('en-US', 'translation') || {};
19
20
 
20
- // Use react-i18next if available, otherwise fallback to direct i18n
21
- if (translationResult?.t && typeof translationResult.t === 'function' && i18n.isInitialized) {
22
- return (key: string, options?: any): string => {
23
- const result = translationResult.t(key, options);
24
- return typeof result === 'string' ? result : String(result);
25
- };
26
- } else {
27
- return (key: string, options?: any): string => {
28
- // Fallback to direct i18n.t
29
- if (i18n.isInitialized && typeof i18n.t === 'function') {
30
- const result = i18n.t(key, options);
31
- return typeof result === 'string' ? result : String(result);
32
- }
33
- // Final fallback: return key
34
- return key;
35
- };
21
+ // Check if settings translations are missing
22
+ if (!existingTranslations.settings) {
23
+ // Add settings translations as fallback
24
+ const settingsTranslations = {
25
+ settings: {
26
+ editProfile: "Edit Profile",
27
+ sections: {
28
+ physicalInfoAndGoals: "Physical Info and Goals",
29
+ appSettings: "App Settings",
30
+ accountManagement: "Account Management"
31
+ },
32
+ personalInfo: {
33
+ title: "Personal Information",
34
+ subtitle: "Height, Weight, Age, Gender"
35
+ },
36
+ nutritionGoals: {
37
+ title: "Nutrition Goals",
38
+ subtitle: "Calories, Protein, Carbs, Fat"
39
+ },
40
+ notifications: {
41
+ title: "Notification Preferences",
42
+ subtitle: "Water and meal reminders"
43
+ },
44
+ darkMode: {
45
+ title: "Dark Mode",
46
+ subtitle: "Change app theme"
47
+ },
48
+ passwordChange: {
49
+ title: "Change Password"
50
+ },
51
+ saveChanges: "Save Changes",
52
+ logout: "Logout",
53
+ emptyState: {
54
+ title: "No recipes yet",
55
+ subtitle: "Create your first recipe to get started"
56
+ },
57
+ addToList: "Add to List"
58
+ }
59
+ };
60
+
61
+ const mergedTranslations = { ...existingTranslations, ...settingsTranslations };
62
+ i18n.addResourceBundle('en-US', 'translation', mergedTranslations, true, true);
63
+ }
36
64
  }
65
+
66
+ // Use direct i18n.t for reliability (no React context issues)
67
+ return (key: string, options?: any): string => {
68
+ if (i18n.isInitialized && typeof i18n.t === 'function') {
69
+ const result = i18n.t(key, options);
70
+ return typeof result === 'string' ? result : String(result);
71
+ }
72
+ // Final fallback: return key
73
+ return key;
74
+ };
37
75
  };