glade下多语言文件如何生成?

来源:互联网 发布:audition mac 编辑:程序博客网 时间:2024/06/08 05:21
Autoconf的多国语言支持

参考:http://cslcy.blogchina.com/cslcy/4475104.html
http://blog.csdn.net/comcat/archive/2007/04/11/1560161.aspx

autogen.sh :

echo "Running libtoolize --force --copy ..."
libtoolize --force --copy
echo "Running glib-gettextize --force --copy ..."
glib-gettextize --force --copy
echo "Running intltoolize --force --copy ..."
intltoolize --force --copy

echo "Running aclocal ..."
aclocal
echo "Running autoheader ..."
autoheader
echo "Running autoconf ..."
autoconf
echo "Running automake --add-missing --copy ..."
automake --add-missing --copy
echo "Running ./configure"
./configure

0. 增加多国语言的命令:

libtoolize --force --copy
glib-gettextize --force --copy
intltoolize --force --copy
这些是有先后顺序的。

libtool:libtool  是一组shell 脚本,它运行于Unix 和Unix-like系统上,为程序员提供统一的、可移植的、简化了的,创建、使用共享库的界面。这样程序员就可以便捷地编制在各种Unix平台上都可以运行的动态连接库了。 

gettext:gettext提供了编程界面、实用工具,它帮助程序员编写支持多语言的应用程序。
 

运行上面的3条命令需要在configure.in中加入:
AC_PROG_LIBTOOL
IT_PROG_INTLTOOL

然后运行aclocal,autoheader,autoconf,automake,

Makefile.am文件中的加上po
SUBDIRS = docs glade pixmaps po src 

最后会提示
sed: can't read ./po/POTFILES.in: No such file or directory,
这时候再在configure.in中的AC_CONFIG_FILES加入
po/Makefile.in,

#native language support
GETTEXT_PACKAGE=AC_PACKAGE_NAME
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name])
AM_GLIB_GNU_GETTEXT

最后在po目录下增加个空的POTFILES.in
重新运行autogen.sh

其他的参见下面的文字,这是以前写的,也许更仔细点,我没有好好整理


1.在configure.in文件中增加:

IT_PROG_INTLTOOL([0.35.0])
AM_PROG_LIBTOOL


2. configure.in中添加

# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MMAP
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([memset munmap select setlocale strcasecmp strerror])

AC_CONFIG_FILES([docs/Makefile
                glade/Makefile
pixmaps/Makefile
po/Makefile.in //在这里添加这个,要不然配置不了,注意是Makefile.in而不是Makefile
                src/Makefile
Makefile])
AC_OUTPUT


3. 执行autogen.sh

echo "Running libtoolize --force --copy ..."
libtoolize --force --copy
echo "Running glib-gettextize --force --copy ..."
glib-gettextize --force --copy
echo "Running intltoolize --force --copy ..."
intltoolize --force --copy

echo "Running aclocal ..."
aclocal
echo "Running autoheader ..."
autoheader
echo "Running autoconf ..."
autoconf
echo "Running automake --add-missing --copy ..."
automake --add-missing --copy
echo "Running ./configure"
./configure

4. Makefile.am文件中的加上po
SUBDIRS = docs glade pixmaps po src


5。切换到po目录

创建POTFILES.in和LINGUAS文件,内容分别为

(POTFILES.in)
# List of source files containing translatable strings.
[encoding: UTF-8]

glade/wbuscanner.glade
src/main.c

(LINGUAS)
# please keep this list sorted alphabetically
#
zh_CN


make update-po
mv wbuscanner.pot zh_CN.po
然后将zh_CN.po中需要翻译的内容进行翻译
make update-po
make

PS:记得在这里touch个ChangeLog,要不然make dist的时候会出错


多国语言文件将会被安装到  /usr/local/share/locale/zh_CN/LC_MESSAGES/wbuscanner.mo


6.main.c


#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif

/*
* Standard gettext macros.
*/
#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define textdomain(String) (String)
#  define gettext(String) (String)
#  define dgettext(Domain,Message) (Message)
#  define dcgettext(Domain,Message,Type) (Message)
#  define bindtextdomain(Domain,Directory) (Domain)
#  define _(String) (String)
#  define N_(String) (String)
#endif


然后在main()中:
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif

在gtk_init之后加入就可以主动切换到中文模式
//切换到中文模式
//setlocale(LC_ALL,"zh_CN.UTF-8");
7。需要翻译的字符串写成 _("hello")


最后记得在顶层MAKEFILE.am上加上

EXTRA_DIST +=
intltool-extract.in
intltool-merge.in
intltool-update.in

要不然make dist后再解压编译的话就编译不了了

记得在翻译文件后在.po种更改
"Content-Type: text/plain; charset=CHARSET "为
"Content-Type: text/plain; charset=UTF-8 "
 
来源:开发者参考网(devtopic.com) 类别:Linux/Unix
原创粉丝点击