@umituz/react-native-localization 1.12.0 → 1.14.0

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
@@ -243,6 +243,26 @@ function MyComponent() {
243
243
  }
244
244
  ```
245
245
 
246
+ #### **Add Project Translations to Package i18n**
247
+
248
+ For better integration, add your project translations to the package i18n instance:
249
+
250
+ ```typescript
251
+ import { addTranslationResources } from '@umituz/react-native-localization';
252
+
253
+ // In your project's i18n config
254
+ const projectTranslations = require('./locales/en-US');
255
+
256
+ addTranslationResources({
257
+ 'en-US': {
258
+ translation: projectTranslations.default || projectTranslations,
259
+ },
260
+ // Add other languages as needed
261
+ });
262
+ ```
263
+
264
+ This ensures all translations work through the same i18n instance, preventing conflicts.
265
+
246
266
  ### Step 7: Translation Management
247
267
 
248
268
  #### Adding New Translations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-localization",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
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",
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ export { LanguageSwitcher } from './infrastructure/components/LanguageSwitcher';
12
12
  export { useLanguageNavigation } from './infrastructure/components/useLanguageNavigation';
13
13
 
14
14
  // Configuration
15
- export { default as i18n } from './infrastructure/config/i18n';
15
+ export { default as i18n, addTranslationResources } from './infrastructure/config/i18n';
16
16
  export {
17
17
  SUPPORTED_LANGUAGES,
18
18
  LANGUAGES, // Alias for SUPPORTED_LANGUAGES (backward compatibility)
@@ -197,4 +197,19 @@ const initializeI18n = () => {
197
197
  // CRITICAL: i18n.isInitialized check prevents multiple initializations
198
198
  initializeI18n();
199
199
 
200
+ /**
201
+ * Add additional translation resources to the existing i18n instance
202
+ * This allows projects to add their own translations to the package translations
203
+ */
204
+ export const addTranslationResources = (resources: Record<string, { translation: any }>) => {
205
+ for (const [langCode, resource] of Object.entries(resources)) {
206
+ if (resource.translation) {
207
+ // Merge with existing translations if any
208
+ const existingTranslations = i18n.getResourceBundle(langCode, 'translation') || {};
209
+ const mergedTranslations = { ...existingTranslations, ...resource.translation };
210
+ i18n.addResourceBundle(langCode, 'translation', mergedTranslations, true, true);
211
+ }
212
+ }
213
+ };
214
+
200
215
  export default i18n;