Better validated text fields with translations and human-friendly texts: first draft

This commit is contained in:
Pieter Vander Vennet 2022-02-11 04:28:11 +01:00
parent 695a0867c7
commit 9ab4fbd6f5
7 changed files with 581 additions and 528 deletions

View file

@ -23,6 +23,7 @@ import Table from "../Base/Table";
import Combine from "../Base/Combine";
import Title from "../Base/Title";
import InputElementMap from "./InputElementMap";
import Translations from "../i18n/Translations";
interface TextFieldDef {
name: string,
@ -84,7 +85,7 @@ class WikidataTextField implements TextFieldDef {
]).AsMarkdown()
public isValid(str) {
public isValid(str) : boolean{
if (str === undefined) {
return false;
@ -490,6 +491,7 @@ export default class ValidatedTextField {
* {string (typename) --> TextFieldDef}
*/
public static AllTypes: Map<string, TextFieldDef> = ValidatedTextField.allTypesDict();
private static Tranlations: string | BaseUIElement;
public static InputForType(type: string, options?: {
placeholder?: string | BaseUIElement,
@ -508,7 +510,9 @@ export default class ValidatedTextField {
inputStyle?: string
}): InputElement<string> {
options = options ?? {};
options.placeholder = options.placeholder ?? type;
if(options.placeholder === undefined) {
options.placeholder = Translations.t.validation[type]?.description ?? type
}
const tp: TextFieldDef = ValidatedTextField.AllTypes.get(type)
const isValidTp = tp.isValid;
let isValid;

View file

@ -1,11 +1,12 @@
import {FixedUiElement} from "../Base/FixedUiElement";
import AllTranslationAssets from "../../AllTranslationAssets";
import {Translation} from "./Translation";
import BaseUIElement from "../BaseUIElement";
import * as known_languages from "../../assets/generated/used_languages.json"
import CompiledTranslations from "../../assets/generated/CompiledTranslations";
export default class Translations {
static t = AllTranslationAssets.t;
static t = CompiledTranslations.t;
private static knownLanguages = new Set(known_languages.languages)
constructor() {
throw "Translations is static. If you want to intitialize a new translation, use the singular form"