-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #606 from nature-heart-software/feat/add-custom-tr…
…anslation Add custom translation API
- Loading branch information
Showing
13 changed files
with
1,100 additions
and
78 deletions.
There are no files selected for viewing
39 changes: 19 additions & 20 deletions
39
apps/app/src/features/audio/components/inputs/NvAudioInputFormPart.vue
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
30 changes: 30 additions & 0 deletions
30
apps/app/src/features/translation/components/inputs/NvCustomTranslationFromSelect.vue
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,30 @@ | ||
<template> | ||
<NvSelect | ||
ref="select" | ||
v-loading="isFetching" | ||
:autocompleteWidth="width" | ||
:modelValue="settingsStore.customTextTranslationFrom" | ||
:options="options" | ||
placeholder="Select a language" | ||
@update:modelValue="(value) => settingsStore.$patch({ customTextTranslationFrom: value })" | ||
/> | ||
</template> | ||
<script lang="ts" setup> | ||
import { NvSelect } from '@packages/ui' | ||
import { useElementSize } from '@vueuse/core' | ||
import { computed, ref } from 'vue' | ||
import { useSettingsStore } from '@/features/settings/store' | ||
import { useGetCustomLanguagesQuery } from '@/features/translation/hooks/useGetCustomLanguagesQuery' | ||
const settingsStore = useSettingsStore() | ||
const select = ref() | ||
const { width } = useElementSize(select) | ||
const { data, isFetching } = useGetCustomLanguagesQuery() | ||
const options = computed( | ||
() => | ||
data.value?.from.map((language) => ({ | ||
label: language.name, | ||
value: language.id, | ||
})) || [], | ||
) | ||
</script> |
30 changes: 30 additions & 0 deletions
30
apps/app/src/features/translation/components/inputs/NvCustomTranslationToSelect.vue
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,30 @@ | ||
<template> | ||
<NvSelect | ||
ref="select" | ||
v-loading="isFetching" | ||
:autocompleteWidth="width" | ||
:modelValue="settingsStore.customTextTranslationTo" | ||
:options="options" | ||
placeholder="Select a language" | ||
@update:modelValue="(value) => settingsStore.$patch({ customTextTranslationTo: value })" | ||
/> | ||
</template> | ||
<script lang="ts" setup> | ||
import { NvSelect } from '@packages/ui' | ||
import { useElementSize } from '@vueuse/core' | ||
import { computed, ref } from 'vue' | ||
import { useSettingsStore } from '@/features/settings/store' | ||
import { useGetCustomLanguagesQuery } from '@/features/translation/hooks/useGetCustomLanguagesQuery' | ||
const settingsStore = useSettingsStore() | ||
const select = ref() | ||
const { width } = useElementSize(select) | ||
const { data, isFetching } = useGetCustomLanguagesQuery() | ||
const options = computed( | ||
() => | ||
data.value?.to.map((language) => ({ | ||
label: language.name, | ||
value: language.id, | ||
})) || [], | ||
) | ||
</script> |
29 changes: 29 additions & 0 deletions
29
apps/app/src/features/translation/components/inputs/NvTranslationStrategySelect.vue
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,29 @@ | ||
<template> | ||
<NvSelect | ||
ref="select" | ||
:autocompleteWidth="width" | ||
:modelValue="settingsStore.textTranslationStrategy" | ||
:options="[ | ||
{ | ||
label: 'Cloud Translation', | ||
value: 'cloud-translation', | ||
}, | ||
{ | ||
label: 'Custom', | ||
value: 'custom', | ||
}, | ||
]" | ||
class="shrink-0" | ||
@update:modelValue="(value) => settingsStore.$patch({ textTranslationStrategy: value })" | ||
/> | ||
</template> | ||
<script lang="ts" setup> | ||
import { NvSelect } from '@packages/ui' | ||
import { useElementSize } from '@vueuse/core' | ||
import { ref } from 'vue' | ||
import { useSettingsStore } from '@/features/settings/store' | ||
const settingsStore = useSettingsStore() | ||
const select = ref() | ||
const { width } = useElementSize(select) | ||
</script> |
26 changes: 26 additions & 0 deletions
26
apps/app/src/features/translation/hooks/useGetCustomLanguagesQuery.ts
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,26 @@ | ||
import { useQuery } from 'vue-query' | ||
import axios from 'axios' | ||
import { useSettingsStore } from '@/features/settings/store' | ||
import { decrypt } from '@/utils/security' | ||
|
||
export const useGetCustomLanguagesQueryKey = () => ['get-custom-languages'] | ||
export const useGetCustomLanguagesQuery = () => | ||
useQuery(useGetCustomLanguagesQueryKey(), async () => { | ||
const settingsStore = useSettingsStore() | ||
const endpoint = settingsStore.customTextTranslationEndpoint | ||
const { data } = await axios.post<{ | ||
from: { | ||
id: string | ||
name: string | ||
}[] | ||
to: { | ||
id: string | ||
name: string | ||
}[] | ||
}>(`${endpoint.endsWith('/') ? endpoint.slice(0, -1) : endpoint}/languages`, { | ||
credentials: { | ||
apiKey: decrypt(settingsStore.customTextTranslationApiKey), | ||
}, | ||
}) | ||
return data | ||
}) |
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
Oops, something went wrong.