File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ Onyx.connect({
2626// Note: This has to be initialized inside a function and not at the top level of the file, because Intl is polyfilled,
2727// and if React Native executes this code upon import, then the polyfill will not be available yet and it will barf
2828let CONJUNCTION_LIST_FORMATS_FOR_LOCALES : Record < string , Intl . ListFormat > ;
29+
2930function init ( ) {
3031 CONJUNCTION_LIST_FORMATS_FOR_LOCALES = Object . values ( CONST . LOCALES ) . reduce ( ( memo : Record < string , Intl . ListFormat > , locale ) => {
3132 // eslint-disable-next-line no-param-reassign
@@ -34,6 +35,10 @@ function init() {
3435 } , { } ) ;
3536}
3637
38+ // Memoized function to create PluralRules instances
39+ const createPluralRules = ( locale : Locale ) : Intl . PluralRules => new Intl . PluralRules ( locale ) ;
40+ const memoizedCreatePluralRules = memoize ( createPluralRules ) ;
41+
3742/**
3843 * Helper function to get the translated string for given
3944 * locale and phrase. This function is used to avoid
@@ -70,7 +75,7 @@ function getTranslatedPhrase<TKey extends TranslationPaths>(language: Locale, ph
7075 throw new Error ( `Invalid plural form for '${ phraseKey } '` ) ;
7176 }
7277
73- const pluralRule = new Intl . PluralRules ( language ) . select ( phraseObject . count ) ;
78+ const pluralRule = memoizedCreatePluralRules ( language ) . select ( phraseObject . count ) ;
7479
7580 const pluralResult = translateResult [ pluralRule ] ;
7681 if ( pluralResult ) {
You can’t perform that action at this time.
0 commit comments