summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--site/i18n.js19
-rw-r--r--site/index.html6
-rw-r--r--todo.org4
3 files changed, 24 insertions, 5 deletions
diff --git a/site/i18n.js b/site/i18n.js
index 38ffe7b..5f882c5 100644
--- a/site/i18n.js
+++ b/site/i18n.js
@@ -54,7 +54,6 @@ let locale = "en";
// is found, it returns the key as a fallback value
// (therefore, keys should themselves be understandable texts)
export function _(key) {
- console.log("getting translation for ", locale, key);
return !(locale in langs) ? key
: !(key in langs[locale]) ? key
: langs[locale][key]
@@ -64,4 +63,22 @@ export function setLang (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(lang);
+ } else {
+ for (var lang of navigator.languages) {
+ if (lang in langs) {
+ setLang (lang);
+ return;
+ }
+ }
+ setLang("en");
+ }
+}
+
export default _;
diff --git a/site/index.html b/site/index.html
index bceb936..c2ac9c9 100644
--- a/site/index.html
+++ b/site/index.html
@@ -1,7 +1,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
- <title>test</title>
+ <title>Error</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
@@ -10,7 +10,7 @@
<script type="module">
import init, { age_encrypt, age_decrypt } from "./rage_wasm.js";
- import _, { setLang } from "./i18n.js";
+ import _, { setLang, tryBrowserDefaultLang } from "./i18n.js";
/// the basic idea here is to have functions which construct parts
/// of the DOM that renders the survey to a user. These functions
@@ -296,6 +296,8 @@
}
}
+ // attempt to set the site's language to the browsers's preference
+ tryBrowserDefaultLang();
if (surveyUrl === "") {
mkReadError (_("Error: nothing here"));
} else {
diff --git a/todo.org b/todo.org
index 3ea98c0..6c5ccb6 100644
--- a/todo.org
+++ b/todo.org
@@ -11,7 +11,7 @@
** IDEA via length
* TODO Server
-** TODO raise less exceptions
+** TODO raise fewer exceptions
** IDEA possibly switch from guile to rust or something
* TODO List of public surveys
@@ -20,5 +20,5 @@
* TODO UI
** IDEA Surveys with multiple pages
Seems unclear how to do this in a way that also works with screen readers etc.
-** TODO Support for multiple languages (defined via config.dhall)
+** DONE Support for multiple languages (defined via config.dhall)
** DONE Automatic Dark mode