-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const messages = require('./messages.json'); | ||
const languages = ['en', 'de']; | ||
|
||
const getString = (lang, key) => { | ||
if (!(key in messages[lang])) console.error(`untranslated key in lang ${lang}: ${key}`); | ||
return messages[lang][key] ?? key; | ||
} | ||
|
||
const update = (lang) => { | ||
for (const el of Array.from(document.querySelectorAll('[data-i18n]'))) { | ||
el.innerText = getString(lang, el.dataset.i18n); | ||
} | ||
|
||
for (const el of Array.from(document.querySelectorAll('[data-i18n-alt]'))) { | ||
el.alt = getString(lang, el.dataset['i18nAlt']); | ||
} | ||
}; | ||
|
||
module.exports = (select) => { | ||
for (const value of languages) { | ||
select.add(new Option(messages[value]['language-name'], value)); | ||
} | ||
|
||
select.value = localStorage.density_lens_lang; | ||
if (!select.value) { | ||
for (const lang of navigator.languages) { | ||
const code = lang.toLowerCase().split('-').shift(); | ||
if (languages.indexOf(code) > -1) { | ||
select.value = code; | ||
console.log('found', code); | ||
break; | ||
} | ||
} | ||
} | ||
if (!select.value) select.value = 'de'; | ||
|
||
select.onchange = () => { | ||
update(select.value); | ||
localStorage.density_lens_lang = select.value; | ||
} | ||
update(select.value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"en": { | ||
"language-code": "en", | ||
"language-name": "English", | ||
|
||
"label-c": "digital spaces", | ||
"label-m": "motivations", | ||
"label-y": "relationships", | ||
"credits": "credits", | ||
"calibration": "calibration", | ||
|
||
"title": "Stories of Online Harassment", | ||
"start-intro": "To explore the poster, give access to your phone camera and calibrate it.", | ||
"start-button": "start", | ||
"start-cta": "Press start when you are ready.", | ||
"calibration-intro": "Align the following scheme to the coloured version on the poster and press Calibrate.", | ||
"calibration-button": "calibrate", | ||
"credits-developed": "Developed by", | ||
"credits-designed": "Designed by", | ||
"credits-back": "back" | ||
}, | ||
"de": { | ||
"language-code": "de", | ||
"language-name": "Deutsch", | ||
|
||
"label-c": "digitale räume", | ||
"label-m": "motivationen", | ||
"label-y": "beziehungen", | ||
"credits": "impressum", | ||
"calibration": "kalibrierung", | ||
|
||
"title": "Stories of Online Harassment", | ||
"start-intro": "Gib den Kamerazugriff frei und kalibriere die Farbwerte um das Poster zu erforschen.", | ||
"start-button": "start", | ||
"start-cta": "Drücke auf start wenn du bereit bist.", | ||
"calibration-intro": "Richte das Bild an dem bunten Symbol auf dem Poster aus und bestätige um das Bild zu kalibrieren.", | ||
"calibration-button": "kalibrieren", | ||
"credits-developed": "Entwickelt von", | ||
"credits-designed": "Designed von", | ||
"credits-back": "zurück" | ||
} | ||
} |