fix: update translations on lang change on MetaRow

This commit is contained in:
Tim 2024-01-03 12:16:18 +01:00
parent a37579f70e
commit 1c2a7f9f90
2 changed files with 7 additions and 6 deletions

View file

@ -16,7 +16,7 @@ const MetaRow = ({ className, title, catalog, message, itemComponent }) => {
const catalogTitle = React.useMemo(() => {
return title ?? t.catalogTitle(catalog);
}, [title, catalog]);
}, [title, catalog, t.catalogTitle]);
const items = React.useMemo(() => {
return catalog?.items ?? catalog?.content?.content;

View file

@ -1,20 +1,21 @@
const { useCallback } = require('react');
const { useTranslation } = require('react-i18next');
const useTranslate = () => {
const { t } = useTranslation();
const string = (key) => t(key);
const string = useCallback((key) => t(key), [t]);
const stringWithPrefix = (value, prefix, fallback = null) => {
const stringWithPrefix = useCallback((value, prefix, fallback = null) => {
const key = `${prefix}${value}`;
const defaultValue = fallback ?? value.charAt(0).toUpperCase() + value.slice(1);
return t(key, {
defaultValue,
});
};
}, [t]);
const catalogTitle = ({ addon, id, name, type } = {}, withType = true) => {
const catalogTitle = useCallback(({ addon, id, name, type } = {}, withType = true) => {
if (addon && id && name) {
const partialKey = `${addon.manifest.id}/${id}`;
const translatedName = stringWithPrefix(partialKey, 'CATALOG_', name);
@ -28,7 +29,7 @@ const useTranslate = () => {
}
return null;
};
}, [stringWithPrefix]);
return {
string,