Skip to content

Commit

Permalink
first stab at localization too which I'll probably end up discarding
Browse files Browse the repository at this point in the history
  • Loading branch information
bromagosa committed Aug 11, 2022
1 parent e132af8 commit 3f36e76
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 17 deletions.
34 changes: 33 additions & 1 deletion locale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ end

-- Localization tools

localizer.sorted_keys = function ()
local keys = {}
local input_file =
io.open('locales/en.lua', 'r')
for line in input_file:lines() do
local key = line:match('^%s*%a.*=')
if key and line:match('",') then
local comment = line:match('", %-%-.*')
table.insert(
keys,
{
key = key:sub(1, -3):match('%a.*'),
comment = comment and comment:sub(6) or nil
}
)
else
if line:match('^%s*%-') then
-- we found a single-line comment
table.insert(
keys,
{
key = nil,
comment = line:match('%-%-.*'):sub(4)
}
)
end
end
end
return keys
end

localizer.update = function ()
-- Takes the EN locale file and rebuilds the currently selected locale, line
-- by line.
Expand All @@ -85,7 +116,8 @@ localizer.update = function ()
os.execute('cp locales/' .. localizer.language .. '.lua /tmp')

local input_file = io.open('locales/en.lua', 'r')
local output_file = io.open('locales/' .. localizer.language .. '.lua', 'w+')
local output_file =
io.open('locales/' .. localizer.language .. '.lua', 'w+')

for line in input_file:lines() do
-- try to extract the key
Expand Down
9 changes: 9 additions & 0 deletions site.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,12 @@ app:get('/user_admin', capture_errors(function (self)
return { redirect_to = self:build_url('index') }
end
end))


-- Tools

--[[
app:get('/localize', capture_errors(function (self)
return { render = 'localize' }
end))
]]--
35 changes: 35 additions & 0 deletions views/localize.etlua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<% local source_lang = params.source_lang or 'en' %>
<h1>Localization tool</h1>
<span>Source: </span>
<script>var url = new URL(location.href);</script>
<select onchange="
url.searchParams.set('source_lang', this.value);
location.href = url.href;
">
<% for k, _ in pairs(locale.locales) do %>
<option
<%= (k == source_lang) and 'selected' or '' %>
value="<%= k %>"><%= k %></option>
<% end %>
</select>
<br>
<br>

<% for _, entry in ipairs(locale.sorted_keys()) do %>
<% if entry.key then %>
<div class="locale-entry">
<h3><%= entry.key %></h3>
<label><%= source_lang %> : <input readonly value="<%= locale.locales[source_lang][entry.key] or '' %>"></input></label>
<% if entry.comment then %> <span><%= entry.comment %></span> <% end %>
<br>
<label for="<%=entry.key%>"><%=locale.language%> : </label><input for="<%= entry.key %>" value="<%= locale.at(entry.key) %>"></input>
</div>
<% elseif entry.comment then %>
<div class="locale-comment">
<p><%= entry.comment %></p>
</div>
<% end %>
<% end %>

<br>
<a class="pure-button" onclick="alert('yes')">Download</a>
38 changes: 22 additions & 16 deletions views/todo
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
TODO
====
TWEAKS
======
[ ] unify self.per_page, self.items_per_page and self.params.items_per_page
[ ] rethink rate limiting for the site, maybe using CRLF protection?

[ ] localization
[ ] user admin
[ ] flagged projects
[ ] titles of curated collections
[ ] errors
[ ] all static pages
[ ] all errors
[ ] all okay messages and titles
LOCALIZATION
============
[ ] user admin
[ ] flagged projects
[ ] titles of curated collections
[ ] errors
[ ] all static pages
[ ] all errors
[ ] all okay messages and titles

[ ] rethink rate limiting for the site, maybe using CRLF protection?
MISSING FUNCTIONALITY
=====================
[ ] edit project notes
[ ] edit project title
[ ] front page management
[ ] upload TOTM image, set TOTM
[ ] [un]feature collection carousel
[ ] follow user

TODO AFTER DEPLOYING
====================
MISSING PAGES
=============
[ ] zombie_admin
[ ] project
[ ] edit notes
[ ] edit title

0 comments on commit 3f36e76

Please sign in to comment.