summaryrefslogtreecommitdiff
path: root/src/ollama_web/static/i18n.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ollama_web/static/i18n.js')
-rw-r--r--src/ollama_web/static/i18n.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ollama_web/static/i18n.js b/src/ollama_web/static/i18n.js
new file mode 100644
index 0000000..985b452
--- /dev/null
+++ b/src/ollama_web/static/i18n.js
@@ -0,0 +1,28 @@
+/** Small i18n helper for the browser.
+ *
+ * The server injects ``window.I18N`` as a nested message object. This module
+ * exposes ``t(key, fallback)`` to resolve dot-separated keys safely.
+ */
+(function () {
+ "use strict";
+
+ function t(key, fallback) {
+ if (typeof key !== "string") {
+ return fallback !== undefined ? fallback : String(key);
+ }
+ const parts = key.split(".");
+ let current = window.I18N;
+ for (const part of parts) {
+ if (current == null || typeof current !== "object" || !(part in current)) {
+ return fallback !== undefined ? fallback : key;
+ }
+ current = current[part];
+ }
+ if (typeof current === "string") {
+ return current;
+ }
+ return fallback !== undefined ? fallback : key;
+ }
+
+ window.t = t;
+})();