elua: support for default domain in gettext module
authorDaniel Kolesa <quaker66@gmail.com>
Mon, 28 Apr 2014 13:41:58 +0000 (14:41 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:49 +0000 (15:48 +0100)
src/bin/elua/core/gettext.lua

index 6192613..065cefd 100644 (file)
@@ -15,6 +15,8 @@ end
 
 local domains = {}
 
+local default_domain
+
 M.register_domain = function(dom, dir)
     local d, err = bind_textdomain(dom, dir)
     if not d then
@@ -28,10 +30,20 @@ M.get_domain = function(dom)
     return domains[dom]
 end
 
+M.set_default_domain = function(dom)
+    if not domains[dom] then return false end
+    default_domain = dom
+    return true
+end
+
 local cast, ffistr = ffi.cast, ffi.string
 
 if dgettext then
     M.gettext = function(dom, msgid)
+        if not msgid then
+            msgid = dom
+            dom   = default_domain
+        end
         if not domains[dom] or not msgid then return msgid end
         local cmsgid = cast("const char*", msgid)
         local lmsgid = dgettext(dom, cmsgid)