mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
fix: update translations on lang change on MetaRow
This commit is contained in:
parent
a37579f70e
commit
1c2a7f9f90
2 changed files with 7 additions and 6 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue