@@ -276,6 +276,8 @@ function deSanitizeHtmlTags(str: string, identifier: string): string {
276
276
. replace ( new RegExp ( `${ identifier } >${ identifier } ` , 'g' ) , '>' ) ;
277
277
}
278
278
279
+ const pluralKey = 'count' as const ;
280
+
279
281
class LocalizedStringBuilder < T extends MergedLocalizerTokens > extends String {
280
282
private readonly token : T ;
281
283
private args ?: ArgsFromToken < T > ;
@@ -363,8 +365,6 @@ class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
363
365
}
364
366
365
367
private resolvePluralString ( ) : string {
366
- const pluralKey = 'count' as const ;
367
-
368
368
let num : number | string | undefined = this . args ?. [ pluralKey as keyof ArgsFromToken < T > ] ;
369
369
370
370
if ( num === undefined ) {
@@ -420,17 +420,19 @@ class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
420
420
}
421
421
}
422
422
423
- return pluralString . replaceAll ( '#' , ` ${ num } ` ) ;
423
+ return pluralString ;
424
424
}
425
425
426
426
private formatStringWithArgs ( str : string ) : string {
427
427
/** Find and replace the dynamic variables in a localized string and substitute the variables with the provided values */
428
428
return str . replace ( / \{ ( \w + ) \} / g, ( match , arg : string ) => {
429
- const matchedArg = this . args
430
- ? this . args [ arg as keyof ArgsFromToken < T > ] ?. toString ( )
431
- : undefined ;
429
+ const matchedArg = this . args ? this . args [ arg as keyof ArgsFromToken < T > ] : undefined ;
430
+
431
+ if ( arg === pluralKey && typeof matchedArg === 'number' && Number . isFinite ( matchedArg ) ) {
432
+ return new Intl . NumberFormat ( this . crowdinLocale ) . format ( matchedArg ) ;
433
+ }
432
434
433
- return matchedArg ?? match ;
435
+ return matchedArg ?. toString ( ) ?? match ;
434
436
} ) ;
435
437
}
436
438
}
0 commit comments