Skip to content

Commit

Permalink
Now supports i18n
Browse files Browse the repository at this point in the history
* Added the rest of the English translation (Resolves #11)
* Bump version
  • Loading branch information
karai17 committed Jan 27, 2016
1 parent 1e12228 commit 3d3f0ad
Show file tree
Hide file tree
Showing 48 changed files with 371 additions and 441 deletions.
8 changes: 8 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
local config = require "lapis.config"
local token = require "secrets.token"
local software = "Lapis-chan"
local version = "1.1.0"
local lua_path = ""
local lua_cpath = ""


config("development", {
software = software,
version = version,
subdomains = false,
site_name = "Lapis-chan",
port = 8080,
Expand All @@ -22,6 +26,8 @@ config("development", {
})

config("production", {
software = software,
version = version,
code_cache = "on",
subdomains = false,
site_name = "Lapis-chan",
Expand All @@ -40,6 +46,8 @@ config("production", {
})

config("test", {
software = software,
version = version,
subdomains = false,
site_name = "Lapis-chan",
port = 80,
Expand Down
20 changes: 4 additions & 16 deletions controllers/admin.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local assert_error = require("lapis.application").assert_error
local assert_valid = require("lapis.validate").assert_valid
local csrf = require "lapis.csrf"
local i18n = require "i18n"
local Announcements = require "models.announcements"
local Boards = require "models.boards"
local Pages = require "models.pages"
Expand All @@ -11,11 +10,6 @@ local Users = require "models.users"

return {
before = function(self)
-- Set localization
i18n.setLocale(self.session.locale or "en")
i18n.loadFile("locale/" .. i18n.getLocale() .. ".lua")
self.i18n = i18n

-- Get data
self.announcements = Announcements:get_announcements()
self.boards = Boards:get_boards()
Expand All @@ -27,7 +21,7 @@ return {
self.board = { theme = "yotsuba_b" }

-- Page title
self.page_title = i18n("admin_panel")
self.page_title = self.i18n("admin_panel")

-- Generate CSRF token
self.csrf_token = csrf.generate_token(self)
Expand Down Expand Up @@ -61,15 +55,9 @@ return {
self.admin_du_url = self.admin_url .. "delete/user/"
end,
on_error = function(self)
self.err = i18n(unpack(self.errors))

if self.err then
self.err = "<p>" .. self.err .. "</p>"
else
self.err = ""
for _, e in ipairs(self.errors) do
self.err = self.err .. "<p>" .. tostring(e) .. "</p>\n"
end
local err = self.i18n(unpack(self.errors))
if err then
self.errors = { err }
end

if not self.session.name then
Expand Down
46 changes: 17 additions & 29 deletions controllers/admin_announcement.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
local assert_error = require("lapis.application").assert_error
local assert_valid = require("lapis.validate").assert_valid
local csrf = require "lapis.csrf"
local i18n = require "i18n"
local Announcements = require "models.announcements"
local Boards = require "models.boards"

return {
before = function(self)
-- Set localization
i18n.setLocale(self.session.locale or "en")
i18n.loadFile("locale/" .. i18n.getLocale() .. ".lua")
self.i18n = i18n

-- Get all announcement data
self.announcements = Announcements:get_announcements()

Expand All @@ -25,7 +19,7 @@ return {
self.csrf_token = csrf.generate_token(self)

-- Page title
self.page_title = i18n("admin_panel")
self.page_title = self.i18n("admin_panel")

-- Verify Authorization
if self.session.name then
Expand All @@ -40,8 +34,8 @@ return {
if self.params.action == "create" then
self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("create_ann")
self.i18n("admin_panel"),
self.i18n("create_ann")
)
self.announcement = self.params
return
Expand All @@ -51,8 +45,8 @@ return {
if self.params.action == "modify" then
self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("modify_ann")
self.i18n("admin_panel"),
self.i18n("modify_ann")
)
self.announcement = Announcements:get_announcement(self.params.ann)
return
Expand All @@ -65,23 +59,17 @@ return {

self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("success")
self.i18n("admin_panel"),
self.i18n("success")
)
self.action = i18n("deleted_ann", { ann.text })
self.action = self.i18n("deleted_ann", { ann.text })
return
end
end,
on_error = function(self)
self.err = i18n(unpack(self.errors))

if self.err then
self.err = "<p>" .. self.err .. "</p>"
else
self.err = ""
for _, e in ipairs(self.errors) do
self.err = self.err .. "<p>" .. tostring(e) .. "</p>\n"
end
local err = self.i18n(unpack(self.errors))
if err then
self.errors = { err }
end

if not self.session.name then
Expand Down Expand Up @@ -120,10 +108,10 @@ return {

self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("success")
self.i18n("admin_panel"),
self.i18n("success")
)
self.action = i18n("created_ann", { ann.text })
self.action = self.i18n("created_ann", { ann.text })

return { render = "admin.success" }
end
Expand Down Expand Up @@ -154,10 +142,10 @@ return {

self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("success")
self.i18n("admin_panel"),
self.i18n("success")
)
self.action = i18n("modified_ann", { ann.text })
self.action = self.i18n("modified_ann", { ann.text })

return { render = "admin.success" }
end
Expand Down
46 changes: 17 additions & 29 deletions controllers/admin_board.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
local assert_error = require("lapis.application").assert_error
local assert_valid = require("lapis.validate").assert_valid
local csrf = require "lapis.csrf"
local i18n = require "i18n"
local lfs = require "lfs"
local Boards = require "models.boards"
local Posts = require "models.posts"
local Threads = require "models.threads"

return {
before = function(self)
-- Set localization
i18n.setLocale(self.session.locale or "en")
i18n.loadFile("locale/" .. i18n.getLocale() .. ".lua")
self.i18n = i18n

-- Get all board data
self.boards = Boards:get_boards()

Expand All @@ -24,7 +18,7 @@ return {
self.csrf_token = csrf.generate_token(self)

-- Page title
self.page_title = i18n("admin_panel")
self.page_title = self.i18n("admin_panel")

-- Verify Authorization
if self.session.name then
Expand Down Expand Up @@ -52,8 +46,8 @@ return {
if self.params.action == "create" then
self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("create_board")
self.i18n("admin_panel"),
self.i18n("create_board")
)
self.board = self.params

Expand All @@ -68,8 +62,8 @@ return {
if self.params.action == "modify" then
self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("modify_board")
self.i18n("admin_panel"),
self.i18n("modify_board")
)
self.board = Boards:get_board(self.params.board)
self.board.archive_time = self.board.archive_time / 24 / 60 / 60
Expand All @@ -85,23 +79,17 @@ return {

self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("success")
self.i18n("admin_panel"),
self.i18n("success")
)
self.action = i18n("deleted_board", { board.short_name, board.name })
self.action = self.i18n("deleted_board", { board.short_name, board.name })
return
end
end,
on_error = function(self)
self.err = i18n(unpack(self.errors))

if self.err then
self.err = "<p>" .. self.err .. "</p>"
else
self.err = ""
for _, e in ipairs(self.errors) do
self.err = self.err .. "<p>" .. tostring(e) .. "</p>\n"
end
local err = self.i18n(unpack(self.errors))
if err then
self.errors = { err }
end

if not self.session.name then
Expand Down Expand Up @@ -167,10 +155,10 @@ return {

self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("success")
self.i18n("admin_panel"),
self.i18n("success")
)
self.action = i18n("created_board", { board.short_name, board.name })
self.action = self.i18n("created_board", { board.short_name, board.name })

return { render = "admin.success" }
end
Expand Down Expand Up @@ -208,10 +196,10 @@ return {

self.page_title = string.format(
"%s - %s",
i18n("admin_panel"),
i18n("success")
self.i18n("admin_panel"),
self.i18n("success")
)
self.action = i18n("modified_board", { board.short_name, board.name })
self.action = self.i18n("modified_board", { board.short_name, board.name })

return { render = "admin.success" }
end
Expand Down
Loading

0 comments on commit 3d3f0ad

Please sign in to comment.