File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,14 @@ export type TranslationsType = {
1717 minute : string
1818}
1919
20- let translationsPerLocale : Record < string , TranslationsType > = { }
20+ export type TranslationResolver = (
21+ locale : string | undefined
22+ ) => TranslationsType
23+
24+ let translationsPerLocale : Record <
25+ string ,
26+ TranslationsType | TranslationResolver
27+ > = { }
2128
2229export function getTranslation < K extends keyof TranslationsType > (
2330 locale : string | undefined ,
@@ -32,7 +39,10 @@ export function getTranslation<K extends keyof TranslationsType>(
3239 )
3340 return fallback || key
3441 }
35- const translation = translationsPerLocale [ l ] [ key ]
42+ const translation : TranslationsType [ K ] =
43+ typeof translationForLocale === 'function'
44+ ? translationForLocale ( locale ) [ key ]
45+ : translationForLocale [ key ]
3646 if ( ! translation ) {
3747 console . warn (
3848 `[react-native-paper-dates] The locale ${ locale } is registered, but ${ key } is missing`
@@ -43,7 +53,7 @@ export function getTranslation<K extends keyof TranslationsType>(
4353
4454export function registerTranslation (
4555 locale : string ,
46- translations : TranslationsType
56+ translations : TranslationsType | TranslationResolver
4757) {
4858 translationsPerLocale [ locale ] = translations
4959}
You can’t perform that action at this time.
0 commit comments