| An Internationalized Software Project With Auto Tools | ||
|---|---|---|
| Prev | Internationalization Tips | Next |
String s = i18n("Press OK to delete ") + n + i18n(" files");
|
printf(i18n("Press OK to delete %d files"), n);
|
char * msg = "Press ok to confirm the following actions:\n" "Deleting of %d files\n" "Deleting of %d directories"; |
printf("Press OK to %s %d file(s)", action, number);
|
printf("Drücken Sie OK, um %d Datei(en) zu %s", number, action);
|
switch (action)
{
case create:
printf(i18n(Press OK to insert %d file(s)), number); break;
case delete:
printf(i18n(Press OK to delete %d file(s)), number); break;
}
|
new MessageFormat(i18n("Press OK to {0} {1} file(s)"))
.format(new Object[] {action, new Integer(number)})
|
"Drücken Sie OK, um {1} Datei(en) zu {0}"
|
printf(i18n("You have won %d point(s)!"), n);
|
if (n == 1)
printf(i18n("You have won one point!"));
else
printf(i18n("You have won %d points!"), n);
|
#define i18nP(singular, plural, n) ngettext(singular, plural, n) |
printf(i18nP("You have won one point!", "You have won %d points!", n), n);
|
.pot file |
... msgid "You have won one point!" msgid_plural "You have won %d points!" msgstr[0] "" ... |
german .po file |
... Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1; ... |
.po file |
... msgid "You have won one point!" msgid_plural "You have won %d points!" msgstr[0] "Sie haben einen Punkt gewonnen!" msgstr[1] "Sie haben %d Punkte gewonnen!" ... |
const char * errors [] = {i18n("a message"), i18n("another message")};
int main(int)
{
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
printf(i18n("error: %s\n"), errors[1]);
}
|
#define i18nM(x) x |
const char * errors [] = {i18nM("a message"), i18nM("another message")};
int main(int)
{
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
printf(i18n("error: %s\n"), i18n(errors[1]));
}
|
const char * directions [] = {i18nM("right"), i18nM("left")};
const char * results [] = {i18nM("right"), i18nM("wrong")};
|
Menu|File Menu|Printer Menu|File|Open Menu|File|New Menu|Printer|Select Menu|Printer|Open |
char * sgettext (const char *msgid)
{
char *msgval = gettext (msgid);
if (msgval == msgid)
msgval = strrchr (msgid, '|') + 1;
return msgval;
}
|
Menu|File Menu|Printer Menu_File|Open Menu_File|New Menu_Printer|Select Menu_Printer|Open |
int strcntchar(const char * s, char c)
{
for (int i = 0; ; ++s, ++i)
{
if (!(s = strchr(s, c)))
return i;
}
}
char * sgettext (const char *msgid)
{
char *msgval = gettext (msgid);
int pipeCount = strcntchar(msgid, '|');
if (pipeCount && pipeCount == strcntchar(msgval, '|'))
msgval = strchr (msgval, '|') + 1;
return msgval;
}
|
src/i18n.h |
#include "../config.h" #include "gettext.h" #define i18n(x) sgettext(x) #define i18nP(singular, plural, n) ngettext(singular, plural, n) #define i18nM(x) x char * sgettext (const char *msgid); int strcntchar(const char * s, char c); |
# touch src/i18n.cpp |
src/i18n.cpp |
#include "i18n.h"
#include <string.h>
int strcntchar(const char * s, char c)
{
for (int i = 0; ; ++s, ++i)
{
if (!(s = strchr(s, c)))
return i;
}
}
char * sgettext (const char *msgid)
{
char *msgval = gettext(msgid);
int pipeCount = strcntchar(msgid, '|');
if (pipeCount && pipeCount == strcntchar(msgval, '|'))
msgval = strchr(msgval, '|') + 1;
return msgval;
}
|
src/Makefile.am |
... bin_PROGRAMS = testproj testproj_SOURCES = main.cpp i18n.cpp noinst_HEADERS = testproj.h i18n.h ... |
src/main.cpp |
#include <stdio.h>
#include <locale.h>
#include "testmodule/testfunc.h"
#include "i18n.h"
// These arrays will be instantiated before gettext is initialized.
// Nevertheless they will be translated correctly
// The string 'right' has two different meanings and is prefixed, so that it
// can have different translations.
const char * directions [] = {i18nM("directions|right"), i18nM("left")};
const char * results [] = {i18nM("results|right"), i18nM("wrong")};
int main(int)
{
int n;
// initialize gettext
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
printMessage();
|
# gmake ... # gmake update-po ... 2 translated messages, 8 untranslated messages. gmake[2]: Leaving directory `/usr/home/he/develop/testproj/po' gmake[1]: Leaving directory `/usr/home/he/develop/testproj/po' |
po/de.po |
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR James T. # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR |
# gmake update-gmo ... 10 translated messages. gmake[1]: Leaving directory `/usr/home/he/develop/testproj/po' # gmake install ... # testproj Hello world! Press a key Possible directions: right, left Possible results: right, wrong Enter a number: 42 You have won 42 points! # setenv LC_ALL de_DE.ISO8859-1 ; testproj ; unsetenv LC_ALL Hallo Welt! Drücken Sie eine Taste Mögliche Richtungen: rechts, links Mögliche Ergebnisse: richtig, falsch Geben Sie eine Zahl ein: 1 Sie haben einen Punkt gewonnen! |
| Prev | Home | Next |
| Using gettext | Documentation Overview |