Always use "other" as "local source" language
This commit is contained in:
@@ -28,6 +28,7 @@ import { AppRoutes } from '@/modules/core/AppRoute.constants';
|
|||||||
import { translateExtensionLanguage } from '@/modules/extension/Extensions.utils';
|
import { translateExtensionLanguage } from '@/modules/extension/Extensions.utils';
|
||||||
import { StyledGroupItemWrapper } from '@/modules/core/components/virtuoso/StyledGroupItemWrapper.tsx';
|
import { StyledGroupItemWrapper } from '@/modules/core/components/virtuoso/StyledGroupItemWrapper.tsx';
|
||||||
import { TExtension } from '@/modules/extension/Extensions.types.ts';
|
import { TExtension } from '@/modules/extension/Extensions.types.ts';
|
||||||
|
import { Sources } from '@/modules/source/services/Sources.ts';
|
||||||
|
|
||||||
interface IExtensionOptions {
|
interface IExtensionOptions {
|
||||||
extensionId: TExtension['pkgName'] | undefined;
|
extensionId: TExtension['pkgName'] | undefined;
|
||||||
@@ -84,7 +85,7 @@ export function ExtensionOptions({ extensionId, closeDialog }: IExtensionOptions
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="h6" component="h3" sx={{ flexGrow: 1 }}>
|
<Typography variant="h6" component="h3" sx={{ flexGrow: 1 }}>
|
||||||
{translateExtensionLanguage(source.lang)}
|
{translateExtensionLanguage(Sources.getLanguage(source))}
|
||||||
</Typography>
|
</Typography>
|
||||||
{source.isConfigurable && (
|
{source.isConfigurable && (
|
||||||
<CustomTooltip title={t('settings.title')}>
|
<CustomTooltip title={t('settings.title')}>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
SourceNsfwInfo,
|
SourceNsfwInfo,
|
||||||
SourceRepoInfo,
|
SourceRepoInfo,
|
||||||
} from '@/modules/source/Source.types.ts';
|
} from '@/modules/source/Source.types.ts';
|
||||||
import { langSortCmp } from '@/modules/core/utils/Languages.ts';
|
import { DefaultLanguage, langSortCmp } from '@/modules/core/utils/Languages.ts';
|
||||||
|
|
||||||
export class Sources {
|
export class Sources {
|
||||||
static readonly LOCAL_SOURCE_ID = '0';
|
static readonly LOCAL_SOURCE_ID = '0';
|
||||||
@@ -22,14 +22,22 @@ export class Sources {
|
|||||||
return source.id === Sources.LOCAL_SOURCE_ID;
|
return source.id === Sources.LOCAL_SOURCE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getLanguages(sources: SourceLanguageInfo[]): string[] {
|
static getLanguage(source: SourceIdInfo & SourceLanguageInfo): string {
|
||||||
return [...new Set(sources.map((source) => source.lang))].toSorted(langSortCmp);
|
if (Sources.isLocalSource(source)) {
|
||||||
|
return DefaultLanguage.OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
static groupByLanguage<Source extends SourceLanguageInfo & SourceDisplayNameInfo>(
|
return source.lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getLanguages(sources: (SourceIdInfo & SourceLanguageInfo)[]): string[] {
|
||||||
|
return [...new Set(sources.map((source) => Sources.getLanguage(source)))].toSorted(langSortCmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static groupByLanguage<Source extends SourceIdInfo & SourceLanguageInfo & SourceDisplayNameInfo>(
|
||||||
sources: Source[],
|
sources: Source[],
|
||||||
): Record<string, Source[]> {
|
): Record<string, Source[]> {
|
||||||
const sourcesByLanguage = Object.groupBy(sources, (source) => source.lang);
|
const sourcesByLanguage = Object.groupBy(sources, (source) => Sources.getLanguage(source));
|
||||||
const sourcesBySortedLanguage = Object.entries(sourcesByLanguage).toSorted(([a], [b]) => langSortCmp(a, b));
|
const sourcesBySortedLanguage = Object.entries(sourcesByLanguage).toSorted(([a], [b]) => langSortCmp(a, b));
|
||||||
const sortedSourcesBySortedLanguage = sourcesBySortedLanguage.map(([language, sourcesOfLanguage]) => [
|
const sortedSourcesBySortedLanguage = sourcesBySortedLanguage.map(([language, sourcesOfLanguage]) => [
|
||||||
language,
|
language,
|
||||||
@@ -51,7 +59,9 @@ export class Sources {
|
|||||||
.filter((source) => showNsfw || !source.isNsfw || (keepLocalSource && Sources.isLocalSource(source)))
|
.filter((source) => showNsfw || !source.isNsfw || (keepLocalSource && Sources.isLocalSource(source)))
|
||||||
.filter(
|
.filter(
|
||||||
(source) =>
|
(source) =>
|
||||||
!languages || languages.includes(source.lang) || (keepLocalSource && Sources.isLocalSource(source)),
|
!languages ||
|
||||||
|
languages.includes(Sources.getLanguage(source)) ||
|
||||||
|
(keepLocalSource && Sources.isLocalSource(source)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user