Add sneak-jumping technique
[minetest_tutorial_subgame.git] / mods / intllib / lib.lua
blobb3f183b95c3b2e52605aae915fe00bef1085468f
2 intllib = intllib or {}
4 local escapes = {
5 ["\\"] = "\\",
6 ["n"] = "\n",
9 local function unescape(s)
10 return s:gsub("([\\]?)\\(.)", function(slash, what)
11 if slash and (slash ~= "") then
12 return "\\"..what
13 else
14 return escapes[what] or what
15 end
16 end)
17 end
19 local function find_eq(s)
20 for slashes, pos in s:gmatch("([\\]*)=()") do
21 if (slashes:len() % 2) == 0 then
22 return pos - 1
23 end
24 end
25 end
27 function intllib.load_strings(filename)
28 local file, err = io.open(filename, "r")
29 if not file then
30 return nil
31 end
32 local strings = {}
33 for line in file:lines() do
34 line = line:trim()
35 if line ~= "" and line:sub(1, 1) ~= "#" then
36 local pos = find_eq(line)
37 if pos then
38 local msgid = unescape(line:sub(1, pos - 1):trim())
39 strings[msgid] = unescape(line:sub(pos + 1):trim())
40 end
41 end
42 end
43 file:close()
44 return strings
45 end