Add language endpoint to developer APIs (#41)

* Added languages endpoint and its tests
This commit is contained in:
David
2021-08-30 21:35:22 +02:00
committed by GitHub
parent 1b6c324560
commit 870ec2db64
11 changed files with 360 additions and 74 deletions

View File

@@ -33,11 +33,16 @@ export function replaceBoth(
return { source, target };
}
export function retrieveFiltered() {
const [sourceLangs, targetLangs] = langTypes.map(type => (
Object.entries(languages).filter(([code]) => (
!Object.keys(exceptions[type]).includes(code)
))
export function retrieveFromType(type?: LangType): [string, string][] {
const langEntries = Object.entries(languages);
if (!type)
return langEntries;
return langEntries.filter(([code]) => (
!Object.keys(exceptions[type]).includes(code)
));
return { sourceLangs, targetLangs };
}
export function getName(code: string): string | null {
return isKeyOf(languages)(code) ? languages[code] : null;
}

View File

@@ -7,8 +7,9 @@ export async function googleScrape(
target: string,
query: string
): Promise<{
translationRes?: string,
errorMsg?: string
translationRes: string
} | {
errorMsg: string
}> {
const parsed = replaceBoth("mapping", { source, target });
const res = await fetch(
@@ -56,10 +57,7 @@ export function extractSlug(slug: string[]): {
}
}
export async function textToSpeechScrape(lang: string, text?: string) {
if (!text)
return null;
export async function textToSpeechScrape(lang: string, text: string) {
const { target: parsedLang } = replaceBoth("mapping", { source: "", target: lang });
const lastSpace = text.lastIndexOf(" ", 200);