Files
blog/frontend/shared/utils/locale.ts
T

17 lines
557 B
TypeScript
Raw Normal View History

export type Locale = 'it' | 'en'
export const LOCALES: Locale[] = ['it', 'en']
/** Prefixes a bare, unprefixed path (e.g. `/blog/mio-slug`) for the given locale. */
export function localePath(locale: Locale, path: string): string {
if (locale !== 'en') return path
return path === '/' ? '/en' : `/en${path}`
}
/** Strips the `/en` prefix, if any, returning the bare Italian-equivalent path. */
export function bareLocalePath(path: string): string {
if (path === '/en') return '/'
if (path.startsWith('/en/')) return path.slice(3)
return path
}