Add translation buttons

This commit is contained in:
Pieter Vander Vennet 2022-04-01 12:51:55 +02:00
parent 592bc4ae0b
commit 2c7fb556dc
31 changed files with 442 additions and 150 deletions

View file

@ -16,6 +16,7 @@ export default class Link extends BaseUIElement {
if (this._embeddedShow === undefined) {
throw "Error: got a link where embeddedShow is undefined"
}
this.onClick(() => {})
}

33
UI/Base/LinkToWeblate.ts Normal file
View file

@ -0,0 +1,33 @@
import {VariableUiElement} from "./VariableUIElement";
import Locale from "../i18n/Locale";
import Link from "./Link";
import Svg from "../../Svg";
export default class LinkToWeblate extends VariableUiElement {
constructor(context: string, availableTranslations: object) {
super( Locale.language.map(ln => {
if (Locale.showLinkToWeblate.data === false) {
return undefined;
}
if(availableTranslations["*"] !== undefined){
return undefined
}
const icon = Svg.translate_svg()
.SetClass("rounded-full border border-gray-400 inline-block w-4 h-4 m-1 weblate-link self-center")
if(availableTranslations[ln] === undefined){
icon.SetClass("bg-red-400")
}
return new Link(icon,
LinkToWeblate.hrefToWeblate(ln, context), true)
} ,[Locale.showLinkToWeblate]));
this.SetClass("enable-links hidden-on-mobile")
}
public static hrefToWeblate(language: string, contextKey: string): string{
const [category, ...rest] = contextKey.split(":")
const key = rest.join(":")
const baseUrl = "https://hosted.weblate.org/translate/mapcomplete/"
return baseUrl + category + "/" + language + "/?offset=1&q=context%3A%3D%22" + key + "%22"
}
}