Skip to content

Commit

Permalink
Use description text for weblink plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dokempf committed Jul 30, 2024
1 parent 0d1cc5c commit 2477e02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/fields/CustomDataTypeLink.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script>
import { bestLanguage } from "../../lib/l10n";
import { dataLanguagesStore } from "../../lib/stores";
import { fieldData } from "../../lib/easydbHelpers";
import { A } from "flowbite-svelte";
Expand All @@ -10,4 +12,4 @@
const fdata = fieldData(data, table, field);
</script>

<A href={fdata.url}>{fdata.url}</A>
<A href={fdata.url}>{bestLanguage(fdata.text, $dataLanguagesStore)}</A>
11 changes: 7 additions & 4 deletions src/lib/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ const language_priority = ["de-DE", "en-US"];
// Select the best language from the given data
export function bestLanguage(data, lang) {
// If the selected language exists, we take it
if (lang in data) {
return data[lang];
for (let l of lang) {
if ((l in data) && (data[l] !== "")) {
return data[l];
}
}

// Otherwise we select the language with the highest priority
for (let l in language_priority) {
if (l in data)
for (let l of language_priority) {
if ((l in data) && (data[l] !== "")) {
return data[l];
}
}

// Finally, we select any language that we can find
Expand Down

0 comments on commit 2477e02

Please sign in to comment.