MCPcopy
hub / github.com/slopus/happy / t

Function t

packages/happy-app/sources/text/index.ts:167–207  ·  view source on GitHub ↗
(
    key: K,
    ...args: GetParams<GetValue<Translations, K>> extends void
        ? []
        : [GetParams<GetValue<Translations, K>>]
)

Source from the content-addressed store, hash-verified

165 * t('sessionInfo.agentState') // "Agent State" or "Состояние агента"
166 */
167export function t<K extends TranslationKey>(
168 key: K,
169 ...args: GetParams<GetValue<Translations, K>> extends void
170 ? []
171 : [GetParams<GetValue<Translations, K>>]
172): string {
173 try {
174 // Get current language translations
175 const currentTranslations = translations[currentLanguage];
176
177 // Navigate to the value using dot notation
178 const keys = key.split('.');
179 let value: any = currentTranslations;
180
181 for (const k of keys) {
182 value = value[k];
183 if (value === undefined) {
184 console.warn(`Translation missing: ${key}`);
185 return key;
186 }
187 }
188
189 // If it's a function, call it with the provided parameters
190 if (typeof value === 'function') {
191 const params = args[0];
192 return value(params);
193 }
194
195 // If it's a string constant, return it directly
196 if (typeof value === 'string') {
197 return value;
198 }
199
200 // Fallback for unexpected types
201 console.warn(`Invalid translation value type for key: ${key}`);
202 return key;
203 } catch (error) {
204 console.error(`Translation error for key: ${key}`, error);
205 return key;
206 }
207}
208
209/**
210 * Get the currently active language

Callers 15

HeaderTitleTabletFunction · 0.90
InboxView.tsxFile · 0.90
TabBar.tsxFile · 0.90
OAuthView.tsxFile · 0.90
FABWide.tsxFile · 0.90
getConnectionStatusFunction · 0.90
HeaderTitleWithSubtitleFunction · 0.90
UpdateBanner.tsxFile · 0.90
SessionsListFunction · 0.90
SessionsList.tsxFile · 0.90
FileViewPanel.tsxFile · 0.90
ConnectButton.tsxFile · 0.90

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected