Enable all languages in translators mode

This commit is contained in:
pietervdvn 2022-04-03 03:00:45 +02:00
parent 86d9047e5e
commit a037d04577
3 changed files with 25 additions and 8 deletions

View file

@ -66,10 +66,6 @@ export default class UserRelatedState extends ElementsState {
} }
}); });
QueryParameters.GetBooleanQueryParameter("fs-translation-mode",false,"If set, will show the translation buttons")
.addCallbackAndRunD(tr => Locale.showLinkToWeblate.setData(Locale.showLinkToWeblate.data || tr))
this.changes = new Changes(this, layoutToUse?.isLeftRightSensitive() ?? false) this.changes = new Changes(this, layoutToUse?.isLeftRightSensitive() ?? false)
@ -126,6 +122,9 @@ export default class UserRelatedState extends ElementsState {
if (layoutToUse === undefined) { if (layoutToUse === undefined) {
return; return;
} }
if(Locale.showLinkToWeblate.data){
return true; // Disable auto switching as we are in translators mode
}
if (this.layoutToUse.language.indexOf(currentLanguage) < 0) { if (this.layoutToUse.language.indexOf(currentLanguage) < 0) {
console.log( console.log(
"Resetting language to", "Resetting language to",

View file

@ -4,22 +4,33 @@ import BaseUIElement from "./BaseUIElement";
import * as native from "../assets/language_native.json" import * as native from "../assets/language_native.json"
import * as language_translations from "../assets/language_translations.json" import * as language_translations from "../assets/language_translations.json"
import {Translation} from "./i18n/Translation"; import {Translation} from "./i18n/Translation";
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 {
public static CreateLanguagePicker( public static CreateLanguagePicker(
languages: string[], languages: string[],
label: string | BaseUIElement = "") { label: string | BaseUIElement = "") : BaseUIElement{
if (languages === undefined || languages.length <= 1) { if (languages === undefined || languages.length <= 1) {
return undefined; return undefined;
} }
return new DropDown(label, languages.map(lang => { 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)
}
private static dropdownFor(languages: string[], label: string | BaseUIElement): BaseUIElement {
return new DropDown(label, languages.map(lang => {
return {value: lang, shown: LanguagePicker.hybrid(lang) } return {value: lang, shown: LanguagePicker.hybrid(lang) }
} }
), Locale.language); ), Locale.language)
} }
private static hybrid(lang: string): Translation { private static hybrid(lang: string): Translation {

View file

@ -6,8 +6,8 @@ import {QueryParameters} from "../../Logic/Web/QueryParameters";
export default class Locale { export default class Locale {
public static showLinkToWeblate: UIEventSource<boolean> = new UIEventSource<boolean>(false);
public static language: UIEventSource<string> = Locale.setup(); public static language: UIEventSource<string> = Locale.setup();
public static showLinkToWeblate: UIEventSource<boolean> = new UIEventSource<boolean>(false);
private static setup() { private static setup() {
const source = LocalStorageSource.Get('language', "en"); const source = LocalStorageSource.Get('language', "en");
@ -20,6 +20,13 @@ export default class Locale {
QueryParameters.GetQueryParameter("language", undefined, "The language to display mapcomplete in. Will be ignored in case a logged-in-user did set their language before. If the specified language does not exist, it will default to the first language in the theme."), QueryParameters.GetQueryParameter("language", undefined, "The language to display mapcomplete in. Will be ignored in case a logged-in-user did set their language before. If the specified language does not exist, it will default to the first language in the theme."),
true true
) )
QueryParameters.GetBooleanQueryParameter("fs-translation-mode",false,"If set, will show the translation buttons")
.addCallbackAndRunD(tr => {
console.log("Query parameter for translation mode is", tr)
Locale.showLinkToWeblate.setData(Locale.showLinkToWeblate.data || tr);
})
} }
return source; return source;
} }