From a67488473f130f2a0d4173eec6b72c1018bc9d89 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Sat, 10 Aug 2024 16:36:55 +0200 Subject: [PATCH 1/2] (terms)(sources) add autocomplete & convention explanation for the key field --- components/AutocompleteSelect.vue | 9 +++++++- components/SourceSubmitForm.vue | 15 ++++++++---- components/TermsSubmitForm.vue | 8 ++++++- components/TimezoneSelect.vue | 2 +- locale/_base/translations.suml | 3 ++- locale/de/translations.suml | 2 +- locale/en/translations.suml | 3 ++- locale/eo/translations.suml | 2 +- locale/es/translations.suml | 2 +- locale/et/translations.suml | 2 +- locale/fr/translations.suml | 2 +- locale/gl/translations.suml | 2 +- locale/it/translations.suml | 2 +- locale/ja/translations.suml | 2 +- locale/ko/translations.suml | 2 +- locale/lad/translations.suml | 2 +- locale/nl/translations.suml | 2 +- locale/no/translations.suml | 2 +- locale/pl/translations.suml | 3 ++- locale/pt/translations.suml | 2 +- locale/ru/translations.suml | 2 +- locale/sv/translations.suml | 2 +- locale/vi/translations.suml | 2 +- locale/zh/translations.suml | 2 +- server/routes/sources.ts | 38 ++++++++++++++++++++++--------- server/routes/terms.ts | 16 +++++++++++++ 26 files changed, 93 insertions(+), 38 deletions(-) diff --git a/components/AutocompleteSelect.vue b/components/AutocompleteSelect.vue index 1917345b5..a60ebf814 100644 --- a/components/AutocompleteSelect.vue +++ b/components/AutocompleteSelect.vue @@ -5,7 +5,7 @@ v-model="filter" type="text" class="form-control" - :placeholder="$t('profile.timezone.placeholder')" + v-bind="$attrs" @focus="show" @blur="hide" @keydown="filterKeydown" @@ -26,9 +26,11 @@ diff --git a/components/TermsSubmitForm.vue b/components/TermsSubmitForm.vue index 54bdddc31..3527cf9d9 100644 --- a/components/TermsSubmitForm.vue +++ b/components/TermsSubmitForm.vue @@ -53,9 +53,10 @@
- +

sources.submit.keyInfo + sources.submit.keyInfoConvention

@@ -122,6 +123,7 @@ interface Data { }; submitting: boolean; afterSubmit: boolean; + keys: Record, } export default Vue.extend({ @@ -139,6 +141,7 @@ export default Vue.extend({ }, submitting: false, afterSubmit: false, + keys: {}, }; }, methods: { @@ -177,5 +180,8 @@ export default Vue.extend({ this.$el.scrollIntoView(); }, }, + async mounted() { + this.keys = await this.$axios.$get('/terms/keys'); + }, }); diff --git a/components/TimezoneSelect.vue b/components/TimezoneSelect.vue index c1fa3a04c..d1fcdf2ff 100644 --- a/components/TimezoneSelect.vue +++ b/components/TimezoneSelect.vue @@ -5,7 +5,7 @@ profile.timezone.detect - + diff --git a/locale/_base/translations.suml b/locale/_base/translations.suml index 28e381750..286355d71 100644 --- a/locale/_base/translations.suml +++ b/locale/_base/translations.suml @@ -139,7 +139,8 @@ sources: another: 'Submit another one' moderation: 'Submissions will have to get approved before getting published.' key: 'Key' - keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary' + keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary.' + keyInfoConvention: 'Ideally: the simplest form of the term, in English, in lower-case.' images: 'Images' spoiler: 'Spoiler' otherVersions: 'In other languages' diff --git a/locale/de/translations.suml b/locale/de/translations.suml index a0e1a00f6..102e6df37 100644 --- a/locale/de/translations.suml +++ b/locale/de/translations.suml @@ -151,7 +151,7 @@ sources: another: 'Ein weiteres Beispiel einreichen' moderation: 'Einreichungen müssen erst genehmigt werden, bevor sie veröffentlicht werden.' key: 'Schlüssel' - keyInfo: 'Kennzeichen, um Quellen zwischen Sprachversionen und dem Wörterbuch zu verbinden' + keyInfo: 'Kennzeichen, um Quellen zwischen Sprachversionen und dem Wörterbuch zu verbinden.' images: 'Bilder' spoiler: 'Spoiler' otherVersions: 'In anderen Sprachen' diff --git a/locale/en/translations.suml b/locale/en/translations.suml index 599f6e8c9..6fd0394e6 100644 --- a/locale/en/translations.suml +++ b/locale/en/translations.suml @@ -137,7 +137,8 @@ sources: another: 'Submit another one' moderation: 'Submissions will have to get approved before getting published.' key: 'Key' - keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary' + keyInfo: 'Identifier for linking sources between language versions and linking with the dictionary.' + keyInfoConvention: 'Ideally: the simplest form of the term, in English, in lower-case.' images: 'Images' spoiler: 'Spoiler' otherVersions: 'In other languages' diff --git a/locale/eo/translations.suml b/locale/eo/translations.suml index 397dfd21d..f3402cfaf 100644 --- a/locale/eo/translations.suml +++ b/locale/eo/translations.suml @@ -101,7 +101,7 @@ sources: another: 'Alsendi pluan' moderation: 'Alsendaĵoj estas aprobendaj antaŭ ol publikigo.' key: 'Ŝlosilo' - keyInfo: 'Identigilo por ligi fontojn inter lingvoversiojn kaj ligado al la vortaro' + keyInfo: 'Identigilo por ligi fontojn inter lingvoversiojn kaj ligado al la vortaro.' images: 'Bildoj' otherVersions: 'En aliaj lingvoj' referenced: 'Ekzemploj de uzo' diff --git a/locale/es/translations.suml b/locale/es/translations.suml index 0285f3fbf..724f4689d 100644 --- a/locale/es/translations.suml +++ b/locale/es/translations.suml @@ -128,7 +128,7 @@ sources: another: 'Enviar otro' moderation: 'Los envíos deben ser aprobados antes de ser publicados.' key: 'Clave' - keyInfo: 'Identificador para vincular fuentes entre versiones en varios idiomas y vincularlas con el diccionario' + keyInfo: 'Identificador para vincular fuentes entre versiones en varios idiomas y vincularlas con el diccionario.' images: 'Imágenes' spoiler: 'Spoiler' fragmentsInfo: > diff --git a/locale/et/translations.suml b/locale/et/translations.suml index a61f0dd30..5416d8a62 100644 --- a/locale/et/translations.suml +++ b/locale/et/translations.suml @@ -100,7 +100,7 @@ sources: another: 'Esita veel üks' moderation: 'Esitatud viited kinnitatakse enne avaldamist moderaatori poolt.' key: 'Võti' - keyInfo: 'Identifikaator allikate sidumiseks keeleversioonide vahel ning sõnastikuga' + keyInfo: 'Identifikaator allikate sidumiseks keeleversioonide vahel ning sõnastikuga.' images: 'Pildid' spoiler: 'Spoiler' otherVersions: 'Teistes keeltes' diff --git a/locale/fr/translations.suml b/locale/fr/translations.suml index 00ca3d2ff..0305aab2e 100644 --- a/locale/fr/translations.suml +++ b/locale/fr/translations.suml @@ -118,7 +118,7 @@ sources: thanks: 'Merci de votre contribution !' another: 'Soumettre un autre exemple' moderation: 'Les soumissions devront être approuvées avant d’être publiées.' - keyInfo: 'Identifiant pour relier les sources entre les versions linguistiques et établir des liens avec le dictionnaire' + keyInfo: 'Identifiant pour relier les sources entre les versions linguistiques et établir des liens avec le dictionnaire.' images: 'Images' spoiler: 'Spoiler' otherVersions: 'Dans d’autres langues' diff --git a/locale/gl/translations.suml b/locale/gl/translations.suml index 995fff0a2..a2f8c151c 100644 --- a/locale/gl/translations.suml +++ b/locale/gl/translations.suml @@ -115,7 +115,7 @@ sources: another: 'Enviar outro' moderation: 'Os envios devem ser aprovados antes de serem publicados.' key: 'Chave' - keyInfo: 'Identificador para conectar fontes entre versões e conectar com dicionário' + keyInfo: 'Identificador para conectar fontes entre versões e conectar com dicionário.' images: 'Imagens' spoiler: 'Spoiler' # TODO otherVersions: 'Em outros idiomas' diff --git a/locale/it/translations.suml b/locale/it/translations.suml index 4b9052e4e..edd98e4c2 100644 --- a/locale/it/translations.suml +++ b/locale/it/translations.suml @@ -128,7 +128,7 @@ sources: another: 'Inviane un altro' moderation: 'Il materiale deve essere approvato prima della sua pubblicazione.' key: 'Chiave' - keyInfo: 'Identificativo per collegare fonti tra lingue diverse e collegarle con il dizionario' + keyInfo: 'Identificativo per collegare fonti tra lingue diverse e collegarle con il dizionario.' images: 'Immagini' otherVersions: 'In altre lingue' referenced: 'Esempi di utilizzo' diff --git a/locale/ja/translations.suml b/locale/ja/translations.suml index 6969796f3..7d1d05c0d 100644 --- a/locale/ja/translations.suml +++ b/locale/ja/translations.suml @@ -101,7 +101,7 @@ sources: another: 'もう一つ送信' moderation: '承認されるまで投稿は公開されません。' key: 'キー' - keyInfo: '言語間、及び辞書とリンクするのための識別子' + keyInfo: '言語間、及び辞書とリンクするのための識別子。' images: '画像' spoiler: 'ネタバレ' otherVersions: '他の言語で' diff --git a/locale/ko/translations.suml b/locale/ko/translations.suml index cbc8d4571..c07fe409b 100644 --- a/locale/ko/translations.suml +++ b/locale/ko/translations.suml @@ -118,7 +118,7 @@ sources: another: '제출 더하기' moderation: '제출물은 먼저 승인받아야합니다.' key: '키' - keyInfo: '언어 버전 간 소스 연결 및 사전 연결 식별자' + keyInfo: '언어 버전 간 소스 연결 및 사전 연결 식별자.' images: '이미지' spoiler: '스포주의' otherVersions: '다른 언어' diff --git a/locale/lad/translations.suml b/locale/lad/translations.suml index fb667cbf9..4759ac00e 100644 --- a/locale/lad/translations.suml +++ b/locale/lad/translations.suml @@ -117,7 +117,7 @@ sources: another: 'Embiar otruno' moderation: 'Los embios deven ser aseptados antes de ser publikados.' key: 'Yave' - keyInfo: 'Identifiador para atar manaderos entre versiones en varias linguas i atarlas kon el diksionaryo' + keyInfo: 'Identifiador para atar manaderos entre versiones en varias linguas i atarlas kon el diksionaryo.' images: 'Imajes' spoiler: 'Spoiler' otherVersions: 'En otras linguas' diff --git a/locale/nl/translations.suml b/locale/nl/translations.suml index d98583254..1029bb5de 100644 --- a/locale/nl/translations.suml +++ b/locale/nl/translations.suml @@ -116,7 +116,7 @@ sources: another: 'Dien nog een voorbeeld in' moderation: 'Inzendingen zullen moeten worden goedgekeurd alvorens te worden gepubliceerd.' key: 'Sleutel' - keyInfo: 'Identifier om bronnen te linken tussen verschillende vertalingen van de website en om met het woordenboek te linken' + keyInfo: 'Identifier om bronnen te linken tussen verschillende vertalingen van de website en om met het woordenboek te linken.' images: 'Afbeeldingen' spoiler: 'Spoiler' otherVersions: 'In andere talen' diff --git a/locale/no/translations.suml b/locale/no/translations.suml index ad5f7f458..8d2848fc9 100644 --- a/locale/no/translations.suml +++ b/locale/no/translations.suml @@ -110,7 +110,7 @@ sources: another: 'Legg til en til' moderation: 'Bidrag må bli vurdert og godtatt før de blir lagt ut.' key: 'Nøkkel' - keyInfo: 'identifiserer for å linke kilder mellom språkversjoner og linker med ordboken' + keyInfo: 'identifiserer for å linke kilder mellom språkversjoner og linker med ordboken.' images: 'Bilder' spoiler: 'Sladd' otherVersions: 'På andre språk' diff --git a/locale/pl/translations.suml b/locale/pl/translations.suml index e776ae3e6..f6976c46d 100644 --- a/locale/pl/translations.suml +++ b/locale/pl/translations.suml @@ -141,7 +141,8 @@ sources: another: 'Zgłoś kolejne źródło' moderation: 'Propozycje będą musiały zostać zatwierdzone przed opublikowaniem.' key: 'Klucz' - keyInfo: 'Identyfikator do łączenia tekstów między wersjami językowymi i łączenia ze słownikiem' + keyInfo: 'Identyfikator do łączenia tekstów między wersjami językowymi i łączenia ze słownikiem.' + keyInfoConvention: 'Najlepiej: najprostsza forma wpisu, po angielsku, małymi literami.' images: 'Obrazki' spoiler: 'Spoiler' otherVersions: 'W innych językach' diff --git a/locale/pt/translations.suml b/locale/pt/translations.suml index 29e6c2219..269b76d11 100644 --- a/locale/pt/translations.suml +++ b/locale/pt/translations.suml @@ -126,7 +126,7 @@ sources: another: 'Enviar outro' moderation: 'Os envios devem ser aprovados antes de serem publicados.' key: 'Chave' - keyInfo: 'Identificador para conectar fontes entre versões e conectar com dicionário' + keyInfo: 'Identificador para conectar fontes entre versões e conectar com dicionário.' images: 'Imagens' spoiler: 'Spoiler' fragmentsInfo: > diff --git a/locale/ru/translations.suml b/locale/ru/translations.suml index e248f6401..7cfca8754 100644 --- a/locale/ru/translations.suml +++ b/locale/ru/translations.suml @@ -122,7 +122,7 @@ sources: another: 'Добавить ещё' moderation: 'Предложения должны быть одобрены перед публикацией.' key: 'Ключ' - keyInfo: 'Идентификатор, используемый для связки источников из разных языковых версий и связки со словарём' + keyInfo: 'Идентификатор, используемый для связки источников из разных языковых версий и связки со словарём.' images: 'Изображения' spoiler: 'Спойлер' otherVersions: 'На других языках' diff --git a/locale/sv/translations.suml b/locale/sv/translations.suml index bb9212b76..31d41d010 100644 --- a/locale/sv/translations.suml +++ b/locale/sv/translations.suml @@ -122,7 +122,7 @@ sources: another: 'Skicka in en till' moderation: 'Bidragen måste godkännas innan de publiceras.' key: 'Nyckel' - keyInfo: 'Identifierare för att länka källor mellan språkversioner och länka till ordbok' + keyInfo: 'Identifierare för att länka källor mellan språkversioner och länka till ordbok.' images: 'Bilder' spoiler: 'Spoiler' # Swedish just takes the word spoiler directly otherVersions: 'På andra språk' diff --git a/locale/vi/translations.suml b/locale/vi/translations.suml index 103fa787d..7a2de64dc 100644 --- a/locale/vi/translations.suml +++ b/locale/vi/translations.suml @@ -128,7 +128,7 @@ sources: another: 'Gửi thêm' moderation: 'Các ví dụ sẽ phải được phê duyệt trước khi được thêm vào.' key: 'Mã định danh' - keyInfo: 'Mã định danh để liên kết các nguồn ở các phiên bản ngôn ngữ khác và liên kết với từ điển' + keyInfo: 'Mã định danh để liên kết các nguồn ở các phiên bản ngôn ngữ khác và liên kết với từ điển.' images: 'Ảnh' spoiler: 'Spoiler' otherVersions: 'Trong các ngôn ngữ khác' diff --git a/locale/zh/translations.suml b/locale/zh/translations.suml index 48fe3d48c..c264ef078 100644 --- a/locale/zh/translations.suml +++ b/locale/zh/translations.suml @@ -119,7 +119,7 @@ sources: another: '提交另一個' moderation: '提交的內容必須先獲得批准才能發布。' key: '鍵' # TODO - keyInfo: '用於在語言版本之間連接源並與字典連接的標誌符' + keyInfo: '用於在語言版本之間連接源並與字典連接的標誌符。' images: '意象' spoiler: '劇透內容' otherVersions: '在其他語言' diff --git a/server/routes/sources.ts b/server/routes/sources.ts index 9a53697d5..bd231ac44 100644 --- a/server/routes/sources.ts +++ b/server/routes/sources.ts @@ -95,17 +95,6 @@ router.get('/sources', handleErrorAsync(async (req, res) => { return res.json(await linkOtherVersions(req, await req.db.all(sql))); })); -router.get('/sources/:id', handleErrorAsync(async (req, res) => { - return res.json(await linkOtherVersions(req, await req.db.all(SQL` - SELECT s.*, u.username AS submitter FROM sources s - LEFT JOIN users u ON s.submitter_id = u.id - WHERE s.locale = ${global.config.locale} - AND s.deleted = 0 - AND s.approved >= ${req.isGranted('sources') ? 0 : 1} - AND s.id = ${req.params.id} - `))); -})); - router.post('/sources/submit', handleErrorAsync(async (req, res) => { if (!req.user || !await req.isUserAllowedToPost()) { return res.status(401).json({ error: 'Unauthorised' }); @@ -176,4 +165,31 @@ router.post('/sources/remove/:id', handleErrorAsync(async (req, res) => { return res.json('ok'); })); +router.get('/sources/keys', handleErrorAsync(async (req, res) => { + const keys = await req.db.all<{key: string}>(SQL` + SELECT trim(key) AS key + FROM sources + WHERE key IS NOT NULL + AND deleted = 0 + AND approved = 1 + GROUP BY key + ORDER BY key + `); + + return res.json( + Object.fromEntries(keys.map((k) => [k.key, k.key])), + ); +})); + +router.get('/sources/:id', handleErrorAsync(async (req, res) => { + return res.json(await linkOtherVersions(req, await req.db.all(SQL` + SELECT s.*, u.username AS submitter FROM sources s + LEFT JOIN users u ON s.submitter_id = u.id + WHERE s.locale = ${global.config.locale} + AND s.deleted = 0 + AND s.approved >= ${req.isGranted('sources') ? 0 : 1} + AND s.id = ${req.params.id} + `))); +})); + export default router; diff --git a/server/routes/terms.ts b/server/routes/terms.ts index 816d79758..53190a8f4 100644 --- a/server/routes/terms.ts +++ b/server/routes/terms.ts @@ -174,4 +174,20 @@ router.post('/terms/remove/:id', handleErrorAsync(async (req, res) => { return res.json('ok'); })); +router.get('/terms/keys', handleErrorAsync(async (req, res) => { + const keys = await req.db.all<{key: string}>(SQL` + SELECT trim(key) AS key + FROM terms + WHERE key IS NOT NULL + AND deleted = 0 + AND approved = 1 + GROUP BY key + ORDER BY key + `); + + return res.json( + Object.fromEntries(keys.map((k) => [k.key, k.key])), + ); +})); + export default router; From 2533b97f6c1468e8df6cc0fa25c5067fd9e0b9ce Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Sat, 10 Aug 2024 16:40:16 +0200 Subject: [PATCH 2/2] (lint) --- components/AutocompleteSelect.vue | 4 ++-- components/SourceSubmitForm.vue | 6 +++--- components/TermsSubmitForm.vue | 8 ++++---- components/TimezoneSelect.vue | 2 +- server/routes/sources.ts | 2 +- server/routes/terms.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/AutocompleteSelect.vue b/components/AutocompleteSelect.vue index a60ebf814..ea7062f41 100644 --- a/components/AutocompleteSelect.vue +++ b/components/AutocompleteSelect.vue @@ -30,7 +30,7 @@ export default { props: { value: {}, options: { required: true }, - freeform: { type: Boolean } + freeform: { type: Boolean }, }, data() { return { @@ -53,7 +53,7 @@ export default { if (this.freeform) { this.$emit('input', this.filter); } - } + }, }, methods: { select(option) { diff --git a/components/SourceSubmitForm.vue b/components/SourceSubmitForm.vue index 7d46fe869..032cbcb11 100644 --- a/components/SourceSubmitForm.vue +++ b/components/SourceSubmitForm.vue @@ -232,6 +232,9 @@ export default Vue.extend({ keys: {}, }; }, + async mounted() { + this.keys = await this.$axios.$get('/sources/keys'); + }, methods: { async submit(): Promise { this.submitting = true; @@ -278,8 +281,5 @@ export default Vue.extend({ this.$el.scrollIntoView(); }, }, - async mounted() { - this.keys = await this.$axios.$get('/sources/keys'); - }, }); diff --git a/components/TermsSubmitForm.vue b/components/TermsSubmitForm.vue index 3527cf9d9..a8303f336 100644 --- a/components/TermsSubmitForm.vue +++ b/components/TermsSubmitForm.vue @@ -53,7 +53,7 @@
- +

sources.submit.keyInfo sources.submit.keyInfoConvention @@ -144,6 +144,9 @@ export default Vue.extend({ keys: {}, }; }, + async mounted() { + this.keys = await this.$axios.$get('/terms/keys'); + }, methods: { async submit(): Promise { this.submitting = true; @@ -180,8 +183,5 @@ export default Vue.extend({ this.$el.scrollIntoView(); }, }, - async mounted() { - this.keys = await this.$axios.$get('/terms/keys'); - }, }); diff --git a/components/TimezoneSelect.vue b/components/TimezoneSelect.vue index d1fcdf2ff..e471d61ba 100644 --- a/components/TimezoneSelect.vue +++ b/components/TimezoneSelect.vue @@ -5,7 +5,7 @@ profile.timezone.detect - + diff --git a/server/routes/sources.ts b/server/routes/sources.ts index bd231ac44..48da51f90 100644 --- a/server/routes/sources.ts +++ b/server/routes/sources.ts @@ -166,7 +166,7 @@ router.post('/sources/remove/:id', handleErrorAsync(async (req, res) => { })); router.get('/sources/keys', handleErrorAsync(async (req, res) => { - const keys = await req.db.all<{key: string}>(SQL` + const keys = await req.db.all<{ key: string }>(SQL` SELECT trim(key) AS key FROM sources WHERE key IS NOT NULL diff --git a/server/routes/terms.ts b/server/routes/terms.ts index 53190a8f4..87b69d202 100644 --- a/server/routes/terms.ts +++ b/server/routes/terms.ts @@ -175,7 +175,7 @@ router.post('/terms/remove/:id', handleErrorAsync(async (req, res) => { })); router.get('/terms/keys', handleErrorAsync(async (req, res) => { - const keys = await req.db.all<{key: string}>(SQL` + const keys = await req.db.all<{ key: string }>(SQL` SELECT trim(key) AS key FROM terms WHERE key IS NOT NULL