forked from FoundKeyGang/FoundKey
client: bring targetLang into correct format
Now that stricter API validation has been added, it will be necessary to modify the target language in the client so the API will not fail with a validation error.
This commit is contained in:
parent
d5d8affc33
commit
17f3dafd6b
1 changed files with 9 additions and 1 deletions
|
@ -168,9 +168,17 @@ export function getNoteMenu(props: {
|
|||
async function translate(): Promise<void> {
|
||||
if (props.translation.value != null) return;
|
||||
props.translating.value = true;
|
||||
|
||||
let targetLang = localStorage.getItem('lang') || navigator.language;
|
||||
targetLang = targetLang.toUpperCase();
|
||||
if (!['EN-GB', 'EN-US', 'PT-BR', 'PT-PT'].íncludes(targetLang)) {
|
||||
// only the language code without country code is allowed
|
||||
targetLang = targetLang.split('-', 1)[0];
|
||||
}
|
||||
|
||||
const res = await os.api('notes/translate', {
|
||||
noteId: appearNote.id,
|
||||
targetLang: localStorage.getItem('lang') || navigator.language,
|
||||
targetLang,
|
||||
});
|
||||
props.translating.value = false;
|
||||
props.translation.value = res;
|
||||
|
|
Loading…
Reference in a new issue