frontend js translations

This commit is contained in:
Thomas Lynch
2023-04-20 21:23:50 +10:00
parent 2af32627eb
commit f1cf3f6390
4 changed files with 25 additions and 14 deletions

View File

@@ -13,7 +13,7 @@ local randbytes = require("randbytes")
local templates = require("templates")
local locales_path = "/etc/haproxy/locales/"
local locales_table = {}
-- local locales_strings = {}
local locales_strings = {}
for file_name in io.popen('ls "'..locales_path..'"*.json'):lines() do
local file_name_with_path = utils.split(file_name, "/")
local file_name_without_ext = utils.split(file_name_with_path[#file_name_with_path], ".")[1]
@@ -22,7 +22,7 @@ for file_name in io.popen('ls "'..locales_path..'"*.json'):lines() do
local json_object = json.decode(json_contents)
file:close()
locales_table[file_name_without_ext] = json_object
-- locales_strings[file_name_without_ext] = json_contents
locales_strings[file_name_without_ext] = json_contents
end
-- POW
@@ -104,13 +104,14 @@ end
function _M.view(applet)
-- set the ll language var based off header or default to en-US
-- set the ll and ls language var based off header or default to en-US
local lang = _M.get_first_language(applet)
local ll = locales_table[lang]
if ll == nil then
ll = locales_table[default_lang]
lang = default_lang
end
local ls = locales_strings[lang]
-- set response body and declare status code
local response_body = ""
@@ -198,6 +199,7 @@ function _M.view(applet)
response_body = string.format(
templates.body,
lang,
ls,
ll["Hold on..."],
combined_challenge,
pow_difficulty,

View File

@@ -4,7 +4,7 @@ local _M = {}
_M.body = [[
<!DOCTYPE html>
<html>
<head lang="%s">
<head lang="%s" data-langjson='%s'>
<meta name='viewport' content='width=device-width initial-scale=1'>
<title>%s</title>
<style>
@@ -111,6 +111,7 @@ _M.pow_section = [[
<div id="loader"><div class="b"></div><div class="b"></div><div class="b"></div></div>
</div>
]]
-- alternative, spinner animation
-- .loader{display:inline-block;position:relative;width:80px;height:80px}
-- .loader div{box-sizing:border-box;display:block;position:absolute;width:32px;height:32px;margin:10px;border:5px solid var(--text-color);border-radius:50%%;animation:loader 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;border-color:var(--text-color) transparent transparent transparent}