summaryrefslogtreecommitdiff
path: root/src/scripts/elua/core/gettext.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/elua/core/gettext.lua')
-rw-r--r--src/scripts/elua/core/gettext.lua26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/scripts/elua/core/gettext.lua b/src/scripts/elua/core/gettext.lua
index 96af7d3..3659b4e 100644
--- a/src/scripts/elua/core/gettext.lua
+++ b/src/scripts/elua/core/gettext.lua
@@ -1,7 +1,5 @@
1-- elua gettext module 1-- elua gettext module
2 2
3local ffi = require("ffi")
4
5local M = {} 3local M = {}
6 4
7local gettext = ... 5local gettext = ...
@@ -10,12 +8,6 @@ local bind_textdomain = gettext.bind_textdomain
10local dgettext = gettext.dgettext 8local dgettext = gettext.dgettext
11local dngettext = gettext.dngettext 9local dngettext = gettext.dngettext
12 10
13if dgettext then
14 dgettext = ffi.cast("char *(*)(const char*, const char*)", dgettext)
15 dngettext = ffi.cast("char *(*)(const char*, const char*, const char*, "
16 .. "unsigned long)", dngettext)
17end
18
19local domains = {} 11local domains = {}
20 12
21local default_domain 13local default_domain
@@ -39,7 +31,6 @@ M.set_default_domain = function(dom)
39 return true 31 return true
40end 32end
41 33
42local cast, ffistr = ffi.cast, ffi.string
43local floor = math.floor 34local floor = math.floor
44local type = type 35local type = type
45 36
@@ -50,12 +41,11 @@ if dgettext then
50 dom = default_domain 41 dom = default_domain
51 end 42 end
52 if not domains[dom] or not msgid then return msgid end 43 if not domains[dom] or not msgid then return msgid end
53 local cmsgid = cast("const char*", msgid) 44 local lmsgid = dgettext(dom, msgid)
54 local lmsgid = dgettext(dom, cmsgid) 45 if msgid == lmsgid then
55 if cmsgid == lmsgid then
56 return msgid 46 return msgid
57 end 47 end
58 return ffistr(lmsgid) 48 return lmsgid
59 end 49 end
60 M.dgettext = M.gettext 50 M.dgettext = M.gettext
61 M.ngettext = function(dom, msgid, plmsgid, n) 51 M.ngettext = function(dom, msgid, plmsgid, n)
@@ -69,15 +59,13 @@ if dgettext then
69 if not msgid or n == 1 then return msgid end 59 if not msgid or n == 1 then return msgid end
70 return plmsgid 60 return plmsgid
71 end 61 end
72 local cmsgid = cast("const char*", msgid) 62 local lmsgid = dngettext(dom, msgid, plmsgid, n)
73 local cplmsgid = cast("const char*", plmsgid)
74 local lmsgid = dngettext(dom, cmsgid, cplmsgid, n)
75 if n == 1 then 63 if n == 1 then
76 if cmsgid == lmsgid then return msgid end 64 if msgid == lmsgid then return msgid end
77 else 65 else
78 if cplmsgid == lmsgid then return plmsgid end 66 if plmsgid == lmsgid then return plmsgid end
79 end 67 end
80 return ffistr(lmsgid) 68 return lmsgid
81 end 69 end
82 M.dngettext = M.ngettext 70 M.dngettext = M.ngettext
83else 71else