/usr/share/lua/5.1/say/init.lua is in lua-say 1.3-1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | local unpack = table.unpack or unpack
local registry = { }
local current_namespace
local fallback_namespace
local s = {
_COPYRIGHT = "Copyright (c) 2012 Olivine Labs, LLC.",
_DESCRIPTION = "A simple string key/value store for i18n or any other case where you want namespaced strings.",
_VERSION = "Say 1.2",
set_namespace = function(self, namespace)
current_namespace = namespace
if not registry[current_namespace] then
registry[current_namespace] = {}
end
end,
set_fallback = function(self, namespace)
fallback_namespace = namespace
if not registry[fallback_namespace] then
registry[fallback_namespace] = {}
end
end,
set = function(self, key, value)
registry[current_namespace][key] = value
end
}
local __meta = {
__call = function(self, key, vars)
vars = vars or {}
local str = registry[current_namespace][key] or registry[fallback_namespace][key]
if str == nil then
return nil
end
str = tostring(str)
local strings = {}
for i,v in ipairs(vars) do
table.insert(strings, tostring(v))
end
return #strings > 0 and str:format(unpack(strings)) or str
end,
__index = function(self, key)
return registry[key]
end
}
s:set_fallback('en')
s:set_namespace('en')
s._registry = registry
return setmetatable(s, __meta)
|