LanguagePicker now has a proper constructor

This commit is contained in:
pietervdvn 2022-07-03 00:30:11 +02:00
parent 8047f69fea
commit 51a6756dd4
6 changed files with 29 additions and 30 deletions

View file

@ -5,7 +5,7 @@ import MoreScreen from "./BigComponents/MoreScreen";
import Translations from "./i18n/Translations";
import Constants from "../Models/Constants";
import {Utils} from "../Utils";
import LanguagePicker from "./LanguagePicker";
import LanguagePicker1 from "./LanguagePicker";
import IndexText from "./BigComponents/IndexText";
import FeaturedMessage from "./BigComponents/FeaturedMessage";
import Toggle from "./Input/Toggle";
@ -21,7 +21,7 @@ export default class AllThemesGui {
const state = new UserRelatedState(undefined);
const intro = new Combine([
LanguagePicker.CreateLanguagePicker(Translations.t.index.title.SupportedLanguages())
new LanguagePicker1(Translations.t.index.title.SupportedLanguages(), "")
.SetClass("flex absolute top-2 right-3"),
new IndexText()

View file

@ -9,7 +9,6 @@ import Svg from "../../Svg";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import FullWelcomePaneWithTabs from "./FullWelcomePaneWithTabs";
import Title from "../Base/Title";
export default class ThemeIntroductionPanel extends Combine {
@ -17,7 +16,7 @@ export default class ThemeIntroductionPanel extends Combine {
const t = Translations.t.general
const layout = state.layoutToUse
const languagePicker = LanguagePicker.CreateLanguagePicker(layout.language, t.pickLanguage.Clone())
const languagePicker = new LanguagePicker(layout.language, t.pickLanguage.Clone())
const toTheMap = new SubtleButton(
undefined,

View file

@ -39,7 +39,7 @@ export default class UserBadge extends LoginToggle {
});
const linkStyle = "flex items-baseline"
const languagePicker = (LanguagePicker.CreateLanguagePicker(state.layoutToUse.language) ?? new FixedUiElement(""))
const languagePicker = (new LanguagePicker(state.layoutToUse.language, "") ?? new FixedUiElement(""))
.SetStyle("width:min-content;");
let messageSpan =

View file

@ -62,7 +62,7 @@ export default class ImportHelperGui extends LeftIndex {
}),
toc,
new Toggle(t.testMode.SetClass("block alert"), undefined, state.featureSwitchIsTesting),
LanguagePicker.CreateLanguagePicker(Translations.t.importHelper.title.SupportedLanguages())?.SetClass("mt-4 self-end flex-col"),
new LanguagePicker(Translations.t.importHelper.title.SupportedLanguages(), "")?.SetClass("mt-4 self-end flex-col"),
].map(el => el?.SetClass("pl-4"))
super(

View file

@ -8,52 +8,52 @@ import * as used_languages from "../assets/generated/used_languages.json"
import Lazy from "./Base/Lazy";
import Toggle from "./Input/Toggle";
export default class LanguagePicker {
export default class LanguagePicker extends Toggle {
public static CreateLanguagePicker(
languages: string[],
label: string | BaseUIElement = "") : BaseUIElement{
constructor(languages: string[],
label: string | BaseUIElement = "") {
if (languages === undefined || languages.length <= 1) {
return undefined;
}
const allLanguages : string[] = used_languages.languages;
const allLanguages: string[] = used_languages.languages;
const normalPicker = LanguagePicker.dropdownFor(languages, label);
const fullPicker = new Lazy(() => LanguagePicker.dropdownFor(allLanguages, label))
return new Toggle(fullPicker, normalPicker, Locale.showLinkToWeblate)
super(fullPicker, normalPicker, Locale.showLinkToWeblate);
}
private static dropdownFor(languages: string[], label: string | BaseUIElement): BaseUIElement {
return new DropDown(label, languages
.filter(lang => lang !== "_context")
.map(lang => {
return {value: lang, shown: LanguagePicker.hybrid(lang) }
}
), Locale.language)
return new DropDown(label, languages
.filter(lang => lang !== "_context")
.map(lang => {
return {value: lang, shown: LanguagePicker.hybrid(lang)}
}
), Locale.language)
}
private static hybrid(lang: string): Translation {
const nativeText = native[lang] ?? lang
const allTranslations = (language_translations["default"] ?? language_translations)
const allTranslations = (language_translations["default"] ?? language_translations)
const translation = {}
const trans = allTranslations[lang]
if(trans === undefined){
const trans = allTranslations[lang]
if (trans === undefined) {
return new Translation({"*": nativeText})
}
for (const key in trans) {
const translationInKey = allTranslations[lang][key]
if(nativeText.toLowerCase() === translationInKey.toLowerCase()){
if (nativeText.toLowerCase() === translationInKey.toLowerCase()) {
translation[key] = nativeText
}else{
translation[key] = nativeText + " ("+translationInKey+")"
} else {
translation[key] = nativeText + " (" + translationInKey + ")"
}
}
return new Translation(translation)
}
}
}

View file

@ -98,7 +98,7 @@ class ProfessionalGui extends LeftIndex {
maxDepth: 2
}).SetClass("subtle"),
LanguagePicker.CreateLanguagePicker(Translations.t.professional.title.SupportedLanguages())?.SetClass("mt-4 self-end flex-col"),
new LanguagePicker(Translations.t.professional.title.SupportedLanguages(), "")?.SetClass("mt-4 self-end flex-col"),
].map(el => el?.SetClass("pl-4"))
super(leftContents, content)