i18next 23.8.0 → 23.8.1

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.
@@ -1 +1 @@
1
- {"type":"module","version":"23.8.0"}
1
+ {"type":"module","version":"23.8.1"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next",
3
- "version": "23.8.0",
3
+ "version": "23.8.1",
4
4
  "description": "i18next internationalization framework",
5
5
  "main": "./dist/cjs/i18next.js",
6
6
  "module": "./dist/esm/i18next.js",
@@ -39,6 +39,11 @@ export type TypeOptions = $MergeBy<
39
39
  */
40
40
  returnNull: false;
41
41
 
42
+ /**
43
+ * Allows empty string as valid translation
44
+ */
45
+ returnEmptyString: true;
46
+
42
47
  /**
43
48
  * Allows objects as valid translation result
44
49
  */
package/typescript/t.d.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
 
13
13
  // Type Options
14
14
  type _ReturnObjects = TypeOptions['returnObjects'];
15
+ type _ReturnEmptyString = TypeOptions['returnEmptyString'];
15
16
  type _ReturnNull = TypeOptions['returnNull'];
16
17
  type _KeySeparator = TypeOptions['keySeparator'];
17
18
  type _NsSeparator = TypeOptions['nsSeparator'];
@@ -157,23 +158,32 @@ type ParseTReturnPluralOrdinal<
157
158
  string}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`,
158
159
  > = Res[(KeyWithOrdinalPlural | Key) & keyof Res];
159
160
 
160
- type ParseTReturn<
161
+ type ParseTReturnWithFallback<Key, Val> = Val extends ''
162
+ ? _ReturnEmptyString extends true
163
+ ? ''
164
+ : Key
165
+ : Val extends null
166
+ ? _ReturnNull extends true
167
+ ? null
168
+ : Key
169
+ : Val;
170
+
171
+ type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallback<
161
172
  Key,
162
- Res,
163
- TOpt extends TOptions = {},
164
- > = Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
165
- ? ParseTReturn<RestKey, Res[K1 & keyof Res], TOpt>
166
- : // Process plurals only if count is provided inside options
167
- TOpt['count'] extends number
168
- ? TOpt['ordinal'] extends boolean
169
- ? ParseTReturnPluralOrdinal<Res, Key>
170
- : ParseTReturnPlural<Res, Key>
171
- : // otherwise access plain key without adding plural and ordinal suffixes
172
- Res extends readonly unknown[]
173
- ? Key extends `${infer NKey extends number}`
174
- ? Res[NKey]
175
- : never
176
- : Res[Key & keyof Res];
173
+ Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
174
+ ? ParseTReturn<RestKey, Res[K1 & keyof Res], TOpt>
175
+ : // Process plurals only if count is provided inside options
176
+ TOpt['count'] extends number
177
+ ? TOpt['ordinal'] extends boolean
178
+ ? ParseTReturnPluralOrdinal<Res, Key>
179
+ : ParseTReturnPlural<Res, Key>
180
+ : // otherwise access plain key without adding plural and ordinal suffixes
181
+ Res extends readonly unknown[]
182
+ ? Key extends `${infer NKey extends number}`
183
+ ? Res[NKey]
184
+ : never
185
+ : Res[Key & keyof Res]
186
+ >;
177
187
 
178
188
  type TReturnOptionalNull = _ReturnNull extends true ? null : never;
179
189
  type TReturnOptionalObjects<TOpt extends TOptions> = _ReturnObjects extends true
@@ -9,6 +9,7 @@ import type {
9
9
 
10
10
  // Type Options
11
11
  type _ReturnObjects = TypeOptions['returnObjects'];
12
+ type _ReturnEmptyString = TypeOptions['returnEmptyString'];
12
13
  type _ReturnNull = TypeOptions['returnNull'];
13
14
  type _KeySeparator = TypeOptions['keySeparator'];
14
15
  type _NsSeparator = TypeOptions['nsSeparator'];
@@ -157,23 +158,32 @@ type ParseTReturnPluralOrdinal<
157
158
  string}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`,
158
159
  > = Res[(KeyWithOrdinalPlural | Key) & keyof Res];
159
160
 
160
- type ParseTReturn<
161
+ type ParseTReturnWithFallback<Key, Val> = Val extends ''
162
+ ? _ReturnEmptyString extends true
163
+ ? ''
164
+ : Key
165
+ : Val extends null
166
+ ? _ReturnNull extends true
167
+ ? null
168
+ : Key
169
+ : Val;
170
+
171
+ type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallback<
161
172
  Key,
162
- Res,
163
- TOpt extends TOptions = {},
164
- > = Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
165
- ? ParseTReturn<RestKey, Res[K1 & keyof Res], TOpt>
166
- : // // Process plurals only if count is provided inside options
167
- TOpt['count'] extends number
168
- ? TOpt['ordinal'] extends boolean
169
- ? ParseTReturnPluralOrdinal<Res, Key>
170
- : ParseTReturnPlural<Res, Key>
171
- : // otherwise access plain key without adding plural and ordinal suffixes
172
- Res extends readonly unknown[]
173
- ? Key extends `${infer NKey extends number}`
174
- ? Res[NKey]
175
- : never
176
- : Res[Key & keyof Res];
173
+ Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
174
+ ? ParseTReturn<RestKey, Res[K1 & keyof Res], TOpt>
175
+ : // Process plurals only if count is provided inside options
176
+ TOpt['count'] extends number
177
+ ? TOpt['ordinal'] extends boolean
178
+ ? ParseTReturnPluralOrdinal<Res, Key>
179
+ : ParseTReturnPlural<Res, Key>
180
+ : // otherwise access plain key without adding plural and ordinal suffixes
181
+ Res extends readonly unknown[]
182
+ ? Key extends `${infer NKey extends number}`
183
+ ? Res[NKey]
184
+ : never
185
+ : Res[Key & keyof Res]
186
+ >;
177
187
 
178
188
  type TReturnOptionalNull = _ReturnNull extends true ? null : never;
179
189
  type TReturnOptionalObjects<TOpt extends TOptions> = _ReturnObjects extends true