a070504d2e
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
16 lines
544 B
TypeScript
16 lines
544 B
TypeScript
export const useTranslation = () => ({
|
|
t: (label: string, replacements?: Record<string, string>) => {
|
|
const replace =
|
|
replacements?.replace && typeof replacements === 'object'
|
|
? replacements?.replace
|
|
: replacements;
|
|
let translatedLabel = replacements?.defaultValue || label;
|
|
if (typeof replace === 'object' && replace !== null) {
|
|
Object.keys(replace).forEach((key) => {
|
|
translatedLabel = translatedLabel.replace(`{{${key}}}`, replace[key]);
|
|
});
|
|
}
|
|
return translatedLabel;
|
|
},
|
|
});
|