-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #540 from Stremio/feat/translate-catalog-names
Translate catalog names
- Loading branch information
Showing
11 changed files
with
149 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { useCallback } = require('react'); | ||
const { useTranslation } = require('react-i18next'); | ||
|
||
const useTranslate = () => { | ||
const { t } = useTranslation(); | ||
|
||
const string = useCallback((key) => t(key), [t]); | ||
|
||
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 = useCallback(({ addon, id, name, type } = {}, withType = true) => { | ||
if (addon && id && name) { | ||
const partialKey = `${addon.manifest.id}/${id}`; | ||
const translatedName = stringWithPrefix(partialKey, 'CATALOG_', name); | ||
|
||
if (type && withType) { | ||
const translatedType = stringWithPrefix(type, 'TYPE_'); | ||
return `${translatedName} - ${translatedType}`; | ||
} | ||
|
||
return translatedName; | ||
} | ||
|
||
return null; | ||
}, [stringWithPrefix]); | ||
|
||
return { | ||
string, | ||
stringWithPrefix, | ||
catalogTitle, | ||
}; | ||
}; | ||
|
||
module.exports = useTranslate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.