refactoring: fix translation links
This commit is contained in:
parent
8085079eff
commit
2e9b1016de
5 changed files with 63 additions and 23 deletions
|
@ -7,6 +7,7 @@
|
||||||
import Locale from "../i18n/Locale";
|
import Locale from "../i18n/Locale";
|
||||||
import { Utils } from "../../Utils";
|
import { Utils } from "../../Utils";
|
||||||
import FromHtml from "./FromHtml.svelte";
|
import FromHtml from "./FromHtml.svelte";
|
||||||
|
import WeblateLink from "./WeblateLink.svelte";
|
||||||
|
|
||||||
export let t: Translation;
|
export let t: Translation;
|
||||||
export let tags: Record<string, string> | undefined = undefined;
|
export let tags: Record<string, string> | undefined = undefined;
|
||||||
|
@ -14,17 +15,22 @@
|
||||||
let txt: string | undefined;
|
let txt: string | undefined;
|
||||||
|
|
||||||
$: onDestroy(Locale.language.addCallbackAndRunD(l => {
|
$: onDestroy(Locale.language.addCallbackAndRunD(l => {
|
||||||
const translation = t?.textFor(l)
|
const translation = t?.textFor(l);
|
||||||
if (translation === undefined) {
|
if (translation === undefined) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
if (tags) {
|
if (tags) {
|
||||||
txt = Utils.SubstituteKeys(txt, tags)
|
txt = Utils.SubstituteKeys(txt, tags);
|
||||||
} else {
|
} else {
|
||||||
txt = translation
|
txt = translation;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if t}
|
||||||
|
<span class="inline-flex items-center">
|
||||||
<FromHtml src={txt}></FromHtml>
|
<FromHtml src={txt}></FromHtml>
|
||||||
|
<WeblateLink context={t.context}></WeblateLink>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
|
27
UI/Base/WeblateLink.svelte
Normal file
27
UI/Base/WeblateLink.svelte
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import Locale from "../i18n/Locale";
|
||||||
|
import LinkToWeblate from "./LinkToWeblate";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a small icon which will open up weblate; a contributor can translate the item for 'context' there
|
||||||
|
*/
|
||||||
|
export let context : string
|
||||||
|
|
||||||
|
let linkToWeblate = Locale.showLinkToWeblate;
|
||||||
|
let linkOnMobile = Locale.showLinkOnMobile;
|
||||||
|
let language = Locale.language;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
{#if context}
|
||||||
|
{#if $linkOnMobile}
|
||||||
|
<a href={LinkToWeblate.hrefToWeblate($language, context)} target="_blank" class="mx-1">
|
||||||
|
<img src="./assets/svg/translate.svg" class="w-3 h-3 rounded-full font-gray" />
|
||||||
|
</a>
|
||||||
|
{:else if $linkToWeblate}
|
||||||
|
<a href={LinkToWeblate.hrefToWeblate($language, context)} class="hidden-on-mobile mx-1" target="_blank">
|
||||||
|
<img src="./assets/svg/translate.svg" class="w-3 h-3 rounded-full font-gray" />
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
|
@ -8,8 +8,9 @@
|
||||||
import type { Feature } from "geojson";
|
import type { Feature } from "geojson";
|
||||||
import { UIEventSource } from "../../../Logic/UIEventSource.js";
|
import { UIEventSource } from "../../../Logic/UIEventSource.js";
|
||||||
import ToSvelte from "../../Base/ToSvelte.svelte";
|
import ToSvelte from "../../Base/ToSvelte.svelte";
|
||||||
import FromHtml from "../../Base/FromHtml.svelte";
|
|
||||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig";
|
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig";
|
||||||
|
import WeblateLink from "../../Base/WeblateLink.svelte";
|
||||||
|
import FromHtml from "../../Base/FromHtml.svelte";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 'specialTranslation' renders a `Translation`-object, but interprets the special values as well
|
* The 'specialTranslation' renders a `Translation`-object, but interprets the special values as well
|
||||||
|
@ -34,7 +35,10 @@
|
||||||
|
|
||||||
{#each specs as specpart}
|
{#each specs as specpart}
|
||||||
{#if typeof specpart === "string"}
|
{#if typeof specpart === "string"}
|
||||||
<FromHtml src={Utils.SubstituteKeys(specpart, $tags)}></FromHtml>
|
<span class="inline-flex items-center">
|
||||||
|
<FromHtml src={Utils.SubstituteKeys(specpart, $tags)} />
|
||||||
|
<WeblateLink context={t.context} />
|
||||||
|
</span>
|
||||||
{:else if $tags !== undefined }
|
{:else if $tags !== undefined }
|
||||||
<ToSvelte construct={specpart.func.constr(state, tags, specpart.args, feature, layer)}></ToSvelte>
|
<ToSvelte construct={specpart.func.constr(state, tags, specpart.args, feature, layer)}></ToSvelte>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -7,7 +7,7 @@ export class Translation extends BaseUIElement {
|
||||||
public static forcedLanguage = undefined
|
public static forcedLanguage = undefined
|
||||||
|
|
||||||
public readonly translations: Record<string, string>
|
public readonly translations: Record<string, string>
|
||||||
context?: string
|
public readonly context?: string
|
||||||
|
|
||||||
constructor(translations: Record<string, string>, context?: string) {
|
constructor(translations: Record<string, string>, context?: string) {
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -762,8 +762,12 @@ video {
|
||||||
top: 1rem;
|
top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bottom-2 {
|
.right-1 {
|
||||||
bottom: 0.5rem;
|
right: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom-1 {
|
||||||
|
bottom: 0.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.left-1\/2 {
|
.left-1\/2 {
|
||||||
|
@ -1039,6 +1043,10 @@ video {
|
||||||
height: 3rem;
|
height: 3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.h-6 {
|
||||||
|
height: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.h-screen {
|
.h-screen {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
@ -1047,10 +1055,6 @@ video {
|
||||||
height: 1rem;
|
height: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.h-6 {
|
|
||||||
height: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h-1\/2 {
|
.h-1\/2 {
|
||||||
height: 50%;
|
height: 50%;
|
||||||
}
|
}
|
||||||
|
@ -1170,11 +1174,6 @@ video {
|
||||||
width: 24rem;
|
width: 24rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w-min {
|
|
||||||
width: -webkit-min-content;
|
|
||||||
width: min-content;
|
|
||||||
}
|
|
||||||
|
|
||||||
.w-24 {
|
.w-24 {
|
||||||
width: 6rem;
|
width: 6rem;
|
||||||
}
|
}
|
||||||
|
@ -1455,6 +1454,10 @@ video {
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.border-dashed {
|
||||||
|
border-style: dashed;
|
||||||
|
}
|
||||||
|
|
||||||
.border-dotted {
|
.border-dotted {
|
||||||
border-style: dotted;
|
border-style: dotted;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue