[vlc-devel] commit: Experimental lua gettext support. (Antoine Cellerier )

git version control git at videolan.org
Sun Dec 27 23:19:46 CET 2009


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sun Dec 27 23:01:45 2009 +0100| [16cb266cb6f46c62213d0a5723b21a11110267b9] | committer: Antoine Cellerier 

Experimental lua gettext support.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=16cb266cb6f46c62213d0a5723b21a11110267b9
---

 modules/misc/lua/Modules.am     |    1 +
 modules/misc/lua/intf.c         |    1 +
 modules/misc/lua/libs.h         |    1 +
 modules/misc/lua/libs/gettext.c |   74 +++++++++++++++++++++++++++++++++++++++
 share/lua/intf/rc.lua           |    5 ++-
 5 files changed, 81 insertions(+), 1 deletions(-)

diff --git a/modules/misc/lua/Modules.am b/modules/misc/lua/Modules.am
index 0b6b38b..22aa829 100644
--- a/modules/misc/lua/Modules.am
+++ b/modules/misc/lua/Modules.am
@@ -7,6 +7,7 @@ SOURCES_lua = \
 	libs.h \
 	libs/acl.c \
 	libs/configuration.c \
+	libs/gettext.c \
 	libs/httpd.c \
 	libs/input.c \
 	libs/input.h \
diff --git a/modules/misc/lua/intf.c b/modules/misc/lua/intf.c
index 538faf1..5d73547 100644
--- a/modules/misc/lua/intf.c
+++ b/modules/misc/lua/intf.c
@@ -211,6 +211,7 @@ int Open_LuaIntf( vlc_object_t *p_this )
     luaopen_video( L );
     luaopen_vlm( L );
     luaopen_volume( L );
+    luaopen_gettext( L );
 
     /* clean up */
     lua_pop( L, 1 );
diff --git a/modules/misc/lua/libs.h b/modules/misc/lua/libs.h
index 689025e..7bd8701 100644
--- a/modules/misc/lua/libs.h
+++ b/modules/misc/lua/libs.h
@@ -42,5 +42,6 @@ void luaopen_variables( lua_State * );
 void luaopen_video( lua_State * );
 void luaopen_vlm( lua_State * );
 void luaopen_volume( lua_State * );
+void luaopen_gettext( lua_State * );
 
 #endif
diff --git a/modules/misc/lua/libs/gettext.c b/modules/misc/lua/libs/gettext.c
new file mode 100644
index 0000000..f51f830
--- /dev/null
+++ b/modules/misc/lua/libs/gettext.c
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * gettext.c
+ *****************************************************************************
+ * Copyright (C) 2009 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Antoine Cellerier <dionoea at videolan tod org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_fixups.h>
+
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+#include <lualib.h>     /* Lua libs */
+
+#include "../vlc.h"
+#include "../libs.h"
+
+/*****************************************************************************
+ * Libvlc gettext support
+ *****************************************************************************/
+static int vlclua_gettext( lua_State *L )
+{
+    lua_pushstring( L, _( luaL_checkstring( L, 1 ) ) );
+    return 1;
+}
+
+static int vlclua_gettext_noop( lua_State *L )
+{
+    (void)L;
+    return 1;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static const luaL_Reg vlclua_gettext_reg[] = {
+    { "_", vlclua_gettext },
+    { "N_", vlclua_gettext_noop },
+
+    { NULL, NULL }
+};
+
+void luaopen_gettext( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_gettext_reg );
+    lua_setfield( L, -2, "gettext" );
+}
diff --git a/share/lua/intf/rc.lua b/share/lua/intf/rc.lua
index c02d0a9..af78f4c 100644
--- a/share/lua/intf/rc.lua
+++ b/share/lua/intf/rc.lua
@@ -61,12 +61,15 @@ skip2 = function(foo) return skip(skip(foo)) end
 setarg = common.setarg
 strip = common.strip
 
+_ = vlc.gettext._
+N_ = vlc.gettext.N_
+
 --[[ Setup default environement ]]
 env = { prompt = "> ";
         width = 70;
         autocompletion = 1;
         autoalias = 1;
-        welcome = "Remote control interface initialized. Type `help' for help.";
+        welcome = _("Remote control interface initialized. Type `help' for help.");
         flatplaylist = 0;
       }
 




More information about the vlc-devel mailing list