Skip to content

Commit

Permalink
style: Reformat Lua with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 29, 2024
1 parent fa6786e commit deb02fb
Show file tree
Hide file tree
Showing 11 changed files with 1,020 additions and 951 deletions.
6 changes: 3 additions & 3 deletions .busted
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return {
default = {
lpath = "./?/init.lua"
}
default = {
lpath = "./?/init.lua",
},
}
18 changes: 9 additions & 9 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
std = "max"
include_files = {
"**/*.lua",
"**/*.rockspec",
".busted",
".luacheckrc"
"**/*.lua",
"**/*.rockspec",
".busted",
".luacheckrc",
}
exclude_files = {
".install",
".lua",
".luarocks",
"lua_modules"
".install",
".lua",
".luarocks",
"lua_modules",
}
files["spec"] = {
std = "+busted"
std = "+busted",
}
max_line_length = false
14 changes: 7 additions & 7 deletions fluent-dev-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "dev-0"

source = {
url = "git+https://github.com/alerque/fluent-lua.git",
branch = "master"
branch = "master",
}

description = {
Expand All @@ -15,22 +15,22 @@ description = {
homepage = "https://github.com/alerque/fluent-lua",
issues_url = "https://github.com/alerque/fluent-lua/issues",
maintainer = "Caleb Maclennan <caleb@alerque.com>",
labels = { "i18n" }
labels = { "i18n" },
}

dependencies = {
"lua >= 5.1",
"cldr",
"luaepnf",
"penlight"
"penlight",
}

test_dependencies = {
"busted",
"busted",
}

test = {
type = "busted",
type = "busted",
}

build = {
Expand All @@ -40,6 +40,6 @@ build = {
["fluent.messages"] = "fluent/messages.lua",
["fluent.parser"] = "fluent/parser.lua",
["fluent.resource"] = "fluent/resource.lua",
["fluent.syntax"] = "fluent/syntax.lua"
}
["fluent.syntax"] = "fluent/syntax.lua",
},
}
98 changes: 51 additions & 47 deletions fluent/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,77 +10,81 @@ local FluentResource = require("fluent.resource")
local FluentBundle = class()

function FluentBundle:_init (locale)
self.locales = {}
self:set_locale(locale)
-- Work around Penlight #307
-- self:catch(self.get_message)
self:_patch_init()
return self
self.locales = {}
self:set_locale(locale)
-- Work around Penlight #307
-- self:catch(self.get_message)
self:_patch_init()
return self
end

function FluentBundle:_patch_init ()
if type(rawget(getmetatable(self), "__index")) ~= "function" then
self:catch(function(_, identifier) return self:get_message(identifier) end)
end
if type(rawget(getmetatable(self), "__index")) ~= "function" then
self:catch(function (_, identifier)
return self:get_message(identifier)
end)
end
end

function FluentBundle:set_locale (locale)
self.locale = CLDR.locales[locale] and locale or "und"
if not self.locales[self.locale] then
self.locales[self.locale] = FluentResource()
end
return self:get_locale()
self.locale = CLDR.locales[locale] and locale or "und"
if not self.locales[self.locale] then
self.locales[self.locale] = FluentResource()
end
return self:get_locale()
end

function FluentBundle:get_locale ()
return self.locale
return self.locale
end

function FluentBundle:get_resource (locale)
local locales = self.locales
local resource = locales[locale or self:get_locale()]
resource._patch_init(resource)
return resource
local locales = self.locales
local resource = locales[locale or self:get_locale()]
resource._patch_init(resource)
return resource
end

function FluentBundle:get_message (identifier)
local resource = self:get_resource()
-- TODO iterate over fallback locales if not found in current one
return resource:get_message(identifier)
local resource = self:get_resource()
-- TODO iterate over fallback locales if not found in current one
return resource:get_message(identifier)
end

function FluentBundle:add_messages (input, locale)
-- Work around Penlight #307
-- self:_patch_init()
locale = locale or self:get_locale()
local syntax = FluentSyntax()
local messages =
type(input) == "string"
and syntax:parsestring(input)
or tablex.reduce('+', tablex.imap(function (v)
return syntax:parsestring(v)
end, input))
local resource = self:get_resource(locale)
return resource + messages
-- Work around Penlight #307
-- self:_patch_init()
locale = locale or self:get_locale()
local syntax = FluentSyntax()
local messages = type(input) == "string" and syntax:parsestring(input)
or tablex.reduce(
"+",
tablex.imap(function (v)
return syntax:parsestring(v)
end, input)
)
local resource = self:get_resource(locale)
return resource + messages
end

function FluentBundle:load_file (fname, locale)
locale = locale or self:get_locale()
local syntax = FluentSyntax()
local messages =
type(fname) == "string"
and syntax:parsefile(fname)
or tablex.reduce('+', tablex.imap(function (v)
return syntax:parsefile(v)
end, fname))
local resource = self:get_resource(locale)
return resource + messages
locale = locale or self:get_locale()
local syntax = FluentSyntax()
local messages = type(fname) == "string" and syntax:parsefile(fname)
or tablex.reduce(
"+",
tablex.imap(function (v)
return syntax:parsefile(v)
end, fname)
)
local resource = self:get_resource(locale)
return resource + messages
end

function FluentBundle:format (identifier, parameters)
local resource = self:get_resource()
local message = resource:get_message(identifier)
return message:format(parameters)
local resource = self:get_resource()
local message = resource:get_message(identifier)
return message:format(parameters)
end

return FluentBundle
Loading

0 comments on commit deb02fb

Please sign in to comment.