Feature/update i18next to v23.x (#391)

* Update i18next to v23.x

Update to version 23.2.7

* Use new "ParseKeys" (old: "TFuncKey") type

* Remove unnecessary casts to string

Not needed anymore with the latest version
This commit is contained in:
schroda
2023-07-04 21:53:25 +02:00
committed by GitHub
parent 46ccf20168
commit 5279339b86
13 changed files with 22 additions and 22 deletions

View File

@@ -31,7 +31,7 @@
"@vitejs/plugin-react": "^4.0.0", "@vitejs/plugin-react": "^4.0.0",
"axios": "^1.4.0", "axios": "^1.4.0",
"file-selector": "^0.6.0", "file-selector": "^0.6.0",
"i18next": "^22.5.0", "i18next": "^23.2.7",
"i18next-browser-languagedetector": "^7.0.2", "i18next-browser-languagedetector": "^7.0.2",
"react": "^18.2.0", "react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1", "react-beautiful-dnd": "^13.1.1",

View File

@@ -159,7 +159,7 @@ export default function ExtensionCard(props: IProps) {
sx={{ color: installedState === InstalledState.OBSOLETE ? 'red' : 'inherit' }} sx={{ color: installedState === InstalledState.OBSOLETE ? 'red' : 'inherit' }}
onClick={() => handleButtonClick()} onClick={() => handleButtonClick()}
> >
{t(INSTALLED_STATE_TO_TRANSLATION_KEY_MAP[installedState]) as string} {t(INSTALLED_STATE_TO_TRANSLATION_KEY_MAP[installedState])}
</Button> </Button>
</CardContent> </CardContent>
</Card> </Card>

View File

@@ -48,7 +48,7 @@ const LibraryOptionsPanel: React.FC<IProps> = ({ open, onClose }) => {
open={open} open={open}
onClose={onClose} onClose={onClose}
tabs={['filter', 'sort', 'display']} tabs={['filter', 'sort', 'display']}
tabTitle={(key) => t(TITLES[key]) as string} tabTitle={(key) => t(TITLES[key])}
tabContent={(key) => { tabContent={(key) => {
if (key === 'filter') { if (key === 'filter') {
return ( return (
@@ -70,7 +70,7 @@ const LibraryOptionsPanel: React.FC<IProps> = ({ open, onClose }) => {
return SORT_OPTIONS.map(([mode, label]) => ( return SORT_OPTIONS.map(([mode, label]) => (
<SortRadioInput <SortRadioInput
key={mode} key={mode}
label={t(label) as string} label={t(label)}
checked={options.sorts === mode} checked={options.sorts === mode}
sortDescending={options.sortDesc} sortDescending={options.sortDesc}
onClick={() => onClick={() =>

View File

@@ -168,9 +168,9 @@ const ChapterList: React.FC<IProps> = ({ mangaId }) => {
} }
actionPromise actionPromise
.then(() => makeToast(t(actionsStrings[action].success, { count: chapterIds.length }) as string, 'success')) .then(() => makeToast(t(actionsStrings[action].success, { count: chapterIds.length }), 'success'))
.then(() => mutate()) .then(() => mutate())
.catch(() => makeToast(t(actionsStrings[action].error, { count: chapterIds.length }) as string, 'error')); .catch(() => makeToast(t(actionsStrings[action].error, { count: chapterIds.length }), 'error'));
}; };
if (isLoading) { if (isLoading) {

View File

@@ -38,7 +38,7 @@ const ChapterOptions: React.FC<IProps> = ({ open, onClose, options, optionsDispa
onClose={onClose} onClose={onClose}
minHeight={150} minHeight={150}
tabs={['filter', 'sort', 'display']} tabs={['filter', 'sort', 'display']}
tabTitle={(key) => t(TITLES[key]) as string} tabTitle={(key) => t(TITLES[key])}
tabContent={(key) => { tabContent={(key) => {
if (key === 'filter') { if (key === 'filter') {
return ( return (
@@ -83,7 +83,7 @@ const ChapterOptions: React.FC<IProps> = ({ open, onClose, options, optionsDispa
return SORT_OPTIONS.map(([mode, label]) => ( return SORT_OPTIONS.map(([mode, label]) => (
<SortRadioInput <SortRadioInput
key={mode} key={mode}
label={t(label) as string} label={t(label)}
checked={options.sortBy === mode} checked={options.sortBy === mode}
sortDescending={options.reverse} sortDescending={options.reverse}
onClick={() => onClick={() =>

View File

@@ -48,7 +48,7 @@ export default function DesktopSideBar({ navBarItems }: IProps) {
<Link to={path} style={{ color: 'inherit', textDecoration: 'none' }} key={path}> <Link to={path} style={{ color: 'inherit', textDecoration: 'none' }} key={path}>
<ListItemButton disableRipple key={title}> <ListItemButton disableRipple key={title}>
<ListItemIcon sx={{ minWidth: '0' }}> <ListItemIcon sx={{ minWidth: '0' }}>
<Tooltip placement="right" title={t(title) as string}> <Tooltip placement="right" title={t(title)}>
{iconFor(path, IconComponent, SelectedIconComponent)} {iconFor(path, IconComponent, SelectedIconComponent)}
</Tooltip> </Tooltip>
</ListItemIcon> </ListItemIcon>

View File

@@ -70,7 +70,7 @@ export default function MobileBottomBar({ navBarItems }: IProps) {
: 'grey.600', : 'grey.600',
}} }}
> >
{t(title) as string} {t(title)}
</Box> </Box>
</Box> </Box>
</ListItemButton> </ListItemButton>

View File

@@ -126,7 +126,7 @@ export default function Library() {
<LibraryMangaGrid <LibraryMangaGrid
mangas={mangas} mangas={mangas}
lastLibraryUpdate={lastLibraryUpdate} lastLibraryUpdate={lastLibraryUpdate}
message={t('library.error.label.empty') as string} message={t('library.error.label.empty')}
isLoading={activeTab != null && mangaLoading} isLoading={activeTab != null && mangaLoading}
/> />
); );
@@ -173,7 +173,7 @@ export default function Library() {
<LibraryMangaGrid <LibraryMangaGrid
mangas={mangas} mangas={mangas}
lastLibraryUpdate={lastLibraryUpdate} lastLibraryUpdate={lastLibraryUpdate}
message={t('library.error.label.empty') as string} message={t('library.error.label.empty')}
isLoading={mangaLoading} isLoading={mangaLoading}
/> />
))} ))}

View File

@@ -143,7 +143,7 @@ export default function Reader() {
[ChapterOffset.NEXT]: 'reader.error.label.unable_to_get_next_chapter_skip_dup', [ChapterOffset.NEXT]: 'reader.error.label.unable_to_get_next_chapter_skip_dup',
}; };
makeToast(t(offsetToTranslationKeyMap[offset]) as string, 'error'); makeToast(t(offsetToTranslationKeyMap[offset]), 'error');
} finally { } finally {
setRetrievingNextChapter(false); setRetrievingNextChapter(false);
} }

View File

@@ -191,7 +191,7 @@ export default function SourceMangas() {
const { data: source } = requestManager.useGetSource(sourceId); const { data: source } = requestManager.useGetSource(sourceId);
const [triggerDataRefresh, setTriggerDataRefresh] = useState(false); const [triggerDataRefresh, setTriggerDataRefresh] = useState(false);
const message = !isLoading ? (t(SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY[contentType]) as string) : undefined; const message = !isLoading ? t(SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY[contentType]) : undefined;
const isLocalSource = sourceId === '0'; const isLocalSource = sourceId === '0';
const messageExtra = isLocalSource ? ( const messageExtra = isLocalSource ? (
<> <>

View File

@@ -51,5 +51,5 @@ export const isExtensionStateOrLanguage = (languageCode: string): boolean =>
export const translateExtensionLanguage = (languageCode: string): string => export const translateExtensionLanguage = (languageCode: string): string =>
isExtensionStateOrLanguage(languageCode) isExtensionStateOrLanguage(languageCode)
? (t(extensionLanguageToTranslationKey[languageCode as ExtensionState | DefaultLanguage]) as string) ? t(extensionLanguageToTranslationKey[languageCode as ExtensionState | DefaultLanguage])
: langCodeToName(languageCode); : langCodeToName(languageCode);

View File

@@ -8,7 +8,7 @@
import { OverridableComponent } from '@mui/material/OverridableComponent'; import { OverridableComponent } from '@mui/material/OverridableComponent';
import { SvgIconTypeMap } from '@mui/material/SvgIcon/SvgIcon'; import { SvgIconTypeMap } from '@mui/material/SvgIcon/SvgIcon';
import { TFuncKey } from 'i18next'; import { ParseKeys } from 'i18next';
import { Location } from 'react-router-dom'; import { Location } from 'react-router-dom';
type GenericLocation<State = any> = Omit<Location, 'state'> & { state?: State }; type GenericLocation<State = any> = Omit<Location, 'state'> & { state?: State };
@@ -19,7 +19,7 @@ declare module 'react-router-dom' {
export function useLocation<State = any>(): GenericLocation<State>; export function useLocation<State = any>(): GenericLocation<State>;
} }
export type TranslationKey = TFuncKey; export type TranslationKey = ParseKeys;
export interface IExtension { export interface IExtension {
name: string; name: string;

View File

@@ -1877,12 +1877,12 @@ i18next-browser-languagedetector@^7.0.2:
dependencies: dependencies:
"@babel/runtime" "^7.19.4" "@babel/runtime" "^7.19.4"
i18next@^22.5.0: i18next@^23.2.7:
version "22.5.1" version "23.2.7"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-22.5.1.tgz#99df0b318741a506000c243429a7352e5f44d424" resolved "https://registry.yarnpkg.com/i18next/-/i18next-23.2.7.tgz#1e528b71061ca62668d7d2b6586fb4e6cfe5adb4"
integrity sha512-8TGPgM3pAD+VRsMtUMNknRz3kzqwp/gPALrWMsDnmC1mKqJwpWyooQRLMcbTwq8z8YwSmuj+ZYvc+xCuEpkssA== integrity sha512-EsbHHvF6b+p+B6Cht5fYWY7VE/WYOrqB1+DNwa1UpLTw6mG5g4tc8KCEjUUOSMUA2yqCsdYQP+PqVq5nBMtOtQ==
dependencies: dependencies:
"@babel/runtime" "^7.20.6" "@babel/runtime" "^7.22.5"
ignore@^5.2.0: ignore@^5.2.0:
version "5.2.4" version "5.2.4"