gettext example

This commit is contained in:
Kolan Sh 2012-09-24 16:11:06 +04:00
parent 4d32dd63ae
commit 1882501451
43 changed files with 872 additions and 0 deletions

106
c/gettext-gtk/Makefile Normal file
View File

@ -0,0 +1,106 @@
# Makefile generated by command: smake.sh -t helloworld -Pglib-2.0 -Pgtk+-2.0
# This file is generated with smake.sh.
# You can use this make file with instruction make to
# use one of build mode: debug, profile, develop, release.
# No need to call make clean if You make with other mode,
# because the Makefile containes rules for automatically clean.
# Some usage examples:
# make # default mode is debug
# CFLAGS="-O2 -march=core2 -mtune=core2 -msse4.1 -mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=develop
# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=profile
# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=release
# Report bugs to <mecareful@gmail.com>
#_________________________________
# ENVIRONMENT |
#________________________________|
TARGET0=helloworld
TARGETS= $(TARGET0)
CC=cc
CXX=c++
CFLAGS := $(CFLAGS)
CXXFLAGS := $(CXXFLAGS)
LDFLAGS := $(LDFLAGS)
LIBS=-latk-1.0 -lcairo -lfontconfig -lfreetype -lgdk-x11-2.0 -lgdk_pixbuf-2.0 -lgio-2.0 -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0 -lgtk-x11-2.0 -lpango-1.0 -lpangocairo-1.0 -lpangoft2-1.0 -lrt -pthread
SRC=
INCLUDES=-D_REENTRANT -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/directfb -I/usr/include/freetype2 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/include/gtk-2.0 -I/usr/include/libdrm -I/usr/include/libpng15 -I/usr/include/pango-1.0 -I/usr/include/pixman-1 -I/usr/lib64/glib-2.0/include -I/usr/lib64/gtk-2.0/include -pthread
#________________________________________
# BUILD SCRIPT (don't change) |
#_______________________________________|
ifeq ($(mode),)
mode = debug
endif
ifeq ($(mode),debug)
CFLAGS := -O0 -g -DDEBUG -std=c99 -pedantic -Wextra -Wconversion $(CFLAGS)
LDFLAGS := $(LDFLAGS)
endif
ifeq ($(mode),profile)
CFLAGS := -O0 -g -DDEBUG -std=c99 -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
LDFLAGS := -g -p $(LDFLAGS)
endif
ifeq ($(mode),develop)
CFLAGS := -O2 -g -DDEBUG -std=c99 $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
ifeq ($(mode),release)
CFLAGS := -O2 -std=c99 $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
CFLAGS += -Wall $(INCLUDES)
LDFLAGS += -Wall
all:
@make change_make_options &>/dev/null
+make $(TARGETS)
ifneq ($(mode),debug)
ifneq ($(mode),profile)
ifneq ($(mode),develop)
ifneq ($(mode),release)
@echo "Invalid build mode."
@echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'"
@exit 1
endif
endif
endif
endif
@echo ".........................."
@echo "Building on "$(mode)" mode "
@echo "CFLAGS=$(CFLAGS)"
@echo "LDFLAGS=$(LDFLAGS)"
@echo ".........................."
OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~')
OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~')
OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~')
change_make_options:
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
@echo CLEANING...
@make clean
@echo "MODE=$(mode)" > make_options.out
@echo "CFLAGS=$(CFLAGS)" >> make_options.out
@echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
endif
%.o :
$(CC) -c $(CFLAGS) $(SRC) -o $@ $<
clean:
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGETS)
.PHONY: all change_make_options clean
#_________________________________
# R U L E S |
#________________________________|
target_objs0 = \
helloworld.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0) $(LIBS)
helloworld.o: \
helloworld.c

View File

@ -0,0 +1,43 @@
#include <gtk/gtk.h>
#include <libintl.h>
#define _(String) gettext (String)
//#define gettext_noop(String) String
#////////////define N_(String) gettext_noop (String)
#define GETTEXT_PACKAGE "helloworld"
//#define LOCALEDIR "./locale"
static void button_clicked(GtkWidget * widget, gpointer data)
{
g_print("Button pressed!\n");
}
static gboolean delete_event(GtkWidget * widget, GdkEvent * event, gpointer data)
{
g_print("Delete event occurred\n");
return FALSE;
}
static void destroy(GtkWidget * widget, gpointer data)
{
g_print("Destroy signal sent\n");
gtk_main_quit();
}
int main(int argc, char ** argv)
{
GtkWidget * window;
GtkWidget * button;
//bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
//bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), _("Hello World!"));
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
button = gtk_button_new_with_label(_("Quit"));
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_clicked), NULL);
g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(window));
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main();
return 0;
}

View File

@ -0,0 +1,26 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-19 18:16+0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: helloworld.c:31
msgid "Hello World!"
msgstr ""
#: helloworld.c:35
msgid "Quit"
msgstr ""

View File

@ -0,0 +1,27 @@
# Russian translations for PACKAGE package.
# Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# <kolan@nickolay-842.insysltd.ru>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-19 18:16+0400\n"
"PO-Revision-Date: 2012-09-19 18:16+0400\n"
"Last-Translator: <kolan@nickolay-842.insysltd.ru>\n"
"Language-Team: Russian\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: helloworld.c:31
msgid "Hello World!"
msgstr "Привет, Мир!"
#: helloworld.c:35
msgid "Quit"
msgstr "Выход"

3
c/gettext-gtk/make_po.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
xgettext -C helloworld.c -k_

View File

@ -0,0 +1,12 @@
project (gettextex1)
cmake_minimum_required (VERSION 2.8)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(MacroOptionalAddSubdirectory)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/run")
set (LOCALE_INSTALL_DIR "share/locale")
macro_optional_add_subdirectory (po)
add_subdirectory (test)

1
c/gettext_cmake/README Normal file
View File

@ -0,0 +1 @@
To fix Borland varrags.h && stdarg.h error just comment #error line in them.

View File

@ -0,0 +1,31 @@
# - MACRO_OPTIONAL_ADD_SUBDIRECTORY() combines ADD_SUBDIRECTORY() with an OPTION()
# MACRO_OPTIONAL_ADD_SUBDIRECTORY( <dir> )
# If you use MACRO_OPTIONAL_ADD_SUBDIRECTORY() instead of ADD_SUBDIRECTORY(),
# this will have two effects
# 1 - CMake will not complain if the directory doesn't exist
# This makes sense if you want to distribute just one of the subdirs
# in a source package, e.g. just one of the subdirs in kdeextragear.
# 2 - If the directory exists, it will offer an option to skip the
# subdirectory.
# This is useful if you want to compile only a subset of all
# directories.
# Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
MACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY _dir )
GET_FILENAME_COMPONENT(_fullPath ${_dir} ABSOLUTE)
IF(EXISTS ${_fullPath})
IF(${ARGC} EQUAL 2)
OPTION(BUILD_${_dir} "Build directory ${_dir}" ${ARGV1})
ELSE(${ARGC} EQUAL 2)
OPTION(BUILD_${_dir} "Build directory ${_dir}" TRUE)
ENDIF(${ARGC} EQUAL 2)
IF(BUILD_${_dir})
ADD_SUBDIRECTORY(${_dir})
ENDIF(BUILD_${_dir})
ENDIF(EXISTS ${_fullPath})
ENDMACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY)

View File

@ -0,0 +1,9 @@
find_package(Gettext REQUIRED)
if (NOT GETTEXT_MSGMERGE_EXECUTABLE)
MESSAGE(FATAL_ERROR "Please install msgmerge binary")
endif (NOT GETTEXT_MSGMERGE_EXECUTABLE)
if (NOT GETTEXT_MSGFMT_EXECUTABLE)
MESSAGE(FATAL_ERROR "Please install msgmerge binary")
endif (NOT GETTEXT_MSGFMT_EXECUTABLE)
add_subdirectory(ru)
add_subdirectory(it)

View File

@ -0,0 +1,28 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: gettextex1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-21 14:30+0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:14
#, c-format
msgid "Hello World!"
msgstr ""
#: /home/kolan/dev/c/gettext/test/gettextex1.c:16
#, c-format
msgid "Quit"
msgstr ""

View File

@ -0,0 +1,2 @@
file(GLOB _po_files *.po)
GETTEXT_PROCESS_PO_FILES(it ALL INSTALL_DESTINATION ${LOCALE_INSTALL_DIR} PO_FILES ${_po_files} )

View File

@ -0,0 +1,28 @@
# Italian translations for gettextex1 package.
# Copyright (C) 2012 THE gettextex1'S COPYRIGHT HOLDER
# This file is distributed under the same license as the gettextex1 package.
# <mecareful@gmail.com>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: gettextex1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-21 14:30+0400\n"
"PO-Revision-Date: 2012-09-21 13:32+0400\n"
"Last-Translator: <mecareful@gmail.com>\n"
"Language-Team: Italian\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ASCII\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:14
#, c-format
msgid "Hello World!"
msgstr ""
#: /home/kolan/dev/c/gettext/test/gettextex1.c:16
#, c-format
msgid "Quit"
msgstr ""

View File

@ -0,0 +1,2 @@
file(GLOB _po_files *.po)
GETTEXT_PROCESS_PO_FILES(ru ALL INSTALL_DESTINATION ${LOCALE_INSTALL_DIR} PO_FILES ${_po_files} )

View File

@ -0,0 +1,29 @@
# Russian translations for gettextex1 package.
# Copyright (C) 2012 THE gettextex1'S COPYRIGHT HOLDER
# This file is distributed under the same license as the gettextex1 package.
# <memecareful@gmail.com>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: gettextex1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-21 14:30+0400\n"
"PO-Revision-Date: 2012-09-21 13:32+0400\n"
"Last-Translator: <memecareful@gmail.com>\n"
"Language-Team: Russian\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:14
#, c-format
msgid "Hello World!"
msgstr "Привет, Мир!"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:16
#, c-format
msgid "Quit"
msgstr "Выход"

View File

View File

@ -0,0 +1,13 @@
find_package (PkgConfig REQUIRED)
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
include_directories (${GLIB2_INCLUDE_DIRS})
link_directories (${GLIB2_LIBRARY_DIRS})
if (CMAKE_COMPILER_IS_GNUCC)
add_definitions (${GLIB2_CFLAGS_OTHER})
endif ()
# add the executable
add_executable (gettextex1 gettextex1.c)
target_link_libraries (gettextex1 ${GLIB2_LIBRARIES})

View File

@ -0,0 +1,21 @@
#include <glib/gprintf.h>
#include <glib/gi18n.h>
#include <locale.h>
#define _(String) gettext (String)
#define GETTEXT_PACKAGE "gettextex1"
#define LOCALEDIR "./locale"
int main(void)
{
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
//bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
g_printf (_("Hello World!"));
g_printf ("\n");
g_printf (_("Quit"));
return 0;
}

View File

@ -0,0 +1,18 @@
@echo off
echo a
del /s/q/f build-borland
rmdir /s/q build-borland
mkdir build-borland
cd build-borland
cmake -G "Borland Makefiles" -DCMAKE_C_FLAGS="-Ic:/usr-bcb/include" ..
make
mkdir run\locale
mkdir run\locale\ru
mkdir run\locale\ru\LC_MESSAGES
mkdir run\locale\it
mkdir run\locale\it\LC_MESSAGES
copy po\ru\gettextex1.gmo run\locale\ru\LC_MESSAGES\gettextex1.mo
copy po\it\gettextex1.gmo run\locale\it\LC_MESSAGES\gettextex1.mo
cd run
gettextex1.exe
cd ..\..

View File

@ -0,0 +1,11 @@
#!/bin/bash
rm -rf build-gcc
mkdir build-gcc && cd build-gcc && cmake .. && make
[ 0 != $? ] && echo "make failed ;-(" && exit 1
mkdir -p run/locale/ru/LC_MESSAGES
mkdir -p run/locale/it/LC_MESSAGES
cp po/ru/gettextex1.gmo run/locale/ru/LC_MESSAGES/gettextex1.mo
cp po/it/gettextex1.gmo run/locale/it/LC_MESSAGES/gettextex1.mo
cd run
./gettextex1

View File

@ -0,0 +1,11 @@
#!/bin/bash
rm -rf build-mingw
mkdir build-mingw && cd build-mingw && cmake -G "MSYS Makefiles" .. && make
[ 0 != $? ] && echo "make failed ;-(" && exit 1
mkdir -p run/locale/ru/LC_MESSAGES
mkdir -p run/locale/it/LC_MESSAGES
cp po/ru/gettextex1.gmo run/locale/ru/LC_MESSAGES/gettextex1.mo
cp po/it/gettextex1.gmo run/locale/it/LC_MESSAGES/gettextex1.mo
cd run
./gettextex1

View File

@ -0,0 +1,18 @@
@echo off
echo a
del /s/q/f build-msvc
rmdir /s/q build-msvc
mkdir build-msvc
cd build-msvc
cmake -G "NMake Makefiles" -DCMAKE_C_FLAGS="-Ic:/usr/include" ..
nmake
mkdir run\locale
mkdir run\locale\ru
mkdir run\locale\ru\LC_MESSAGES
mkdir run\locale\it
mkdir run\locale\it\LC_MESSAGES
copy po\ru\gettextex1.gmo run\locale\ru\LC_MESSAGES\gettextex1.mo
copy po\it\gettextex1.gmo run\locale\it\LC_MESSAGES\gettextex1.mo
cd run
gettextex1.exe
cd ..\..

View File

@ -0,0 +1,38 @@
#!/bin/sh
##
# settings
##
PROJECT=gettextex1
PO_DIR_NAME=po
SCRIPT_PATH=`readlink -f $0`
SCRIPT_DIR=${SCRIPT_PATH%/*}
PRJDIR=${SCRIPT_DIR%/*}
FILELIST="${PRJDIR}/test/*.c"
##
# code
##
echo $FILELIST
xgettext --package-name=$PROJECT --default-domain=$PROJECT --add-comments=/// \
-k_ -kQ_ -kC_ -kN_ -kNC_ -kg_dgettext -kg_dcgettext \
-kg_dngettext -kg_dpgettext -kg_dpgettext2 -kg_strip_context -F -n -o \
$PRJDIR/$PO_DIR_NAME/$PROJECT.pot $FILELIST
[ 0 != $? ] && echo "xgettext failed ;-(" && exit 1
[ ! -e $PRJDIR/$PO_DIR_NAME/$PROJECT.pot ] && echo "No strings found ;-(" && exit 1
for d in $PRJDIR/$PO_DIR_NAME/*; do
[ ! -d $d ] && continue
if [ -e $d/$PROJECT.po ]; then
echo "Merging '${d##*/}' locale" && msgmerge -F -U $d/$PROJECT.po $PRJDIR/$PO_DIR_NAME/$PROJECT.pot
[ 0 != $? ] && echo "msgmerge failed ;(" && exit 1
else
echo "Creating '${d##*/}' locale" && msginit -l ${d##*/} -o $d/$PROJECT.po -i $PRJDIR/$PO_DIR_NAME/$PROJECT.pot
[ 0 != $? ] && echo "msginit failed ;(" && exit 1
fi
done

View File

@ -0,0 +1,20 @@
project (gettextex2)
cmake_minimum_required (VERSION 2.8)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(MacroOptionalAddSubdirectory)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/run")
include_directories ("${CMAKE_BINARY_DIR}")
include_directories ("${PROJECT_SOURCE_DIR}/src")
if (NOT "" STREQUAL "${CUSTOM_INCLUDE_PATH}")
include_directories ("${CUSTOM_INCLUDE_PATH}")
endif ()
add_subdirectory (src)
set (LOCALE_INSTALL_DIR "share/locale")
macro_optional_add_subdirectory (po)
add_subdirectory (test)

View File

@ -0,0 +1,31 @@
# - MACRO_OPTIONAL_ADD_SUBDIRECTORY() combines ADD_SUBDIRECTORY() with an OPTION()
# MACRO_OPTIONAL_ADD_SUBDIRECTORY( <dir> )
# If you use MACRO_OPTIONAL_ADD_SUBDIRECTORY() instead of ADD_SUBDIRECTORY(),
# this will have two effects
# 1 - CMake will not complain if the directory doesn't exist
# This makes sense if you want to distribute just one of the subdirs
# in a source package, e.g. just one of the subdirs in kdeextragear.
# 2 - If the directory exists, it will offer an option to skip the
# subdirectory.
# This is useful if you want to compile only a subset of all
# directories.
# Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
MACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY _dir )
GET_FILENAME_COMPONENT(_fullPath ${_dir} ABSOLUTE)
IF(EXISTS ${_fullPath})
IF(${ARGC} EQUAL 2)
OPTION(BUILD_${_dir} "Build directory ${_dir}" ${ARGV1})
ELSE(${ARGC} EQUAL 2)
OPTION(BUILD_${_dir} "Build directory ${_dir}" TRUE)
ENDIF(${ARGC} EQUAL 2)
IF(BUILD_${_dir})
ADD_SUBDIRECTORY(${_dir})
ENDIF(BUILD_${_dir})
ENDIF(EXISTS ${_fullPath})
ENDMACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY)

View File

@ -0,0 +1,9 @@
find_package(Gettext REQUIRED)
if (NOT GETTEXT_MSGMERGE_EXECUTABLE)
MESSAGE(FATAL_ERROR "Please install msgmerge binary")
endif (NOT GETTEXT_MSGMERGE_EXECUTABLE)
if (NOT GETTEXT_MSGFMT_EXECUTABLE)
MESSAGE(FATAL_ERROR "Please install msgmerge binary")
endif (NOT GETTEXT_MSGFMT_EXECUTABLE)
add_subdirectory(ru)
add_subdirectory(it)

View File

@ -0,0 +1,28 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: gettextex1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-21 14:30+0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:14
#, c-format
msgid "Hello World!"
msgstr ""
#: /home/kolan/dev/c/gettext/test/gettextex1.c:16
#, c-format
msgid "Quit"
msgstr ""

View File

@ -0,0 +1,2 @@
file(GLOB _po_files *.po)
GETTEXT_PROCESS_PO_FILES(it ALL INSTALL_DESTINATION ${LOCALE_INSTALL_DIR} PO_FILES ${_po_files} )

View File

@ -0,0 +1,28 @@
# Italian translations for gettextex1 package.
# Copyright (C) 2012 THE gettextex1'S COPYRIGHT HOLDER
# This file is distributed under the same license as the gettextex1 package.
# <mecareful@gmail.com>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: gettextex1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-21 14:30+0400\n"
"PO-Revision-Date: 2012-09-21 13:32+0400\n"
"Last-Translator: <mecareful@gmail.com>\n"
"Language-Team: Italian\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ASCII\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:14
#, c-format
msgid "Hello World!"
msgstr ""
#: /home/kolan/dev/c/gettext/test/gettextex1.c:16
#, c-format
msgid "Quit"
msgstr ""

View File

@ -0,0 +1,2 @@
file(GLOB _po_files *.po)
GETTEXT_PROCESS_PO_FILES(ru ALL INSTALL_DESTINATION ${LOCALE_INSTALL_DIR} PO_FILES ${_po_files} )

View File

@ -0,0 +1,29 @@
# Russian translations for gettextex1 package.
# Copyright (C) 2012 THE gettextex1'S COPYRIGHT HOLDER
# This file is distributed under the same license as the gettextex1 package.
# <memecareful@gmail.com>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: gettextex1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-09-21 14:30+0400\n"
"PO-Revision-Date: 2012-09-21 13:32+0400\n"
"Last-Translator: <memecareful@gmail.com>\n"
"Language-Team: Russian\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:14
#, c-format
msgid "Hello World!"
msgstr "Привет, Мир!"
#: /home/kolan/dev/c/gettext/test/gettextex1.c:16
#, c-format
msgid "Quit"
msgstr "Выход"

View File

View File

@ -0,0 +1,13 @@
find_package (PkgConfig REQUIRED)
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
include_directories (${GLIB2_INCLUDE_DIRS})
link_directories (${GLIB2_LIBRARY_DIRS})
if (CMAKE_COMPILER_IS_GNUCC)
add_definitions (${GLIB2_CFLAGS_OTHER})
endif ()
# add the main library
add_library (gettextex2 SHARED gettextex2.c)
target_link_libraries (gettextex2 ${GLIB2_LIBRARIES})

View File

@ -0,0 +1,12 @@
#define GETTEXT_PACKAGE "gettextex2"
#if !defined (__STDC__) && !defined(_MSC_VER)
#define __STDC__ 1
#include <glib/gi18n.h>
#undef __STDC__
#else
#ifdef __MINGW32__
#include <glib/gi18n.h>
#else
#include <glib/gi18n-lib.h>
#endif
#endif

View File

@ -0,0 +1,42 @@
#if defined(_MSC_VER) || defined(__BORLANDC__)
#include <windows.h>
#endif
#include "gettext_config.h"
#include <glib/gprintf.h>
#include "gettextex2.h"
#ifdef LOCALEDIR
#undef LOCALEDIR
#define LOCALEDIR "./locale"
#endif
#ifdef __GNUC__
void __attribute__ ((constructor)) texparser_load (void)
#elif defined (_MSC_VER) || defined (__BORLANDC__)
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
#else
#error Unknown compiler
#endif
{
#ifdef LOCALEDIR
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); // remove if standard path used
#endif
textdomain (GETTEXT_PACKAGE);
#if defined(_MSC_VER) || defined(__BORLANDC__)
(void) hInstance;
(void) dwReason;
(void) lpReserved;
return TRUE;
#endif
}
void
gettextex2 (void)
{
g_printf (_("Hello World!"));
g_printf ("\n");
g_printf (_("Quit"));
}

View File

@ -0,0 +1,8 @@
#ifndef __GETTEXTEX2_H__
#define __GETTEXTEX2_H__
#include "gettextex2_export.h"
GETTEXTEX2_EXPRT void gettextex2 (void);
#endif // __GETTEXTEX2_H__

View File

@ -0,0 +1,14 @@
#ifndef __GETTEXTEX2_EXPORT_H__
#define __GETTEXTEX2_EXPORT_H__
#ifdef WIN32
# ifdef gettextex2_EXPORTS
# define GETTEXTEX2_EXPRT __declspec(dllexport)
# else
# define GETTEXTEX2_EXPRT __declspec(dllimport)
# endif
#else
# define GETTEXTEX2_EXPRT
#endif
#endif /* __GETTEXTEX2_EXPORT_H__ */

View File

@ -0,0 +1,13 @@
find_package (PkgConfig REQUIRED)
pkg_check_modules (GLIB2 REQUIRED glib-2.0)
include_directories (${GLIB2_INCLUDE_DIRS})
link_directories (${GLIB2_LIBRARY_DIRS})
if (CMAKE_COMPILER_IS_GNUCC)
add_definitions (${GLIB2_CFLAGS_OTHER})
endif ()
# add the executable
add_executable (gettextex2_test gettextex2_test.c)
target_link_libraries (gettextex2_test gettextex2 ${GLIB2_LIBRARIES})

View File

@ -0,0 +1,14 @@
#include <glib/gprintf.h>
#include <locale.h>
#include "gettextex2.h"
int main(void)
{
setlocale (LC_ALL, "");
gettextex2 ();
return 0;
}

View File

@ -0,0 +1,28 @@
@echo off
echo a
del /s/q/f build-borland
rmdir /s/q build-borland
mkdir build-borland
cd build-borland
cmake -G "Borland Makefiles" -DCMAKE_C_FLAGS="-DLOCALEDIR" -DCUSTOM_INCLUDE_PATH="c:/usr-bcb/include" ..
make
mkdir src\locale
mkdir src\locale\ru
mkdir src\locale\ru\LC_MESSAGES
mkdir src\locale\it
mkdir src\locale\it\LC_MESSAGES
copy po\ru\gettextex2.gmo src\locale\ru\LC_MESSAGES\gettextex2.mo
copy po\it\gettextex2.gmo src\locale\it\LC_MESSAGES\gettextex2.mo
mkdir run\locale
mkdir run\locale\ru
mkdir run\locale\ru\LC_MESSAGES
mkdir run\locale\it
mkdir run\locale\it\LC_MESSAGES
copy po\ru\gettextex2.gmo run\locale\ru\LC_MESSAGES\gettextex2.mo
copy po\it\gettextex2.gmo run\locale\it\LC_MESSAGES\gettextex2.mo
cd run
gettextex2_test.exe
cd ..\..

View File

@ -0,0 +1,18 @@
#!/bin/bash
rm -rf build-gcc
mkdir build-gcc && cd build-gcc && cmake -DCMAKE_C_FLAGS="-DLOCALEDIR" .. && make
[ 0 != $? ] && echo "make failed ;-(" && exit 1
mkdir -p src/locale/ru/LC_MESSAGES
mkdir -p src/locale/it/LC_MESSAGES
cp po/ru/gettextex2.gmo src/locale/ru/LC_MESSAGES/gettextex2.mo
cp po/it/gettextex2.gmo src/locale/it/LC_MESSAGES/gettextex2.mo
mkdir -p run/locale/ru/LC_MESSAGES
mkdir -p run/locale/it/LC_MESSAGES
cp po/ru/gettextex2.gmo run/locale/ru/LC_MESSAGES/gettextex2.mo
cp po/it/gettextex2.gmo run/locale/it/LC_MESSAGES/gettextex2.mo
cd run
./gettextex2_test

View File

@ -0,0 +1,18 @@
#!/bin/bash
rm -rf build-mingw
mkdir build-mingw && cd build-mingw && cmake -G "MSYS Makefiles" -DCMAKE_C_FLAGS="-DLOCALEDIR" .. && make
[ 0 != $? ] && echo "make failed ;-(" && exit 1
mkdir -p src/locale/ru/LC_MESSAGES
mkdir -p src/locale/it/LC_MESSAGES
cp po/ru/gettextex2.gmo src/locale/ru/LC_MESSAGES/gettextex2.mo
cp po/it/gettextex2.gmo src/locale/it/LC_MESSAGES/gettextex2.mo
mkdir -p run/locale/ru/LC_MESSAGES
mkdir -p run/locale/it/LC_MESSAGES
cp po/ru/gettextex2.gmo run/locale/ru/LC_MESSAGES/gettextex2.mo
cp po/it/gettextex2.gmo run/locale/it/LC_MESSAGES/gettextex2.mo
cd run
./gettextex2_test

View File

@ -0,0 +1,28 @@
@echo off
echo a
del /s/q/f build-msvc
rmdir /s/q build-msvc
mkdir build-msvc
cd build-msvc
cmake -G "NMake Makefiles" -DCUSTOM_INCLUDE_PATH="c:/usr/include" -DCMAKE_C_FLAGS="-DLOCALEDIR" ..
nmake
mkdir src\locale
mkdir src\locale\ru
mkdir src\locale\ru\LC_MESSAGES
mkdir src\locale\it
mkdir src\locale\it\LC_MESSAGES
copy po\ru\gettextex2.gmo src\locale\ru\LC_MESSAGES\gettextex2.mo
copy po\it\gettextex2.gmo src\locale\it\LC_MESSAGES\gettextex2.mo
mkdir run\locale
mkdir run\locale\ru
mkdir run\locale\ru\LC_MESSAGES
mkdir run\locale\it
mkdir run\locale\it\LC_MESSAGES
copy po\ru\gettextex2.gmo run\locale\ru\LC_MESSAGES\gettextex2.mo
copy po\it\gettextex2.gmo run\locale\it\LC_MESSAGES\gettextex2.mo
cd run
gettextex2_test.exe
cd ..\..

View File

@ -0,0 +1,38 @@
#!/bin/sh
##
# settings
##
PROJECT=gettextex1
PO_DIR_NAME=po
SCRIPT_PATH=`readlink -f $0`
SCRIPT_DIR=${SCRIPT_PATH%/*}
PRJDIR=${SCRIPT_DIR%/*}
FILELIST="${PRJDIR}/test/*.c"
##
# code
##
echo $FILELIST
xgettext --package-name=$PROJECT --default-domain=$PROJECT --add-comments=/// \
-k_ -kQ_ -kC_ -kN_ -kNC_ -kg_dgettext -kg_dcgettext \
-kg_dngettext -kg_dpgettext -kg_dpgettext2 -kg_strip_context -F -n -o \
$PRJDIR/$PO_DIR_NAME/$PROJECT.pot $FILELIST
[ 0 != $? ] && echo "xgettext failed ;-(" && exit 1
[ ! -e $PRJDIR/$PO_DIR_NAME/$PROJECT.pot ] && echo "No strings found ;-(" && exit 1
for d in $PRJDIR/$PO_DIR_NAME/*; do
[ ! -d $d ] && continue
if [ -e $d/$PROJECT.po ]; then
echo "Merging '${d##*/}' locale" && msgmerge -F -U $d/$PROJECT.po $PRJDIR/$PO_DIR_NAME/$PROJECT.pot
[ 0 != $? ] && echo "msgmerge failed ;(" && exit 1
else
echo "Creating '${d##*/}' locale" && msginit -l ${d##*/} -o $d/$PROJECT.po -i $PRJDIR/$PO_DIR_NAME/$PROJECT.pot
[ 0 != $? ] && echo "msginit failed ;(" && exit 1
fi
done