This commit is contained in:
Your Name committed 2026-06-20 18:39:03 -04:00
1 parent 3c4bb06003
commit f7aa4d099f
36 files changed
+528 -180

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
export const SUPPORTED_LOCALES = ['th', 'en', 'ja', 'zh', 'vi', 'ko'] as const;
export type Locale = typeof SUPPORTED_LOCALES[number];
export const DEFAULT_LOCALE: Locale = 'th';
export function isSupportedLocale(locale: string): locale is Locale {
return SUPPORTED_LOCALES.includes(locale as Locale);
}
export function getPathWithoutLocale(path: string): string {
const segments = path.split('/').filter(Boolean);
if (segments.length > 0 && isSupportedLocale(segments[0])) {
segments.shift();
}
return '/' + segments.join('/');
}
export function getPathWithLocale(path: string, locale: string): string {
if (!path) return `/${locale}`;
if (path.startsWith('http')) return path; // Skip absolute external URLs
const pathWithoutLocale = getPathWithoutLocale(path);
if (pathWithoutLocale === '/') return `/${locale}`;
return `/${locale}${pathWithoutLocale}`;
}