2018-03-20 13:30:00 +01:00
|
|
|
/*
|
|
|
|
|
* Verrückte Turing-Maschinen — A turing complete game
|
|
|
|
|
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-26 22:14:10 +02:00
|
|
|
module mod_vtm
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
|
|
|
|
|
2018-03-26 22:14:10 +02:00
|
|
|
export module mod_helfer
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
|
|
|
|
|
export module mod_uebersetzung
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
|
|
|
*/
|
|
|
|
|
var _sprachstapel : Array<string>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
|
|
|
*/
|
|
|
|
|
var _daten : {[sprache : string] : {[schluessel : string] : string}} = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
|
|
|
*/
|
|
|
|
|
export function einrichten(sprachen : Array<string>) : void
|
|
|
|
|
{
|
|
|
|
|
_sprachstapel = [];
|
|
|
|
|
sprachen.forEach
|
|
|
|
|
(
|
|
|
|
|
sprache =>
|
|
|
|
|
{
|
2018-03-27 17:24:31 +02:00
|
|
|
let zeichenketten_roh_ : lib_fehlermonade.typ_fehlermonade<any> = mod_vtm_daten.lesen("zeichenketten-" + sprache);
|
|
|
|
|
if (lib_fehlermonade.voll(zeichenketten_roh_))
|
2018-03-26 22:14:10 +02:00
|
|
|
{
|
2018-03-27 17:24:31 +02:00
|
|
|
let zeichenketten_roh : {[schluessel : string] : string} = (<{[schluessel : string] : string}>(lib_fehlermonade.lesen(zeichenketten_roh_)));
|
2018-03-26 22:14:10 +02:00
|
|
|
_daten[sprache] = {};
|
|
|
|
|
for (let schluessel in zeichenketten_roh)
|
|
|
|
|
{
|
|
|
|
|
_daten[sprache][schluessel] = (<string>(zeichenketten_roh[schluessel]));
|
|
|
|
|
}
|
|
|
|
|
_sprachstapel.push(sprache);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
let meldung : string = ("Zeichenketten für Sprache '" + sprache + "' konnten nicht geladen werden");
|
|
|
|
|
console.warn(meldung);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
|
|
|
*/
|
2018-03-27 17:24:31 +02:00
|
|
|
function lesen(sprache : string, schluessel : string) : lib_fehlermonade.typ_fehlermonade<string>
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
if (sprache in _daten)
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
let satz : {[schluessel : string] : string} = _daten[sprache];
|
|
|
|
|
if (schluessel in satz)
|
|
|
|
|
{
|
2018-03-27 17:24:31 +02:00
|
|
|
return (lib_fehlermonade.mod_schlicht.erstellen<string>(satz[schluessel]));
|
2018-03-26 22:14:10 +02:00
|
|
|
}
|
|
|
|
|
else
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
let meldung : string = ("keine Zeichenketten für Schlüssel '" + schluessel + "' in Sprache '" + sprache + "'");
|
|
|
|
|
console.warn(meldung);
|
2018-03-27 17:24:31 +02:00
|
|
|
return (lib_fehlermonade.mod_nichts.erstellen<string>());
|
2018-03-20 13:30:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
let meldung : string = ("keine Zeichenketten für Sprache '" + sprache + "'");
|
2018-03-20 13:30:00 +01:00
|
|
|
console.warn(meldung);
|
2018-03-27 17:24:31 +02:00
|
|
|
return (lib_fehlermonade.mod_nichts.erstellen<string>());
|
2018-03-20 13:30:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-26 22:14:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
|
|
|
*/
|
|
|
|
|
export function holen(schluessel : string, vars : {[name : string] : string} = {}) : string
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-27 17:24:31 +02:00
|
|
|
let ergebnis : lib_fehlermonade.typ_fehlermonade<string> = (lib_fehlermonade.mod_nichts.erstellen<string>());
|
2018-03-26 22:14:10 +02:00
|
|
|
let gefunden : boolean = (
|
|
|
|
|
_sprachstapel
|
|
|
|
|
.some
|
|
|
|
|
(
|
|
|
|
|
sprache =>
|
|
|
|
|
{
|
2018-03-27 17:24:31 +02:00
|
|
|
let ergebnis_ : lib_fehlermonade.typ_fehlermonade<string> = lesen(sprache, schluessel);
|
|
|
|
|
if (lib_fehlermonade.voll(ergebnis_))
|
2018-03-26 22:14:10 +02:00
|
|
|
{
|
|
|
|
|
ergebnis = ergebnis_;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
if (gefunden)
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-27 17:24:31 +02:00
|
|
|
let str : string = lib_fehlermonade.lesen(ergebnis);
|
2018-03-26 22:14:10 +02:00
|
|
|
for (let name in vars)
|
2018-03-20 13:30:00 +01:00
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
let muster : RegExp = (new RegExp("!var:" + name));
|
|
|
|
|
let wert : string = vars[name];
|
|
|
|
|
str = str.replace(muster, wert);
|
2018-03-20 13:30:00 +01:00
|
|
|
}
|
2018-03-26 22:14:10 +02:00
|
|
|
return str;
|
2018-03-20 13:30:00 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-03-26 22:14:10 +02:00
|
|
|
return ("{" + schluessel + "}");
|
2018-03-20 13:30:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-26 22:14:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
|
|
|
*/
|
|
|
|
|
export function anwenden(kontext : DocumentFragment) : void
|
|
|
|
|
{
|
|
|
|
|
let muster : RegExp = (new RegExp("^!translate:([a-z0-9\.]*)$"));
|
|
|
|
|
document.querySelectorAll("*")[""+"forEach"]
|
|
|
|
|
(
|
|
|
|
|
element =>
|
|
|
|
|
{
|
|
|
|
|
if (element.childElementCount === 0)
|
|
|
|
|
{
|
|
|
|
|
let inhalt : string = element.textContent;
|
|
|
|
|
let fund : any = muster.exec(inhalt);
|
|
|
|
|
if (fund != null)
|
|
|
|
|
{
|
|
|
|
|
let schluessel : string = fund[1];
|
|
|
|
|
let inhalt_ : string = holen(schluessel);
|
|
|
|
|
element.textContent = inhalt_;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// nichts tun
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// nichts tun
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 13:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|