-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature to treat couples of languages as equal when searching f…
…or subtitles * Add 'Language-equals' support This feature will treat couples of languages as equal for list-subtitles operations. It's optional; its methods won't do anything if an empy list is set. See more info at docstrings from 'subliminal_patch.core'. For example, let's say I only want to have "Spanish (es.srt)" subtitles and I don't care about the differences between Spain and LATAM spanish. This feature will allow me to always get European Spanish even from LATAM Spanish providers like Argenteam and Subdivx. Example for config.ini: language_equals = ['spa-MX:spa'] (Which means all Latam Spanish subtitles from every provider will be converted to European Spanish) * Add PT and ZH language tests * Add HI and Forced parsing for language pairs Format example: ["en@HI:en", "es-MX@forced:es-MX"] * Update languages.py * Update API definition to reflect the previous change * Add language equals table to the UI (test only) * Add global language selector and get language from code3 utilities * Add unit tests for language equal feature * Add encode function to language equal feature * Add CRUD methods to the language equals panel * Add equals description * Add parsing support for alpha3 custom languages * no log: add more tests * Add forced and hi support to the language equal target --------- Co-authored-by: morpheus65535 <louis_vezina@hotmail.com> Co-authored-by: LASER-Yi <liangyi0007@gmail.com>
- Loading branch information
1 parent
70d1fd9
commit 547f8c4
Showing
18 changed files
with
956 additions
and
56 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useLanguages } from "@/apis/hooks"; | ||
import { Selector, SelectorProps } from "@/components/inputs"; | ||
import { useSelectorOptions } from "@/utilities"; | ||
import { FunctionComponent, useMemo } from "react"; | ||
|
||
interface LanguageSelectorProps | ||
extends Omit<SelectorProps<Language.Server>, "options" | "getkey"> { | ||
enabled?: boolean; | ||
} | ||
|
||
const LanguageSelector: FunctionComponent<LanguageSelectorProps> = ({ | ||
enabled = false, | ||
...selector | ||
}) => { | ||
const { data } = useLanguages(); | ||
|
||
const filteredData = useMemo(() => { | ||
if (enabled) { | ||
return data?.filter((value) => value.enabled); | ||
} else { | ||
return data; | ||
} | ||
}, [data, enabled]); | ||
|
||
const options = useSelectorOptions( | ||
filteredData ?? [], | ||
(value) => value.name, | ||
(value) => value.code3 | ||
); | ||
|
||
return <Selector {...options} searchable {...selector}></Selector>; | ||
}; | ||
|
||
export default LanguageSelector; |
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,196 @@ | ||
import { | ||
decodeEqualData, | ||
encodeEqualData, | ||
LanguageEqualData, | ||
LanguageEqualImmediateData, | ||
} from "@/pages/Settings/Languages/equals"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("Equals Parser", () => { | ||
it("should parse from string correctly", () => { | ||
interface TestData { | ||
text: string; | ||
expected: LanguageEqualImmediateData; | ||
} | ||
|
||
function testParsedResult( | ||
text: string, | ||
expected: LanguageEqualImmediateData | ||
) { | ||
const result = decodeEqualData(text); | ||
|
||
if (result === undefined) { | ||
expect(false, `Cannot parse '${text}' as language equal data`); | ||
return; | ||
} | ||
|
||
expect( | ||
result, | ||
`${text} does not match with the expected equal data` | ||
).toStrictEqual(expected); | ||
} | ||
|
||
const testValues: TestData[] = [ | ||
{ | ||
text: "spa-MX:spa", | ||
expected: { | ||
source: { | ||
content: "spa-MX", | ||
hi: false, | ||
forced: false, | ||
}, | ||
target: { | ||
content: "spa", | ||
hi: false, | ||
forced: false, | ||
}, | ||
}, | ||
}, | ||
{ | ||
text: "zho@hi:zht", | ||
expected: { | ||
source: { | ||
content: "zho", | ||
hi: true, | ||
forced: false, | ||
}, | ||
target: { | ||
content: "zht", | ||
hi: false, | ||
forced: false, | ||
}, | ||
}, | ||
}, | ||
{ | ||
text: "es-MX@forced:es-MX", | ||
expected: { | ||
source: { | ||
content: "es-MX", | ||
hi: false, | ||
forced: true, | ||
}, | ||
target: { | ||
content: "es-MX", | ||
hi: false, | ||
forced: false, | ||
}, | ||
}, | ||
}, | ||
{ | ||
text: "en:en@hi", | ||
expected: { | ||
source: { | ||
content: "en", | ||
hi: false, | ||
forced: false, | ||
}, | ||
target: { | ||
content: "en", | ||
hi: true, | ||
forced: false, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
testValues.forEach((data) => { | ||
testParsedResult(data.text, data.expected); | ||
}); | ||
}); | ||
|
||
it("should encode to string correctly", () => { | ||
interface TestData { | ||
source: LanguageEqualData; | ||
expected: string; | ||
} | ||
|
||
const testValues: TestData[] = [ | ||
{ | ||
source: { | ||
source: { | ||
content: { | ||
name: "Abkhazian", | ||
code2: "ab", | ||
code3: "abk", | ||
enabled: false, | ||
}, | ||
hi: false, | ||
forced: false, | ||
}, | ||
target: { | ||
content: { | ||
name: "Aragonese", | ||
code2: "an", | ||
code3: "arg", | ||
enabled: false, | ||
}, | ||
hi: false, | ||
forced: false, | ||
}, | ||
}, | ||
expected: "abk:arg", | ||
}, | ||
{ | ||
source: { | ||
source: { | ||
content: { | ||
name: "Abkhazian", | ||
code2: "ab", | ||
code3: "abk", | ||
enabled: false, | ||
}, | ||
hi: true, | ||
forced: false, | ||
}, | ||
target: { | ||
content: { | ||
name: "Aragonese", | ||
code2: "an", | ||
code3: "arg", | ||
enabled: false, | ||
}, | ||
hi: false, | ||
forced: false, | ||
}, | ||
}, | ||
expected: "abk@hi:arg", | ||
}, | ||
{ | ||
source: { | ||
source: { | ||
content: { | ||
name: "Abkhazian", | ||
code2: "ab", | ||
code3: "abk", | ||
enabled: false, | ||
}, | ||
hi: false, | ||
forced: true, | ||
}, | ||
target: { | ||
content: { | ||
name: "Aragonese", | ||
code2: "an", | ||
code3: "arg", | ||
enabled: false, | ||
}, | ||
hi: false, | ||
forced: false, | ||
}, | ||
}, | ||
expected: "abk@forced:arg", | ||
}, | ||
]; | ||
|
||
function testEncodeResult({ source, expected }: TestData) { | ||
const encoded = encodeEqualData(source); | ||
|
||
expect( | ||
encoded, | ||
`Encoded result '${encoded}' is not matched to '${expected}'` | ||
).toEqual(expected); | ||
} | ||
|
||
testValues.forEach(testEncodeResult); | ||
}); | ||
}); |
Oops, something went wrong.