MCPcopy
hub / github.com/different-ai/openwork / t

Function t

apps/app/src/i18n/index.ts:166–192  ·  view source on GitHub ↗
(
  key: string,
  paramsOrLocale?: TranslationParams | Language,
  legacyParams?: Record<string, string | number>,
)

Source from the content-addressed store, hash-verified

164type TranslationParams = Record<string, string | number> & { lng?: Language };
165
166export const t = (
167 key: string,
168 paramsOrLocale?: TranslationParams | Language,
169 legacyParams?: Record<string, string | number>,
170): string => {
171 const params = legacyParams ?? (typeof paramsOrLocale === "string" ? undefined : paramsOrLocale);
172 const loc: Language = typeof paramsOrLocale === "string"
173 ? paramsOrLocale
174 : isLanguage(params?.lng)
175 ? params.lng
176 : locale();
177
178 const lookupKey =
179 typeof params?.count === "number" ? resolvePluralKey(loc, key, params.count) : key;
180
181 const result = lookupEntry(loc, lookupKey);
182 if (result === null) return key;
183
184 if (!params) return result;
185
186 let out = result;
187 for (const [k, v] of Object.entries(params)) {
188 if (k === "lng") continue;
189 out = out.replace(`{${k}}`, String(v));
190 }
191 return out;
192};
193
194/**
195 * Initialize locale from localStorage

Callers 15

ModelBehaviorSelectFunction · 0.90
RestrictionNoticeModalFunction · 0.90
formatTimeAgoFunction · 0.90
NotificationBellFunction · 0.90
SettingsRouteContentFunction · 0.90
SessionRouteFunction · 0.90
CommandPaletteFunction · 0.90
useEngineReloadFunction · 0.90
WelcomeRouteFunction · 0.90
fetchOnceFunction · 0.90

Calls 4

isLanguageFunction · 0.85
localeFunction · 0.85
resolvePluralKeyFunction · 0.85
lookupEntryFunction · 0.85

Tested by

no test coverage detected