Mercurial Hosting > luan
annotate website/src/lib/Shared.luan @ 1933:7d5dabe8eab8
translation work
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 02 May 2025 20:03:51 -0600 |
| parents | 047e4dde22b4 |
| children | 5b5d88cf13b5 |
| rev | line source |
|---|---|
| 1651 | 1 local Luan = require "luan:Luan.luan" |
| 2 local error = Luan.error | |
| 3 local ipairs = Luan.ipairs or error() | |
| 1653 | 4 local pairs = Luan.pairs or error() |
| 1929 | 5 local Time = require "luan:Time.luan" |
| 6 local Http = require "luan:http/Http.luan" | |
| 1933 | 7 local Translator = require "luan:gpt/Translator.luan" |
| 1929 | 8 local Site_translator = require "luan:gpt/Site_translator.luan" |
| 9 local get_lang = Site_translator.get_lang or error() | |
| 10 local languages = Site_translator.languages or error() | |
| 11 local Logging = require "luan:logging/Logging.luan" | |
| 12 local logger = Logging.logger "Shared" | |
| 1651 | 13 |
| 14 | |
| 15 local Shared = {} | |
| 16 | |
| 1933 | 17 function Translator.prompt(html,language) |
| 18 %> | |
| 19 Please translate the HTML below delimited by triple quotes from English to <%=language%>. | |
| 20 | |
| 21 Note that the content is related to computer programming, so keep that in mind while translating. The English word "library" refers to a programming library, not a place to borrow books, so translate to the word in the target language that means programming library. So for Spanish, use "librerÃa". | |
| 22 | |
| 23 Don't translate file names. | |
| 24 | |
| 25 Don't translate the content of <code> tags. | |
| 26 | |
| 27 """ | |
| 28 <%=html%> | |
| 29 """ | |
| 30 <% | |
| 31 end | |
| 32 | |
| 1929 | 33 Http.not_found_handler = Site_translator.not_found_handler or error() |
| 34 | |
| 35 local started = Time.now() | |
| 1932 | 36 |
| 37 local function reactionary_url() | |
| 38 local url = "https://www.reactionary.software" | |
| 39 local lang = get_lang() | |
| 40 if lang ~= "en" then | |
| 41 url = url.."/"..lang | |
| 42 end | |
| 43 return url | |
| 44 end | |
| 45 Shared.reactionary_url = reactionary_url | |
| 1929 | 46 |
| 1651 | 47 function Shared.head() |
| 48 %> | |
| 49 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 50 <style> | |
| 1929 | 51 @import "/site.css?s=<%=started%>"; |
| 1651 | 52 </style> |
| 1929 | 53 <script src="/site.js?s=<%=started%>"></script> |
| 1651 | 54 <% |
| 55 end | |
| 56 | |
| 1652 | 57 local function header(crumbs) |
| 1929 | 58 local lang = get_lang() |
| 59 local home | |
| 60 if lang == "en" then | |
| 61 home = "/" | |
| 62 else | |
| 63 home = "/"..lang.."/" | |
| 64 end | |
| 1651 | 65 %> |
| 66 <div header> | |
| 1747 | 67 <span breadcrumbs> |
| 1929 | 68 <a href="<%=home%>">Luan</a> |
| 1651 | 69 <% for _, crumb in ipairs(crumbs or {}) do %> |
| 1747 | 70 / <%=crumb%> |
| 1651 | 71 <% end %> |
| 1929 | 72 - <select onchange="setLanguage(value)"> |
| 73 <% for code, name in pairs(languages) do | |
| 74 local selected = code==lang and "selected" or "" | |
| 75 %> | |
| 76 <option value="<%=code%>" <%=selected%> ><%=name%></option> | |
| 77 <% end %> | |
| 78 </select> | |
| 1747 | 79 </span> |
| 1932 | 80 <span><a href="<%=reactionary_url()%>/">reactionary software</a> by <a href="https://linkmy.style/fschmidt">fschmidt</a></span> |
| 1651 | 81 </div> |
| 82 <% | |
| 83 end | |
| 1652 | 84 Shared.header = header |
| 85 | |
| 86 function Shared.docs_header() | |
| 1929 | 87 header{[[<a href="docs.html">Documentation</a>]]} |
| 1652 | 88 end |
| 1651 | 89 |
| 1653 | 90 local function show_toc(content) |
| 91 %> | |
| 92 <ul> | |
| 93 <% | |
| 94 for id, info in pairs(content) do | |
| 95 %> | |
|
1812
f44dcb3fedf7
docs - add code block
Franklin Schmidt <fschmidt@gmail.com>
parents:
1784
diff
changeset
|
96 <li c_<%=id%> ><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a> |
| 1653 | 97 <% |
| 98 local subs = info.subs | |
| 99 if subs ~= nil then | |
| 100 show_toc(subs) | |
| 101 end | |
| 102 %> | |
| 103 </li> | |
| 104 <% | |
| 105 end | |
| 106 %> | |
| 107 </ul> | |
| 108 <% | |
| 109 end | |
| 110 Shared.show_toc = show_toc | |
| 111 | |
| 112 local function nothing() end | |
| 113 | |
| 1929 | 114 local show_content, show_content_info |
| 115 | |
| 116 function show_content_info(id,info,h) | |
| 1653 | 117 %> |
| 118 <div heading> | |
| 119 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>> | |
| 120 <a href="#c_<%=id%>">contents</a> | |
| 121 </div> | |
| 122 <% | |
| 123 (info.content or nothing)() | |
| 124 local subs = info.subs | |
| 125 if subs ~= nil then | |
| 126 show_content(subs,h+1) | |
| 127 end | |
| 1929 | 128 end |
| 129 Shared.show_content_info = show_content_info | |
| 130 | |
| 131 function show_content(content,h) | |
| 132 for id, info in pairs(content) do | |
| 133 show_content_info(id,info,h) | |
| 1653 | 134 end |
| 135 end | |
| 136 Shared.show_content = show_content | |
| 137 | |
| 1651 | 138 return Shared |
