14 lines
492 B
TypeScript
14 lines
492 B
TypeScript
|
|
import { useCallback } from "react";
|
||
|
|
import { useI18n } from "./i18n";
|
||
|
|
import { localizePath } from "./languageRoutes";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns a stable `(path) => localized path` function bound to the current
|
||
|
|
* UI language. Use this anywhere a `<Link to>` or `navigate()` target needs to
|
||
|
|
* preserve the active language prefix (e.g. `/malay/browse`).
|
||
|
|
*/
|
||
|
|
export function useLocalizedPath() {
|
||
|
|
const { lang } = useI18n();
|
||
|
|
return useCallback((path: string) => localizePath(path, lang), [lang]);
|
||
|
|
}
|