1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
let langs = {
en : {
// error message in case the survey url was obviously invalid (currently only the case if none was given)
"Error: nothing here": "There's nothing here. Maybe try appending something after the url?\n\nAlternatively, check to see if you copied the whole url.",
// error message in case the http request on the survey url returned a status code that wasn't 200
"Error: survey doesn't exist": "Could not load this survey; are you sure that it exists?",
// error message in case the survey url was loaded, but had some obviously invalid format (i.e. neither json nor age encryption)
"Error: unknown format": "Could not load this survey; it appears to be in a wrong or unknown format.",
// text fragment in error messages, after which the survey url will be printed
"attempted path:": "Attempted path:",
// prompt for a passphrase
"please enter passphrase": "please enter a passphrase to access the survey:",
// error message in case decryption failed
"passphrase incorrect": "passphrase was incorrect!",
// document title for the decryption dialog
"Enter Passphrase": "Enter Passphrase",
// header of the decryption dialog
"Passphrase": "Passphrase",
// the text on the "decrypt" button
"decrypt": "decrypt",
// the text on the "submit" button
"submit": "submit",
// error message in case the given answers were invalid
"Error: answers invalid":"Cannot submit: not all required questions were filled in!",
// error message in case the post request failed entirely (i.e. printed if the .catch-clause of the fetch() function is reached)
"Error: could not post":"Error: The http POST request did not succeed.",
// error message in case the post request returned some other status code than 200; its status code and message will be appended in the next line after the text given here
"Error: post returned error":"Error: The http POST request returned an error code:"
},
de : {
"Error: nothing here": "Hier ist nichts. Evtl. hilft es, etwas hinten an die url dranzuhängen?\n\nAnsonsten: bist du dir sicher, dass du den ganzen Link hierher kopiert hast?",
"Error: survey doesn't exist": "Diese Umfrage konnte nicht geladen werden. Bist du sicher, dass sie existiert?",
"Error: unknown format": "Diese Umfrage scheint ein unbekanntes Format zu haben und konnte nicht angezeigt werden",
"attempted path:": "Abgerufener Pfad:",
"please enter passphrase": "Bitte gebe eine Passphrase ein, um die Umfrage zu entschlüsseln",
"passphrase incorrect": "Passphrase war nicht korrekt!",
"Passphrase": "Passphrase",
"decrypt":"entschlüsseln",
"submit":"absenden",
"Enter Passphrase": "Passphrase eingeben",
"Error: answers invalid":"Einige verpflichtenden Antworten fehlen!",
"Error: could not post":"Fehler: Die http POST Anfrage schlug fehl.",
"Error: post returned error":"Fehler: Die http POST Anfragen schlug fehl und gab einen Fehlercode zurück:"
}
}
// we use english by default until something else is set
let locale = "en";
// the main translation function. if no fitting translation
// is found, it returns the key as a fallback value
// (therefore, keys should themselves be understandable texts)
export function _(key) {
if (!(locale in langs) ? false : (key in langs[locale])) {
return langs[locale][key];
} else {
console.log("missing translation for lang, key:", locale, key);
return key;
}
}
export function setLang (loc) {
console.log("set lang to", loc);
locale = loc;
}
/// attempt to set the site's language to the browser's preference.
/// in case it's not supported it tries any of the languages in
/// navigator.languages, and then falls back to english.
export function tryBrowserDefaultLang () {
let guess = navigator.language;
if (guess in langs) {
setLang(guess);
} else {
for (var lang of navigator.languages) {
if (lang in langs) {
setLang (lang);
return;
}
}
setLang("en");
}
}
export default _;
|