mirror of
https://github.com/minetest-mods/intllib.git
synced 2025-01-09 01:20:25 +01:00
Localize load_strings
This commit is contained in:
parent
934ca0492c
commit
4be14170e7
2
init.lua
2
init.lua
@ -26,7 +26,7 @@ function intllib.Getter(modname)
|
|||||||
local modpath = minetest.get_modpath(modname)
|
local modpath = minetest.get_modpath(modname)
|
||||||
if modpath then
|
if modpath then
|
||||||
local filename = modpath.."/locale/"..LANG..".txt"
|
local filename = modpath.."/locale/"..LANG..".txt"
|
||||||
local msgstr = load_strings(filename)
|
local msgstr = intllib.load_strings(filename)
|
||||||
if msgstr then
|
if msgstr then
|
||||||
intllib.getters[modname] = function (s)
|
intllib.getters[modname] = function (s)
|
||||||
if msgstr[s] and msgstr[s] ~= "" then
|
if msgstr[s] and msgstr[s] ~= "" then
|
||||||
|
4
lib.lua
4
lib.lua
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
intllib = intllib or {}
|
||||||
|
|
||||||
local escapes = {
|
local escapes = {
|
||||||
["\\"] = "\\",
|
["\\"] = "\\",
|
||||||
["n"] = "\n",
|
["n"] = "\n",
|
||||||
@ -22,7 +24,7 @@ local function find_eq(s)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function load_strings(filename)
|
function intllib.load_strings(filename)
|
||||||
local file, err = io.open(filename, "r")
|
local file, err = io.open(filename, "r")
|
||||||
if not file then
|
if not file then
|
||||||
return nil
|
return nil
|
||||||
|
@ -102,11 +102,11 @@ local function printf(fmt, ...)
|
|||||||
io.stdout:write(fmt:format(...))
|
io.stdout:write(fmt:format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
local template_msgs = load_strings(template)
|
local template_msgs = intllib.load_strings(template)
|
||||||
|
|
||||||
for _, file in ipairs(catalogs) do
|
for _, file in ipairs(catalogs) do
|
||||||
print("Processing: "..file)
|
print("Processing: "..file)
|
||||||
local catalog_msgs = load_strings(file)
|
local catalog_msgs = intllib.load_strings(file)
|
||||||
local dirty_lines = { }
|
local dirty_lines = { }
|
||||||
if catalog_msgs then
|
if catalog_msgs then
|
||||||
-- Add new entries from template.
|
-- Add new entries from template.
|
||||||
|
Loading…
Reference in New Issue
Block a user