分类: LINUX
2006-08-31 21:33:17
xiaosuo@gentux skeleton $ mkdir project1 xiaosuo@gentux skeleton $ cd project1 xiaosuo@gentux project1 $ mkdir src xiaosuo@gentux project1 $ cd src |
#ifndef _I18N_H_ #define _I18N_H_ #ifdef HAVE_CONFIG_H #include #endif #ifdef ENABLE_NLS #include #define _(String) gettext(String) #ifdef gettext_noop #define N_(String) gettext_noop(String) #else #define N_(String) (String) #endif #else /* NLS is disabled */ #define _(String) (String) #define N_(String) (String) #define textdomain(String) (String) #define gettext(String) (String) #define dgettext(Domain,String) (String) #define dcgettext(Domain,String,Type) (String) #define bindtextdomain(Domain,Directory) (Domain) #define bind_textdomain_codeset(Domain,Codeset) (Codeset) #endif /* ENABLE_NLS */ #endif /* _I18N_H_ */ |
#include #include #ifdef HAVE_CONFIG_H #include #endif #ifdef ENABLE_NLS #include #endif #include "i18n.h" int main(int argc, char *argv[]) { #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, getenv("LC_MESSAGES")); textdomain(GETTEXT_PACKAGE); setlocale(LC_ALL, ""); #endif printf(_("Hello, world!\n")); return 0; } |
bin_PROGRAMS = project1 project1_SOURCES = \ i18n.h \ project1.c |
SUBDIRS = src |
AC_INIT(configure.in) AM_INIT_AUTOMAKE(project1, 0.0.1) AM_CONFIG_HEADER(config.h) dnl Checks for compiler and system libraries AC_GNU_SOURCE AC_PROG_CC AC_HEADER_STDC AC_ISC_POSIX AM_PROG_CC_STDC AM_PROG_LIBTOOL AC_PROG_INSTALL dnl Define the default CFLAGS CFLAGS="-Wall" AC_SUBST(CFLAGS) dnl Checks for i18n support GETTEXT_PACKAGE=project1 AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Package name for gettext.]) dnl Languages which your application supports ALL_LINGUAS="zh_CN" AC_SUBST(ALL_LINGUAS) AM_GNU_GETTEXT AM_GNU_GETTEXT_VERSION([0.15]) dnl Set PACKAGE_LOCALE_DIR in config.h. if test "x${prefix}" = "xNONE"; then AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${ac_default_prefix}/${DATADIRNAME}/locale", [The package locale directory.]) else AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${prefix}/${DATADIRNAME}/locale", [The package locale directory.]) fi dnl Set PACKAGE SOURCE DIR in config.h. packagesrcdir=`cd $srcdir && pwd` dnl Set PACKAGE PREFIX if test "x${prefix}" = "xNONE"; then packageprefix=${ac_default_prefix} packageetcprefix=/ else packageprefix=${prefix} packageetcprefix=${prefix} fi packagedatadir=share packagedocdir=doc/${PACKAGE} packagepixmapsdir=share/pixmaps/${PACKAGE} packagehelpdir=share/help/${PACKAGE} packagemenudir=share/apps/${PACKAGE} packagemandir=share/man/ packageetcdir=etc/${PACKAGE} dnl Subst PACKAGE_DATA_DIR. NO_PREFIX_PACKAGE_DATA_DIR="${packagedatadir}" AC_SUBST(NO_PREFIX_PACKAGE_DATA_DIR) PACKAGE_DATA_DIR="${packageprefix}/${packagedatadir}" AC_SUBST(PACKAGE_DATA_DIR) dnl Subst PACKAGE_DOC_DIR. NO_PREFIX_PACKAGE_DOC_DIR="${packagedocdir}" AC_SUBST(NO_PREFIX_PACKAGE_DOC_DIR) PACKAGE_DOC_DIR="${packageprefix}/${packagedocdir}" AC_SUBST(PACKAGE_DOC_DIR) dnl Subst PACKAGE_PIXMAPS_DIR. NO_PREFIX_PACKAGE_PIXMAPS_DIR="${packagepixmapsdir}" AC_SUBST(NO_PREFIX_PACKAGE_PIXMAPS_DIR) PACKAGE_PIXMAPS_DIR="${packageprefix}/${packagepixmapsdir}" AC_SUBST(PACKAGE_PIXMAPS_DIR) dnl Subst PACKAGE_HELP_DIR. NO_PREFIX_PACKAGE_HELP_DIR="${packagehelpdir}" AC_SUBST(NO_PREFIX_PACKAGE_HELP_DIR) PACKAGE_HELP_DIR="${packageprefix}/${packagehelpdir}" AC_SUBST(PACKAGE_HELP_DIR) dnl Subst PACKAGE_MENU_DIR. NO_PREFIX_PACKAGE_MENU_DIR="${packagemenudir}" AC_SUBST(NO_PREFIX_PACKAGE_MENU_DIR) PACKAGE_MENU_DIR="${packageprefix}/${packagemenudir}" AC_SUBST(PACKAGE_MENU_DIR) dnl Subset PACKAGE_MAN_DIR NO_PREFIX_PACKAGE_MAN_DIR="${packagemandir}" AC_SUBST(NO_PREFIX_PACKAGE_MAN_DIR) PACKAGE_MAN_DIR="${packageprefix}/${packagemandir}" AC_SUBST(PACKAGE_MAN_DIR) dnl Subset PACKAGE_ETC_DIR NO_PREFIX_PACKAGE_ETC_DIR="${packageetcdir}" AC_SUBST(NO_PREFIX_PACKAGE_ETC_DIR) PACKAGE_ETC_DIR="${packageetcprefix}/${packageetcdir}" AC_SUBST(PACKAGE_ETC_DIR) AC_DEFINE_UNQUOTED([PACKAGE_DATA_DIR], "${packageprefix}/${packagedatadir}", [The data directory.]) AC_DEFINE_UNQUOTED(PACKAGE_DOC_DIR, "${packageprefix}/${packagedocdir}", [The doc directory.]) AC_DEFINE_UNQUOTED(PACKAGE_PIXMAPS_DIR, "${packageprefix}/${packagepixmapsdir}", [The pixmaps directory.]) AC_DEFINE_UNQUOTED(PACKAGE_HELP_DIR, "${packageprefix}/${packagehelpdir}", [The help directory.]) AC_DEFINE_UNQUOTED(PACKAGE_MENU_DIR, "${packageprefix}/${packagemenudir}", [The menu directory.]) AC_DEFINE_UNQUOTED(PACKAGE_MAN_DIR, "${packageprefix}/${packagemandir}", [The man directory.]) AC_DEFINE_UNQUOTED(PACKAGE_ETC_DIR, "${packageetcprefix}/${packageetcdir}", [The etc directory.]) AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}", [The source directory.]) AC_OUTPUT([ Makefile src/Makefile ]) |
xiaosuo@gentux project1 $ touch NEWS README AUTHORS ChangeLog |
xiaosuo@gentux project1 $ gettextize -c -f --intl --no-changelog Creating intl/ subdirectory Creating po/ subdirectory Copying file ABOUT-NLS Copying file config.rpath Copying file intl/bindtextdom.c Copying file intl/ChangeLog Copying file intl/config.charset Copying file intl/dcgettext.c Copying file intl/dcigettext.c Copying file intl/dcngettext.c Copying file intl/dgettext.c Copying file intl/dngettext.c Copying file intl/eval-plural.h Copying file intl/explodename.c Copying file intl/export.h Copying file intl/finddomain.c Copying file intl/gettext.c Copying file intl/gettextP.h Copying file intl/gmo.h Copying file intl/hash-string.c Copying file intl/hash-string.h Copying file intl/intl-compat.c Copying file intl/intl-exports.c Copying file intl/l10nflist.c Copying file intl/langprefs.c Copying file intl/libgnuintl.h.in Copying file intl/loadinfo.h Copying file intl/loadmsgcat.c Copying file intl/localcharset.c Copying file intl/localcharset.h Copying file intl/locale.alias Copying file intl/localealias.c Copying file intl/localename.c Copying file intl/lock.c Copying file intl/lock.h Copying file intl/log.c Copying file intl/Makefile.in Copying file intl/ngettext.c Copying file intl/os2compat.c Copying file intl/os2compat.h Copying file intl/osdep.c Copying file intl/plural.c Copying file intl/plural-exp.c Copying file intl/plural-exp.h Copying file intl/plural.y Copying file intl/printf-args.c Copying file intl/printf-args.h Copying file intl/printf.c Copying file intl/printf-parse.c Copying file intl/printf-parse.h Copying file intl/ref-add.sin Copying file intl/ref-del.sin Copying file intl/relocatable.c Copying file intl/relocatable.h Copying file intl/textdomain.c Copying file intl/vasnprintf.c Copying file intl/vasnprintf.h Copying file intl/vasnwprintf.h Copying file intl/VERSION Copying file intl/version.c Copying file intl/wprintf-parse.h Copying file intl/xsize.h Copying file po/Makefile.in.in Copying file po/boldquot.sed Copying file po/en@boldquot.header Copying file po/en@quot.header Copying file po/insert-header.sin Copying file po/Makevars.template Copying file po/quot.sed Copying file po/remove-potcdate.sin Copying file po/Rules-quot Creating initial po/POTFILES.in Creating directory m4 Copying file m4/codeset.m4 Copying file m4/gettext.m4 Copying file m4/glibc2.m4 Copying file m4/glibc21.m4 Copying file m4/iconv.m4 Copying file m4/intdiv0.m4 Copying file m4/intmax.m4 Copying file m4/inttypes_h.m4 Copying file m4/inttypes-h.m4 Copying file m4/inttypes-pri.m4 Copying file m4/lcmessage.m4 Copying file m4/lib-ld.m4 Copying file m4/lib-link.m4 Copying file m4/lib-prefix.m4 Copying file m4/lock.m4 Copying file m4/longdouble.m4 Copying file m4/longlong.m4 Copying file m4/nls.m4 Copying file m4/po.m4 Copying file m4/printf-posix.m4 Copying file m4/progtest.m4 Copying file m4/signed.m4 Copying file m4/size_max.m4 Copying file m4/stdint_h.m4 Copying file m4/uintmax_t.m4 Copying file m4/ulonglong.m4 Copying file m4/visibility.m4 Copying file m4/wchar_t.m4 Copying file m4/wint_t.m4 Copying file m4/xsize.m4 Updating Makefile.am (backup is in Makefile.am~) Updating configure.in (backup is in configure.in~) Please create po/Makevars from the template in po/Makevars.template. You can then remove po/Makevars.template. Please fill po/POTFILES.in as described in the documentation. Please run 'aclocal -I m4' to regenerate the aclocal.m4 file. You need aclocal from GNU automake 1.5 (or newer) to do this. Then run 'autoconf' to regenerate the configure file. You will also need config.guess and config.sub, which you can get from the CVS of the 'config' project at The commands to fetch them are $ wget '*checkout*/config/config/config.guess' $ wget '*checkout*/config/config/config.sub' You might also want to copy the convenience header file gettext.h from the /usr/share/gettext directory into your package. It is a wrapper around option. Press Return to acknowledge the previous five paragraphs. xiaosuo@gentux project1 $ libtoolize -c -f You should add the contents of `/usr/share/aclocal/libtool.m4' to `aclocal.m4'. xiaosuo@gentux project1 $ aclocal -I m4 xiaosuo@gentux project1 $ autoheader xiaosuo@gentux project1 $ automake --add-missing -c --gnu configure.in: installing `./install-sh' configure.in: installing `./missing' src/Makefile.am: installing `./depcomp' Makefile.am: installing `./INSTALL' Makefile.am: installing `./COPYING' xiaosuo@gentux project1 $ autoconf |
xiaosuo@gentux project1 $ ls ABOUT-NLS ChangeLog config.sub COPYING intl Makefile.am~ po aclocal.m4 config.guess configure depcomp ltmain.sh Makefile.in README AUTHORS config.h.in configure.in INSTALL m4 missing src autom4te.cache config.rpath configure.in~ install-sh Makefile.am NEWS |
xiaosuo@gentux project1 $ cd po |
# List of source files which contain translatable strings. src/project1.c |
xiaosuo@gentux po $ intltool-update -p xiaosuo@gentux po $ ls boldquot.sed insert-header.sin POTFILES.in remove-potcdate.sin en@boldquot.header Makefile.in.in project1.pot Rules-quot en@quot.header Makevars quot.sed |
xiaosuo@gentux po $ cp project1.pot zh_CN.po |
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR # #, fuzzy msgid "" msgstr "" "Project-Id-Version: project1 0.0.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2006-08-29 21:48+0800\n" "PO-Revision-Date: 2006-08-29 21:48+0800\n" "Last-Translator: xiaosuo "Language-Team: xiaosuo "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: ../src/project1.c:19 #, c-format msgid "Hello, world!\n" msgstr "你好,世界!\n" |
xiaosuo@gentux project1 $ ./configure --prefix=`pwd`/test && make && make install |
xiaosuo@gentux project1 $ ./test/bin/project1 你好,世界! xiaosuo@gentux project1 $ export LANG=C xiaosuo@gentux project1 $ export LC_ALL=C xiaosuo@gentux project1 $ ./test/bin/project1 Hello, world! |
xiaosuo@gentux project1 $ find . -name "*~" | xargs rm -f xiaosuo@gentux project1 $ rm test -rf xiaosuo@gentux project1 $ make distclean ... ... xiaosuo@gentux project1 $ cd ../ xiaosuo@gentux skeleton $ tar cjf project1-0.0.1.tar.bz2 project1 |