@umituz/react-native-localization 1.0.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/LICENSE +21 -0
- package/README.md +292 -0
- package/lib/domain/repositories/ILocalizationRepository.d.ts +17 -0
- package/lib/domain/repositories/ILocalizationRepository.d.ts.map +1 -0
- package/lib/domain/repositories/ILocalizationRepository.js +6 -0
- package/lib/domain/repositories/ILocalizationRepository.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/components/LocalizationProvider.d.ts +11 -0
- package/lib/infrastructure/components/LocalizationProvider.d.ts.map +1 -0
- package/lib/infrastructure/components/LocalizationProvider.js +14 -0
- package/lib/infrastructure/components/LocalizationProvider.js.map +1 -0
- package/lib/infrastructure/config/i18n.d.ts +7 -0
- package/lib/infrastructure/config/i18n.d.ts.map +1 -0
- package/lib/infrastructure/config/i18n.js +49 -0
- package/lib/infrastructure/config/i18n.js.map +1 -0
- package/lib/infrastructure/config/languages.d.ts +34 -0
- package/lib/infrastructure/config/languages.d.ts.map +1 -0
- package/lib/infrastructure/config/languages.js +200 -0
- package/lib/infrastructure/config/languages.js.map +1 -0
- package/lib/infrastructure/config/languagesData.d.ts +7 -0
- package/lib/infrastructure/config/languagesData.d.ts.map +1 -0
- package/lib/infrastructure/config/languagesData.js +36 -0
- package/lib/infrastructure/config/languagesData.js.map +1 -0
- package/lib/infrastructure/locales/en-US/animation.json +30 -0
- package/lib/infrastructure/locales/en-US/audio.json +56 -0
- package/lib/infrastructure/locales/en-US/datetime.json +140 -0
- package/lib/infrastructure/locales/en-US/emoji.json +29 -0
- package/lib/infrastructure/locales/en-US/errors.json +43 -0
- package/lib/infrastructure/locales/en-US/forms.json +38 -0
- package/lib/infrastructure/locales/en-US/general.json +56 -0
- package/lib/infrastructure/locales/en-US/icons.json +34 -0
- package/lib/infrastructure/locales/en-US/index.d.ts +757 -0
- package/lib/infrastructure/locales/en-US/index.d.ts.map +1 -0
- package/lib/infrastructure/locales/en-US/index.js +35 -0
- package/lib/infrastructure/locales/en-US/index.js.map +1 -0
- package/lib/infrastructure/locales/en-US/location.json +49 -0
- package/lib/infrastructure/locales/en-US/media.json +49 -0
- package/lib/infrastructure/locales/en-US/navigation.json +52 -0
- package/lib/infrastructure/locales/en-US/onboarding.json +76 -0
- package/lib/infrastructure/locales/en-US/settings.json +65 -0
- package/lib/infrastructure/locales/en-US/toast.json +38 -0
- package/lib/infrastructure/storage/AsyncStorageWrapper.d.ts +12 -0
- package/lib/infrastructure/storage/AsyncStorageWrapper.d.ts.map +1 -0
- package/lib/infrastructure/storage/AsyncStorageWrapper.js +29 -0
- package/lib/infrastructure/storage/AsyncStorageWrapper.js.map +1 -0
- package/lib/infrastructure/storage/LocalizationStore.d.ts +30 -0
- package/lib/infrastructure/storage/LocalizationStore.d.ts.map +1 -0
- package/lib/infrastructure/storage/LocalizationStore.js +90 -0
- package/lib/infrastructure/storage/LocalizationStore.js.map +1 -0
- package/package.json +64 -0
- package/src/domain/repositories/ILocalizationRepository.ts +18 -0
- package/src/index.ts +24 -0
- package/src/infrastructure/components/LocalizationProvider.tsx +21 -0
- package/src/infrastructure/config/i18n.ts +57 -0
- package/src/infrastructure/config/languages.ts +245 -0
- package/src/infrastructure/config/languagesData.ts +38 -0
- package/src/infrastructure/locales/en-US/animation.json +30 -0
- package/src/infrastructure/locales/en-US/audio.json +56 -0
- package/src/infrastructure/locales/en-US/datetime.json +140 -0
- package/src/infrastructure/locales/en-US/emoji.json +29 -0
- package/src/infrastructure/locales/en-US/errors.json +43 -0
- package/src/infrastructure/locales/en-US/forms.json +38 -0
- package/src/infrastructure/locales/en-US/general.json +56 -0
- package/src/infrastructure/locales/en-US/icons.json +34 -0
- package/src/infrastructure/locales/en-US/index.ts +36 -0
- package/src/infrastructure/locales/en-US/location.json +49 -0
- package/src/infrastructure/locales/en-US/media.json +49 -0
- package/src/infrastructure/locales/en-US/navigation.json +52 -0
- package/src/infrastructure/locales/en-US/onboarding.json +76 -0
- package/src/infrastructure/locales/en-US/settings.json +65 -0
- package/src/infrastructure/locales/en-US/toast.json +38 -0
- package/src/infrastructure/storage/AsyncStorageWrapper.ts +30 -0
- package/src/infrastructure/storage/LocalizationStore.ts +118 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ümit UZ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# @umituz/react-native-localization
|
|
2
|
+
|
|
3
|
+
Universal localization system for React Native apps with i18n support. Built with Domain-Driven Design principles and TypeScript.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **29+ Language Support**: Pre-configured support for 29 languages including RTL languages (Arabic)
|
|
8
|
+
- **Automatic Device Locale Detection**: Automatically detects and applies device language on first launch
|
|
9
|
+
- **Persistent Language Preferences**: Saves user's language choice using AsyncStorage
|
|
10
|
+
- **Type-Safe**: Full TypeScript support with type definitions
|
|
11
|
+
- **Zero Configuration**: Works out of the box with sensible defaults
|
|
12
|
+
- **Production Ready**: Battle-tested in production apps
|
|
13
|
+
- **Lightweight**: Minimal dependencies with tree-shakeable exports
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @umituz/react-native-localization
|
|
19
|
+
# or
|
|
20
|
+
yarn add @umituz/react-native-localization
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Peer Dependencies
|
|
24
|
+
|
|
25
|
+
Make sure you have the following peer dependencies installed:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install zustand i18next react-i18next expo-localization @react-native-async-storage/async-storage
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### 1. Wrap Your App with LocalizationProvider
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { LocalizationProvider } from '@umituz/react-native-localization';
|
|
37
|
+
|
|
38
|
+
export default function App() {
|
|
39
|
+
return (
|
|
40
|
+
<LocalizationProvider>
|
|
41
|
+
<YourApp />
|
|
42
|
+
</LocalizationProvider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. Use Localization in Your Components
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { useLocalization } from '@umituz/react-native-localization';
|
|
51
|
+
|
|
52
|
+
function MyComponent() {
|
|
53
|
+
const { t, currentLanguage, setLanguage } = useLocalization();
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<View>
|
|
57
|
+
<Text>{t('general.welcome')}</Text>
|
|
58
|
+
<Text>Current Language: {currentLanguage}</Text>
|
|
59
|
+
<Button title="Switch to Turkish" onPress={() => setLanguage('tr-TR')} />
|
|
60
|
+
</View>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### `useLocalization()`
|
|
68
|
+
|
|
69
|
+
Main hook to access localization functionality.
|
|
70
|
+
|
|
71
|
+
**Returns:**
|
|
72
|
+
- `t`: Translation function
|
|
73
|
+
- `currentLanguage`: Current language code (e.g., 'en-US')
|
|
74
|
+
- `currentLanguageObject`: Full language object with metadata
|
|
75
|
+
- `isRTL`: Boolean indicating if current language is RTL
|
|
76
|
+
- `isInitialized`: Boolean indicating if localization is ready
|
|
77
|
+
- `supportedLanguages`: Array of all supported languages
|
|
78
|
+
- `setLanguage`: Function to change language
|
|
79
|
+
- `initialize`: Function to manually initialize (auto-called by provider)
|
|
80
|
+
|
|
81
|
+
### `LocalizationProvider`
|
|
82
|
+
|
|
83
|
+
Component that initializes the localization system. Wrap your app with this component.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<LocalizationProvider>
|
|
87
|
+
<App />
|
|
88
|
+
</LocalizationProvider>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Helper Functions
|
|
92
|
+
|
|
93
|
+
#### `getLanguageByCode(code: string)`
|
|
94
|
+
|
|
95
|
+
Get language object by language code.
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { getLanguageByCode } from '@umituz/react-native-localization';
|
|
99
|
+
|
|
100
|
+
const language = getLanguageByCode('en-US');
|
|
101
|
+
// Returns: { code: 'en-US', name: 'English', nativeName: 'English', flag: '🇺🇸', rtl: false }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### `getDefaultLanguage()`
|
|
105
|
+
|
|
106
|
+
Get the default language object (English US).
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { getDefaultLanguage } from '@umituz/react-native-localization';
|
|
110
|
+
|
|
111
|
+
const defaultLang = getDefaultLanguage();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### `getDeviceLocale()`
|
|
115
|
+
|
|
116
|
+
Get device's locale and map it to a supported language.
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
import { getDeviceLocale } from '@umituz/react-native-localization';
|
|
120
|
+
|
|
121
|
+
const deviceLanguage = getDeviceLocale();
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Supported Languages
|
|
125
|
+
|
|
126
|
+
The package comes with pre-configured support for 29 languages:
|
|
127
|
+
|
|
128
|
+
| Language | Code | RTL |
|
|
129
|
+
|----------|------|-----|
|
|
130
|
+
| English | en-US | No |
|
|
131
|
+
| Arabic | ar-SA | Yes |
|
|
132
|
+
| Bulgarian | bg-BG | No |
|
|
133
|
+
| Czech | cs-CZ | No |
|
|
134
|
+
| Danish | da-DK | No |
|
|
135
|
+
| German | de-DE | No |
|
|
136
|
+
| Spanish | es-ES | No |
|
|
137
|
+
| Finnish | fi-FI | No |
|
|
138
|
+
| French | fr-FR | No |
|
|
139
|
+
| Hindi | hi-IN | No |
|
|
140
|
+
| Hungarian | hu-HU | No |
|
|
141
|
+
| Indonesian | id-ID | No |
|
|
142
|
+
| Italian | it-IT | No |
|
|
143
|
+
| Japanese | ja-JP | No |
|
|
144
|
+
| Korean | ko-KR | No |
|
|
145
|
+
| Malay | ms-MY | No |
|
|
146
|
+
| Dutch | nl-NL | No |
|
|
147
|
+
| Norwegian | no-NO | No |
|
|
148
|
+
| Polish | pl-PL | No |
|
|
149
|
+
| Portuguese | pt-PT | No |
|
|
150
|
+
| Romanian | ro-RO | No |
|
|
151
|
+
| Russian | ru-RU | No |
|
|
152
|
+
| Swedish | sv-SE | No |
|
|
153
|
+
| Thai | th-TH | No |
|
|
154
|
+
| Filipino | tl-PH | No |
|
|
155
|
+
| Turkish | tr-TR | No |
|
|
156
|
+
| Ukrainian | uk-UA | No |
|
|
157
|
+
| Vietnamese | vi-VN | No |
|
|
158
|
+
| Chinese (Simplified) | zh-CN | No |
|
|
159
|
+
|
|
160
|
+
## Translation Structure
|
|
161
|
+
|
|
162
|
+
The package includes common translations organized by domain:
|
|
163
|
+
|
|
164
|
+
- `animation`: Animation-related translations
|
|
165
|
+
- `audio`: Audio-related translations
|
|
166
|
+
- `datetime`: Date and time translations
|
|
167
|
+
- `emoji`: Emoji-related translations
|
|
168
|
+
- `errors`: Error messages
|
|
169
|
+
- `forms`: Form labels and validation
|
|
170
|
+
- `general`: General UI text
|
|
171
|
+
- `icons`: Icon labels
|
|
172
|
+
- `location`: Location-related translations
|
|
173
|
+
- `media`: Media-related translations
|
|
174
|
+
- `navigation`: Navigation labels
|
|
175
|
+
- `onboarding`: Onboarding flow text
|
|
176
|
+
- `settings`: Settings screen text
|
|
177
|
+
- `toast`: Toast notification messages
|
|
178
|
+
|
|
179
|
+
### Example Translation Usage
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
// Access nested translations
|
|
183
|
+
t('general.welcome')
|
|
184
|
+
t('errors.network.title')
|
|
185
|
+
t('settings.language.title')
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Advanced Usage
|
|
189
|
+
|
|
190
|
+
### Language Selector Component
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
import { useLocalization, SUPPORTED_LANGUAGES } from '@umituz/react-native-localization';
|
|
194
|
+
import { FlatList, TouchableOpacity, Text } from 'react-native';
|
|
195
|
+
|
|
196
|
+
function LanguageSelector() {
|
|
197
|
+
const { currentLanguage, setLanguage } = useLocalization();
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
<FlatList
|
|
201
|
+
data={SUPPORTED_LANGUAGES}
|
|
202
|
+
keyExtractor={(item) => item.code}
|
|
203
|
+
renderItem={({ item }) => (
|
|
204
|
+
<TouchableOpacity onPress={() => setLanguage(item.code)}>
|
|
205
|
+
<Text>
|
|
206
|
+
{item.flag} {item.nativeName}
|
|
207
|
+
{currentLanguage === item.code && ' ✓'}
|
|
208
|
+
</Text>
|
|
209
|
+
</TouchableOpacity>
|
|
210
|
+
)}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### RTL Support
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import { useLocalization } from '@umituz/react-native-localization';
|
|
220
|
+
import { I18nManager } from 'react-native';
|
|
221
|
+
|
|
222
|
+
function MyComponent() {
|
|
223
|
+
const { isRTL } = useLocalization();
|
|
224
|
+
|
|
225
|
+
// Apply RTL layout
|
|
226
|
+
React.useEffect(() => {
|
|
227
|
+
I18nManager.forceRTL(isRTL);
|
|
228
|
+
}, [isRTL]);
|
|
229
|
+
|
|
230
|
+
return <View style={{ flexDirection: isRTL ? 'row-reverse' : 'row' }} />;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Custom Translations
|
|
235
|
+
|
|
236
|
+
You can extend the translations by adding your own:
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
import { i18n } from '@umituz/react-native-localization';
|
|
240
|
+
|
|
241
|
+
// Add custom translations
|
|
242
|
+
i18n.addResources('en-US', 'translation', {
|
|
243
|
+
myFeature: {
|
|
244
|
+
title: 'My Feature',
|
|
245
|
+
description: 'Feature description'
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Use in components
|
|
250
|
+
const { t } = useLocalization();
|
|
251
|
+
console.log(t('myFeature.title')); // 'My Feature'
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## TypeScript Support
|
|
255
|
+
|
|
256
|
+
The package is written in TypeScript and includes full type definitions.
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
import type { Language } from '@umituz/react-native-localization';
|
|
260
|
+
|
|
261
|
+
const language: Language = {
|
|
262
|
+
code: 'en-US',
|
|
263
|
+
name: 'English',
|
|
264
|
+
nativeName: 'English',
|
|
265
|
+
flag: '🇺🇸',
|
|
266
|
+
rtl: false
|
|
267
|
+
};
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Architecture
|
|
271
|
+
|
|
272
|
+
Built with Domain-Driven Design (DDD) principles:
|
|
273
|
+
|
|
274
|
+
- **Domain Layer**: Core business logic and interfaces
|
|
275
|
+
- **Infrastructure Layer**: Implementation details (storage, i18n config, locales)
|
|
276
|
+
- **Presentation Layer**: React components and hooks
|
|
277
|
+
|
|
278
|
+
## Contributing
|
|
279
|
+
|
|
280
|
+
Contributions are welcome! Please read the contributing guidelines before submitting PRs.
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
MIT
|
|
285
|
+
|
|
286
|
+
## Author
|
|
287
|
+
|
|
288
|
+
Ümit UZ <umit@umituz.com>
|
|
289
|
+
|
|
290
|
+
## Repository
|
|
291
|
+
|
|
292
|
+
https://github.com/umituz/react-native-localization
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localization Repository Interface
|
|
3
|
+
* Defines language configuration and types
|
|
4
|
+
*/
|
|
5
|
+
export interface Language {
|
|
6
|
+
code: string;
|
|
7
|
+
name: string;
|
|
8
|
+
nativeName: string;
|
|
9
|
+
flag: string;
|
|
10
|
+
rtl?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ILocalizationRepository {
|
|
13
|
+
getSupportedLanguages(): Language[];
|
|
14
|
+
getLanguageByCode(code: string): Language | undefined;
|
|
15
|
+
isLanguageSupported(code: string): boolean;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ILocalizationRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILocalizationRepository.d.ts","sourceRoot":"","sources":["../../../src/domain/repositories/ILocalizationRepository.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,qBAAqB,IAAI,QAAQ,EAAE,CAAC;IACpC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IACtD,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILocalizationRepository.js","sourceRoot":"","sources":["../../../src/domain/repositories/ILocalizationRepository.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native Localization
|
|
3
|
+
* Universal localization system with i18n support for React Native apps
|
|
4
|
+
*/
|
|
5
|
+
export { useLocalization, useLocalizationStore } from './infrastructure/storage/LocalizationStore';
|
|
6
|
+
export { LocalizationProvider } from './infrastructure/components/LocalizationProvider';
|
|
7
|
+
export { default as i18n } from './infrastructure/config/i18n';
|
|
8
|
+
export { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE, getLanguageByCode, isLanguageSupported, getDefaultLanguage, getDeviceLocale, } from './infrastructure/config/languages';
|
|
9
|
+
export type { Language, ILocalizationRepository } from './domain/repositories/ILocalizationRepository';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAGnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AAGxF,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAG3C,YAAY,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native Localization
|
|
3
|
+
* Universal localization system with i18n support for React Native apps
|
|
4
|
+
*/
|
|
5
|
+
// Hooks
|
|
6
|
+
export { useLocalization, useLocalizationStore } from './infrastructure/storage/LocalizationStore';
|
|
7
|
+
// Components
|
|
8
|
+
export { LocalizationProvider } from './infrastructure/components/LocalizationProvider';
|
|
9
|
+
// Configuration
|
|
10
|
+
export { default as i18n } from './infrastructure/config/i18n';
|
|
11
|
+
export { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE, getLanguageByCode, isLanguageSupported, getDefaultLanguage, getDeviceLocale, } from './infrastructure/config/languages';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,QAAQ;AACR,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAEnG,aAAa;AACb,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AAExF,gBAAgB;AAChB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,GAChB,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalizationProvider Component
|
|
3
|
+
* Initializes localization system on mount
|
|
4
|
+
*/
|
|
5
|
+
import React, { ReactNode } from 'react';
|
|
6
|
+
interface LocalizationProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare const LocalizationProvider: React.FC<LocalizationProviderProps>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=LocalizationProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationProvider.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/components/LocalizationProvider.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,EAAa,SAAS,EAAE,MAAM,OAAO,CAAC;AAGpD,UAAU,yBAAyB;IACjC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,yBAAyB,CAQpE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalizationProvider Component
|
|
3
|
+
* Initializes localization system on mount
|
|
4
|
+
*/
|
|
5
|
+
import React, { useEffect } from 'react';
|
|
6
|
+
import { useLocalizationStore } from '../storage/LocalizationStore';
|
|
7
|
+
export const LocalizationProvider = ({ children }) => {
|
|
8
|
+
const initialize = useLocalizationStore((state) => state.initialize);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
initialize();
|
|
11
|
+
}, [initialize]);
|
|
12
|
+
return <>{children}</>;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=LocalizationProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationProvider.js","sourceRoot":"","sources":["../../../src/infrastructure/components/LocalizationProvider.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAMpE,MAAM,CAAC,MAAM,oBAAoB,GAAwC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACxF,MAAM,UAAU,GAAG,oBAAoB,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAErE,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;AACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/config/i18n.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,SAAS,CAAC;AAmD3B,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18next Configuration
|
|
3
|
+
* Nested translation structure - common translations spread, domain translations nested
|
|
4
|
+
*/
|
|
5
|
+
import i18n from 'i18next';
|
|
6
|
+
import { initReactI18next } from 'react-i18next';
|
|
7
|
+
import { DEFAULT_LANGUAGE } from './languages';
|
|
8
|
+
/**
|
|
9
|
+
* Import all translations from modular folder structure
|
|
10
|
+
* Each locale has an index.ts that merges all JSON files
|
|
11
|
+
*
|
|
12
|
+
* Structure (OFFLINE-ONLY):
|
|
13
|
+
* locales/
|
|
14
|
+
* en-US/ (universal translations in localization domain)
|
|
15
|
+
* index.ts (merges common.json, navigation.json, settings.json, onboarding.json, errors.json)
|
|
16
|
+
*
|
|
17
|
+
* All translations are offline-compatible and work without backend.
|
|
18
|
+
*/
|
|
19
|
+
// Import universal translations from localization domain
|
|
20
|
+
import localizationEnUS from '../locales/en-US';
|
|
21
|
+
/**
|
|
22
|
+
* Translation Resources
|
|
23
|
+
* Nested structure - domain-based organization with direct key access
|
|
24
|
+
* Example: settings.theme.title, onboarding.welcome.title
|
|
25
|
+
*/
|
|
26
|
+
const resources = {
|
|
27
|
+
'en-US': {
|
|
28
|
+
translation: {
|
|
29
|
+
...localizationEnUS,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Initialize i18next
|
|
35
|
+
*/
|
|
36
|
+
i18n.use(initReactI18next).init({
|
|
37
|
+
resources,
|
|
38
|
+
lng: DEFAULT_LANGUAGE,
|
|
39
|
+
fallbackLng: DEFAULT_LANGUAGE,
|
|
40
|
+
interpolation: {
|
|
41
|
+
escapeValue: false, // React already escapes values
|
|
42
|
+
},
|
|
43
|
+
react: {
|
|
44
|
+
useSuspense: false, // Disable suspense for React Native
|
|
45
|
+
},
|
|
46
|
+
compatibilityJSON: 'v4', // Use i18next v4 JSON format
|
|
47
|
+
});
|
|
48
|
+
export default i18n;
|
|
49
|
+
//# sourceMappingURL=i18n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../src/infrastructure/config/i18n.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAuB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE;;;;;;;;;;GAUG;AAEH,yDAAyD;AACzD,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,SAAS,GAAG;IAChB,OAAO,EAAE;QACP,WAAW,EAAE;YACX,GAAG,gBAAgB;SACpB;KACF;CACF,CAAC;AAEF;;GAEG;AACH,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;IAC9B,SAAS;IACT,GAAG,EAAE,gBAAgB;IACrB,WAAW,EAAE,gBAAgB;IAE7B,aAAa,EAAE;QACb,WAAW,EAAE,KAAK,EAAE,+BAA+B;KACpD;IAED,KAAK,EAAE;QACL,WAAW,EAAE,KAAK,EAAE,oCAAoC;KACzD;IAED,iBAAiB,EAAE,IAAI,EAAE,6BAA6B;CACvD,CAAC,CAAC;AAEH,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported Languages Configuration
|
|
3
|
+
* Complete list of 29 languages supported by the app
|
|
4
|
+
*
|
|
5
|
+
* SINGLE SOURCE OF TRUTH: Imports from constants/languages.ts
|
|
6
|
+
* - All language definitions come from one central location
|
|
7
|
+
* - Ensures consistency across app.json, i18n config, and UI
|
|
8
|
+
* - Automatic synchronization between all language configurations
|
|
9
|
+
*
|
|
10
|
+
* DEVICE LOCALE DETECTION:
|
|
11
|
+
* - First launch: Automatically detects device locale
|
|
12
|
+
* - Fallback: English (en-US) if device locale not supported
|
|
13
|
+
* - User choice: Persists after manual language selection
|
|
14
|
+
*/
|
|
15
|
+
import { Language } from '../../domain/repositories/ILocalizationRepository';
|
|
16
|
+
export declare const SUPPORTED_LANGUAGES: Language[];
|
|
17
|
+
export declare const DEFAULT_LANGUAGE = "en-US";
|
|
18
|
+
export declare const getLanguageByCode: (code: string) => Language | undefined;
|
|
19
|
+
export declare const isLanguageSupported: (code: string) => boolean;
|
|
20
|
+
export declare const getDefaultLanguage: () => Language;
|
|
21
|
+
/**
|
|
22
|
+
* Get device locale and map it to supported language
|
|
23
|
+
* Called ONLY on first launch (when no saved language preference exists)
|
|
24
|
+
*
|
|
25
|
+
* @returns Supported language code or DEFAULT_LANGUAGE
|
|
26
|
+
*
|
|
27
|
+
* Examples:
|
|
28
|
+
* - Device: "en" → Returns: "en-US"
|
|
29
|
+
* - Device: "en-GB" → Returns: "en-US"
|
|
30
|
+
* - Device: "tr" → Returns: "tr-TR" (if supported)
|
|
31
|
+
* - Device: "de" → Returns: "en-US" (not supported, fallback)
|
|
32
|
+
*/
|
|
33
|
+
export declare const getDeviceLocale: () => string;
|
|
34
|
+
//# sourceMappingURL=languages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languages.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/config/languages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E,eAAO,MAAM,mBAAmB,EAAE,QAAQ,EAAc,CAAC;AAEzD,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAoKxC,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,QAAQ,GAAG,SAE3D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,OAElD,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,QAErC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,QAAO,MAkClC,CAAC"}
|