managarten/apps/memoro/apps/mobile/utils/languageMapping.ts
Till JS d8a2b37126 chore(memoro): import legacy backend, mobile, and landing apps
Adds the original NestJS backends (backend, audio-backend), Expo mobile app,
and Astro landing page as-is from the standalone memoro repo. These are
not yet migrated to monorepo standards (migration tracked in memory/CLAUDE.md).

Also adds eslint.config.mjs ignore for apps/*/apps/audio-backend/**
and .prettierignore entries for legacy memoro dirs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 17:30:00 +02:00

61 lines
2 KiB
TypeScript

import { AZURE_SUPPORTED_LANGUAGES } from '~/features/audioRecordingV2';
/**
* Maps language codes to readable language names
* @param languageCode - The language code (e.g., "de-DE", "en-US", "de")
* @returns The readable language name (e.g., "Deutsch", "English")
*/
export function getLanguageDisplayName(languageCode: string): string {
if (!languageCode || languageCode === 'unknown') {
return 'unknown';
}
// Check for exact match first (e.g., "de-DE")
const exactMatch = Object.entries(AZURE_SUPPORTED_LANGUAGES).find(
([_, value]) => value.locale === languageCode
);
if (exactMatch) {
return exactMatch[1].nativeName;
}
// Check for partial match (e.g., "de" matches "de-DE")
const partialMatch = Object.entries(AZURE_SUPPORTED_LANGUAGES).find(
([key, value]) => languageCode.startsWith(key) || value.locale.startsWith(languageCode)
);
if (partialMatch) {
return partialMatch[1].nativeName;
}
// Fallback: return the language code as-is
return languageCode;
}
/**
* Maps language codes to readable language names with emoji
* @param languageCode - The language code (e.g., "de-DE", "en-US", "de")
* @returns The readable language name with emoji (e.g., "🇩🇪 Deutsch", "🇺🇸 English")
*/
export function getLanguageDisplayNameWithEmoji(languageCode: string): string {
if (!languageCode || languageCode === 'unknown') {
return 'unknown';
}
// Check for exact match first (e.g., "de-DE")
const exactMatch = Object.entries(AZURE_SUPPORTED_LANGUAGES).find(
([_, value]) => value.locale === languageCode
);
if (exactMatch) {
return `${exactMatch[1].emoji} ${exactMatch[1].nativeName}`;
}
// Check for partial match (e.g., "de" matches "de-DE")
const partialMatch = Object.entries(AZURE_SUPPORTED_LANGUAGES).find(
([key, value]) => languageCode.startsWith(key) || value.locale.startsWith(languageCode)
);
if (partialMatch) {
return `${partialMatch[1].emoji} ${partialMatch[1].nativeName}`;
}
// Fallback: return the language code as-is
return languageCode;
}