MCPcopy Index your code
hub / github.com/reactnativecn/react-native-update / t

Method t

src/i18n.ts:35–58  ·  view source on GitHub ↗

* Translate a key with optional interpolation * @param key - Translation key * @param values - Values for interpolation (optional) * @returns Translated string with interpolated values

(key: TranslationKey, values?: TranslationValues)

Source from the content-addressed store, hash-verified

33 * @returns Translated string with interpolated values
34 */
35 t(key: TranslationKey, values?: TranslationValues): string {
36 const translation =
37 this.translations[this.currentLocale][
38 key as keyof (typeof this.translations)[typeof this.currentLocale]
39 ];
40
41 if (!translation) {
42 // Fallback to the other locale if key not found
43 const fallbackLocale = this.currentLocale === 'zh' ? 'en' : 'zh';
44 const fallbackTranslation =
45 this.translations[fallbackLocale][
46 key as keyof (typeof this.translations)[typeof fallbackLocale]
47 ];
48
49 if (!fallbackTranslation) {
50 // If still not found, return the key itself
51 return String(key);
52 }
53
54 return this.interpolate(fallbackTranslation, values);
55 }
56
57 return this.interpolate(translation, values);
58 }
59
60 /**
61 * Interpolate values into a string template

Callers 15

constructorMethod · 0.80
PushyClass · 0.80
context.tsFile · 0.80
logFunction · 0.80
infoFunction · 0.80
warnFunction · 0.80
errorFunction · 0.80
promiseAnyFunction · 0.80
utils.tsFile · 0.80
assertWebFunction · 0.80
fetchWithTimeoutFunction · 0.80
core.tsFile · 0.80

Calls 1

interpolateMethod · 0.95

Tested by

no test coverage detected