DEPRECATED client-side JavaScript internationalization library with translation, pluralization, and localization support.
npx @tessl/cli install tessl/npm-i18next-client@1.11.00
# i18next-client
1
2
i18next-client is a comprehensive JavaScript internationalization library that provides translation, pluralization, and localization features for web applications. This is the deprecated client-side version (v1.11.5) that has been superseded by the unified i18next v2+ library that works across both client and server environments.
3
4
## Package Information
5
6
- **Package Name**: i18next-client
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install i18next-client` (DEPRECATED - use `i18next` instead)
10
- **Status**: Deprecated - Use the current [i18next](https://github.com/i18next/i18next) package
11
12
## Core Imports
13
14
Global browser usage:
15
```javascript
16
// Automatically available as window.i18n when loaded via script tag
17
<script src="path/to/i18next.js"></script>
18
```
19
20
CommonJS:
21
```javascript
22
const i18n = require('i18next-client');
23
```
24
25
AMD:
26
```javascript
27
define(['i18next'], function(i18n) {
28
// use i18n
29
});
30
```
31
32
jQuery integration:
33
```javascript
34
// When jQuery is available, adds $.t() and $.fn.i18n() methods
35
<script src="path/to/jquery.js"></script>
36
<script src="path/to/i18next.js"></script>
37
```
38
39
## Basic Usage
40
41
```javascript
42
// Initialize with options
43
i18n.init({
44
lng: 'en-US',
45
fallbackLng: 'en',
46
resGetPath: 'locales/__lng__/__ns__.json',
47
ns: {
48
namespaces: ['translation'],
49
defaultNs: 'translation'
50
}
51
}, function(t) {
52
// Library is ready
53
console.log(i18n.t('welcome')); // "Welcome"
54
55
// Translation with interpolation
56
console.log(i18n.t('greeting', { name: 'John' })); // "Hello John"
57
58
// Pluralization
59
console.log(i18n.t('item', { count: 0 })); // "no items"
60
console.log(i18n.t('item', { count: 1 })); // "one item"
61
console.log(i18n.t('item', { count: 5 })); // "5 items"
62
});
63
64
// jQuery usage (when available)
65
$('#myElement').i18n(); // Translates elements with data-i18n attributes
66
console.log($.t('welcome')); // jQuery shortcut for translation
67
```
68
69
## Architecture
70
71
i18next-client is built around several key components:
72
73
- **Initialization System**: Configurable setup with language detection and resource loading
74
- **Translation Engine**: Core translation functionality with interpolation, pluralization, and context handling
75
- **Resource Management**: Dynamic loading, caching, and namespace organization of translation resources
76
- **Language Detection**: Automatic language detection from URL, cookies, localStorage, and browser settings
77
- **jQuery Integration**: DOM localization with data attributes and jQuery plugin methods
78
- **Post-Processing**: Extensible system for custom formatting (sprintf, etc.)
79
80
## Capabilities
81
82
### Core Translation
83
84
Main translation functionality with interpolation, pluralization, and context support. Handles variable replacement, plural forms, and contextual translations.
85
86
```javascript { .api }
87
// Main translation function (both aliases available)
88
function t(key, options): string;
89
function translate(key, options): string;
90
91
// Check if translation exists
92
function exists(key, options): boolean;
93
```
94
95
[Core Translation](./core-translation.md)
96
97
### Initialization and Configuration
98
99
Library setup, configuration management, and initialization lifecycle. Handles resource loading, language detection, and feature configuration.
100
101
```javascript { .api }
102
// Initialize the library
103
function init(options, callback): void;
104
105
// Check initialization status
106
function isInitialized(): boolean;
107
```
108
109
[Initialization and Configuration](./initialization.md)
110
111
### Language Management
112
113
Language detection, switching, and text direction handling. Manages current language state and supports automatic language detection.
114
115
```javascript { .api }
116
// Set current language
117
function setLng(lng, options, callback): void;
118
119
// Get current language
120
function lng(): string;
121
122
// Get text direction for current language
123
function dir(): string; // 'ltr' or 'rtl'
124
125
// Detect browser language
126
function detectLanguage(): string;
127
```
128
129
[Language Management](./language-management.md)
130
131
### Resource Management
132
133
Dynamic loading, caching, and management of translation resources. Supports namespace organization and resource bundle operations.
134
135
```javascript { .api }
136
// Add resource bundle
137
function addResourceBundle(lng, ns, resources, deep, overwrite): void;
138
139
// Check if resource bundle exists
140
function hasResourceBundle(lng, ns): boolean;
141
142
// Get resource bundle
143
function getResourceBundle(lng, ns): object;
144
145
// Remove resource bundle
146
function removeResourceBundle(lng, ns): void;
147
```
148
149
[Resource Management](./resource-management.md)
150
151
### jQuery Integration
152
153
DOM localization features and jQuery plugin methods. Automatically translates elements with data attributes and provides jQuery shortcuts.
154
155
```javascript { .api }
156
// jQuery translation shortcut (when jQuery available)
157
$.t(key, options): string;
158
159
// jQuery plugin for DOM localization
160
$.fn.i18n(options): jQuery;
161
```
162
163
[jQuery Integration](./jquery-integration.md)
164
165
### Advanced Features
166
167
Post-processing, utility functions, and advanced configuration access.
168
169
```javascript { .api }
170
// Add custom post-processor
171
function addPostProcessor(name, processor): void;
172
173
// Apply variable replacement in strings
174
function applyReplacement(str, replacementHash, nestedKey, options): string;
175
176
// Restore previous global i18n reference
177
function noConflict(): object;
178
179
// Access to configuration options
180
const options: InitOptions;
181
182
// Access to plural extensions system
183
const pluralExtensions: {
184
rules: object;
185
addRule(lng, obj): void;
186
setCurrentLng(lng): void;
187
needsPlural(lng, count): boolean;
188
get(lng, count): number;
189
};
190
191
// Access to synchronization system
192
const sync: {
193
load(lngs, options, callback): void;
194
postMissing(lng, ns, key, defaultValue, lngs): void;
195
reload(callback): void;
196
};
197
198
// Access to utility functions
199
const functions: {
200
extend(target, source): object;
201
deepExtend(target, source, overwrite): object;
202
each(object, callback, args): object;
203
escape(data): string;
204
detectLanguage(): string;
205
toLanguages(lng, fallbackLng): string[];
206
applyReplacement(str, replacementHash, nestedKey, options): string;
207
};
208
```
209
210
## Types
211
212
```javascript { .api }
213
// Translation options interface
214
interface TranslationOptions {
215
// Language override
216
lng?: string;
217
218
// Fallback language(s)
219
fallbackLng?: string | string[];
220
221
// Namespace override
222
ns?: string;
223
224
// Variable interpolation values
225
[key: string]: any;
226
227
// Pluralization count
228
count?: number;
229
230
// Context for contextual translations
231
context?: string;
232
233
// Default value if translation not found
234
defaultValue?: string;
235
236
// Return nested objects as trees
237
returnObjectTrees?: boolean;
238
239
// Post-processing options
240
postProcess?: string | string[];
241
242
// Interpolation prefix/suffix overrides
243
interpolationPrefix?: string;
244
interpolationSuffix?: string;
245
}
246
247
// Initialization options interface
248
interface InitOptions {
249
// Target language
250
lng?: string;
251
252
// Fallback language(s)
253
fallbackLng?: string | string[];
254
255
// Languages to preload
256
preload?: string[];
257
258
// Namespace configuration
259
ns?: string | {
260
namespaces: string[];
261
defaultNs: string;
262
};
263
264
// Resource loading path
265
resGetPath?: string;
266
267
// Resource posting path
268
resPostPath?: string;
269
270
// Pre-loaded resource store
271
resStore?: object;
272
273
// Use local storage for caching
274
useLocalStorage?: boolean;
275
276
// Local storage expiration time
277
localStorageExpirationTime?: number;
278
279
// Interpolation settings
280
interpolationPrefix?: string;
281
interpolationSuffix?: string;
282
283
// Debug mode
284
debug?: boolean;
285
286
// Enable jQuery extensions
287
setJqueryExt?: boolean;
288
289
// Additional configuration options...
290
}
291
```