@@ -350,6 +350,8 @@ function deSanitizeHtmlTags(str: string, identifier: string): string {
350
350
. replace ( new RegExp ( `${ identifier } >${ identifier } ` , 'g' ) , '>' ) ;
351
351
}
352
352
353
+ const pluralKey = 'count' as const ;
354
+
353
355
class LocalizedStringBuilder < T extends MergedLocalizerTokens > extends String {
354
356
private readonly token : T ;
355
357
private args ?: ArgsFromToken < T > ;
@@ -437,8 +439,6 @@ class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
437
439
}
438
440
439
441
private resolvePluralString ( ) : string {
440
- const pluralKey = 'count' as const ;
441
-
442
442
let num : number | string | undefined = this . args ?. [ pluralKey as keyof ArgsFromToken < T > ] ;
443
443
444
444
if ( num === undefined ) {
@@ -494,17 +494,19 @@ class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
494
494
}
495
495
}
496
496
497
- return pluralString . replaceAll ( '#' , ` ${ num } ` ) ;
497
+ return pluralString ;
498
498
}
499
499
500
500
private formatStringWithArgs ( str : string ) : string {
501
501
/** Find and replace the dynamic variables in a localized string and substitute the variables with the provided values */
502
502
return str . replace ( / \{ ( \w + ) \} / g, ( match , arg : string ) => {
503
- const matchedArg = this . args
504
- ? this . args [ arg as keyof ArgsFromToken < T > ] ?. toString ( )
505
- : undefined ;
503
+ const matchedArg = this . args ? this . args [ arg as keyof ArgsFromToken < T > ] : undefined ;
504
+
505
+ if ( arg === pluralKey && typeof matchedArg === 'number' && Number . isFinite ( matchedArg ) ) {
506
+ return new Intl . NumberFormat ( this . crowdinLocale ) . format ( matchedArg ) ;
507
+ }
506
508
507
- return matchedArg ?? match ;
509
+ return matchedArg ?. toString ( ) ?? match ;
508
510
} ) ;
509
511
}
510
512
}
0 commit comments