client: bring targetLang into correct format
Some checks failed
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/lint-foundkey-js Pipeline was successful
ci/woodpecker/pr/lint-backend Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint-client Pipeline failed

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:
Johann150 2022-09-19 22:20:50 +02:00
parent d5d8affc33
commit 17f3dafd6b
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -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;