backend: allow for source lang to be overridden in note/translate #160

Manually merged
norm merged 2 commits from backend-translate-source-lang into main 2022-09-21 03:56:24 +00:00
Owner

This adds a new optional sourceLang parameter to the notes/translate
endpoint. If not set, the old behaviour is used, else this sets the
source_lang parameter to the DeepL API call which makes it use the
source language specified instead of using autodetection.

Changelog: Changed
Ref: #33

This adds a new optional `sourceLang` parameter to the `notes/translate` endpoint. If not set, the old behaviour is used, else this sets the `source_lang` parameter to the DeepL API call which makes it use the source language specified instead of using autodetection. Changelog: Changed Ref: https://akkoma.dev/FoundKeyGang/FoundKey/issues/33
Author
Owner

This will only contain the backend part as I'm still not decided on how it'll be done on the frontend.

This will only contain the backend part as I'm still not decided on how it'll be done on the frontend.
norm force-pushed backend-translate-source-lang from e2ac97a5fc to 644c423643 2022-09-17 19:05:22 +00:00 Compare
Owner

If this is supposed to cover all the backend parts of #33, you'll need to adjust the target language part too, to accept EN-GB and EN-US as well as PT-BR and PT-PT. (see also https://www.deepl.com/docs-api/translate-text/translate-text/)

If this is supposed to cover all the backend parts of #33, you'll need to adjust the target language part too, to accept `EN-GB` and `EN-US` as well as `PT-BR` and `PT-PT`. (see also <https://www.deepl.com/docs-api/translate-text/translate-text/>)
Owner

If you want to be extra strict you could add enum validation to source and target language as well.

If you want to be extra strict you could add `enum` validation to source and target language as well.
Author
Owner

Not sure if what I came up with was what you had in mind, but I'm not sure if there's a better way (still kinda new to this sort of stuff).

Not sure if what I came up with was what you had in mind, but I'm not sure if there's a better way (still kinda new to this sort of stuff).
Owner

No, sorry that is not what I meant. You can use the JSON schema enum key of the endpoint in paramDef to make use of the existing validation. Something like this:

export const paramDef = {
	// ...
	properties: {
		// ...
		sourceLang: {
			type: 'string',
			enum: ['BG', 'CS', 'DA', 'DE', 'EL', /* etc. */ ],
		},
		// similar for targetLang
	},
} as const;
No, sorry that is not what I meant. You can use the [JSON schema `enum` key](https://ajv.js.org/json-schema.html#enum) of the endpoint in `paramDef` to make use of the existing validation. Something like this: ```typescript export const paramDef = { // ... properties: { // ... sourceLang: { type: 'string', enum: ['BG', 'CS', 'DA', 'DE', 'EL', /* etc. */ ], }, // similar for targetLang }, } as const; ```
Author
Owner

oh that makes MUCH more sense.

oh that makes MUCH more sense.
norm force-pushed backend-translate-source-lang from 6875a47fbb to c068294c51 2022-09-19 14:49:09 +00:00 Compare
norm force-pushed backend-translate-source-lang from c068294c51 to d5d8affc33 2022-09-19 14:57:21 +00:00 Compare
Johann150 added 1 commit 2022-09-19 20:22:03 +00:00
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
17f3dafd6b
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.
norm manually merged commit 78fd2ee38b into main 2022-09-21 03:56:24 +00:00
norm deleted branch backend-translate-source-lang 2022-09-21 04:02:12 +00:00
Sign in to join this conversation.
No reviewers
No labels
feature
fix
upkeep
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: FoundKeyGang/FoundKey#160
No description provided.