17 lines
557 B
TypeScript
17 lines
557 B
TypeScript
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
|
||
|
|
}
|