Browse Source
* ab/enable-i18n: i18n: add infrastructure for translating Git with gettext Conflicts: Makefilemaint

37 changed files with 1291 additions and 39 deletions
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
package Git::I18N; |
||||
use 5.008; |
||||
use strict; |
||||
use warnings; |
||||
use Exporter 'import'; |
||||
|
||||
our @EXPORT = qw(__); |
||||
our @EXPORT_OK = @EXPORT; |
||||
|
||||
sub __bootstrap_locale_messages { |
||||
our $TEXTDOMAIN = 'git'; |
||||
our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '++LOCALEDIR++'; |
||||
|
||||
require POSIX; |
||||
POSIX->import(qw(setlocale)); |
||||
# Non-core prerequisite module |
||||
require Locale::Messages; |
||||
Locale::Messages->import(qw(:locale_h :libintl_h)); |
||||
|
||||
setlocale(LC_MESSAGES(), ''); |
||||
setlocale(LC_CTYPE(), ''); |
||||
textdomain($TEXTDOMAIN); |
||||
bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR); |
||||
|
||||
return; |
||||
} |
||||
|
||||
BEGIN |
||||
{ |
||||
# Used by our test script to see if it should test fallbacks or |
||||
# not. |
||||
our $__HAS_LIBRARY = 1; |
||||
|
||||
local $@; |
||||
eval { |
||||
__bootstrap_locale_messages(); |
||||
*__ = \&Locale::Messages::gettext; |
||||
1; |
||||
} or do { |
||||
# Tell test.pl that we couldn't load the gettext library. |
||||
$Git::I18N::__HAS_LIBRARY = 0; |
||||
|
||||
# Just a fall-through no-op |
||||
*__ = sub ($) { $_[0] }; |
||||
}; |
||||
} |
||||
|
||||
1; |
||||
|
||||
__END__ |
||||
|
||||
=head1 NAME |
||||
|
||||
Git::I18N - Perl interface to Git's Gettext localizations |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Git::I18N; |
||||
|
||||
print __("Welcome to Git!\n"); |
||||
|
||||
printf __("The following error occured: %s\n"), $error; |
||||
|
||||
=head1 DESCRIPTION |
||||
|
||||
Git's internal Perl interface to gettext via L<Locale::Messages>. If |
||||
L<Locale::Messages> can't be loaded (it's not a core module) we |
||||
provide stub passthrough fallbacks. |
||||
|
||||
This is a distilled interface to gettext, see C<info '(gettext)Perl'> |
||||
for the full interface. This module implements only a small part of |
||||
it. |
||||
|
||||
=head1 FUNCTIONS |
||||
|
||||
=head2 __($) |
||||
|
||||
L<Locale::Messages>'s gettext function if all goes well, otherwise our |
||||
passthrough fallback function. |
||||
|
||||
=head1 AUTHOR |
||||
|
||||
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com> |
||||
|
||||
=head1 COPYRIGHT |
||||
|
||||
Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com> |
||||
|
||||
=cut |
@ -0,0 +1,229 @@
@@ -0,0 +1,229 @@
|
||||
Core GIT Translations |
||||
===================== |
||||
|
||||
This directory holds the translations for the core of Git. This |
||||
document describes how to add to and maintain these translations, and |
||||
how to mark source strings for translation. |
||||
|
||||
|
||||
Generating a .pot file |
||||
---------------------- |
||||
|
||||
The po/git.pot file contains a message catalog extracted from Git's |
||||
sources. You need to generate it to add new translations with |
||||
msginit(1), or update existing ones with msgmerge(1). |
||||
|
||||
Since the file can be automatically generated it's not checked into |
||||
git.git. To generate it do, at the top-level: |
||||
|
||||
make pot |
||||
|
||||
|
||||
Initializing a .po file |
||||
----------------------- |
||||
|
||||
To add a new translation first generate git.pot (see above) and then |
||||
in the po/ directory do: |
||||
|
||||
msginit --locale=XX |
||||
|
||||
Where XX is your locale, e.g. "is", "de" or "pt_BR". |
||||
|
||||
Then edit the automatically generated copyright info in your new XX.po |
||||
to be correct, e.g. for Icelandic: |
||||
|
||||
@@ -1,6 +1,6 @@ |
||||
-# Icelandic translations for PACKAGE package. |
||||
-# Copyright (C) 2010 THE PACKAGE'S COPYRIGHT HOLDER |
||||
-# This file is distributed under the same license as the PACKAGE package. |
||||
+# Icelandic translations for Git. |
||||
+# Copyright (C) 2010 Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
||||
+# This file is distributed under the same license as the Git package. |
||||
# Ævar Arnfjörð Bjarmason <avarab@gmail.com>, 2010. |
||||
|
||||
And change references to PACKAGE VERSION in the PO Header Entry to |
||||
just "Git": |
||||
|
||||
perl -pi -e 's/(?<="Project-Id-Version: )PACKAGE VERSION/Git/' XX.po |
||||
|
||||
|
||||
Updating a .po file |
||||
------------------- |
||||
|
||||
If there's an existing *.po file for your language but you need to |
||||
update the translation you first need to generate git.pot (see above) |
||||
and then in the po/ directory do: |
||||
|
||||
msgmerge --add-location --backup=off -U XX.po git.pot |
||||
|
||||
Where XX.po is the file you want to update. |
||||
|
||||
Testing your changes |
||||
-------------------- |
||||
|
||||
Before you submit your changes go back to the top-level and do: |
||||
|
||||
make |
||||
|
||||
On systems with GNU gettext (i.e. not Solaris) this will compile your |
||||
changed PO file with `msgfmt --check`, the --check option flags many |
||||
common errors, e.g. missing printf format strings, or translated |
||||
messages that deviate from the originals in whether they begin/end |
||||
with a newline or not. |
||||
|
||||
|
||||
Marking strings for translation |
||||
------------------------------- |
||||
|
||||
Before strings can be translated they first have to be marked for |
||||
translation. |
||||
|
||||
Git uses an internationalization interface that wraps the system's |
||||
gettext library, so most of the advice in your gettext documentation |
||||
(on GNU systems `info gettext` in a terminal) applies. |
||||
|
||||
General advice: |
||||
|
||||
- Don't mark everything for translation, only strings which will be |
||||
read by humans (the porcelain interface) should be translated. |
||||
|
||||
The output from Git's plumbing utilities will primarily be read by |
||||
programs and would break scripts under non-C locales if it was |
||||
translated. Plumbing strings should not be translated, since |
||||
they're part of Git's API. |
||||
|
||||
- Adjust the strings so that they're easy to translate. Most of the |
||||
advice in `info '(gettext)Preparing Strings'` applies here. |
||||
|
||||
- If something is unclear or ambiguous you can use a "TRANSLATORS" |
||||
comment to tell the translators what to make of it. These will be |
||||
extracted by xgettext(1) and put in the po/*.po files, e.g. from |
||||
git-am.sh: |
||||
|
||||
# TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a] |
||||
# in your translation. The program will only accept English |
||||
# input at this point. |
||||
gettext "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all " |
||||
|
||||
Or in C, from builtin/revert.c: |
||||
|
||||
/* TRANSLATORS: %s will be "revert" or "cherry-pick" */ |
||||
die(_("%s: Unable to write new index file"), action_name(opts)); |
||||
|
||||
We provide wrappers for C, Shell and Perl programs. Here's how they're |
||||
used: |
||||
|
||||
C: |
||||
|
||||
- Include builtin.h at the top, it'll pull in in gettext.h, which |
||||
defines the gettext interface. Consult with the list if you need to |
||||
use gettext.h directly. |
||||
|
||||
- The C interface is a subset of the normal GNU gettext |
||||
interface. We currently export these functions: |
||||
|
||||
- _() |
||||
|
||||
Mark and translate a string. E.g.: |
||||
|
||||
printf(_("HEAD is now at %s"), hex); |
||||
|
||||
- Q_() |
||||
|
||||
Mark and translate a plural string. E.g.: |
||||
|
||||
printf(Q_("%d commit", "%d commits", number_of_commits)); |
||||
|
||||
This is just a wrapper for the ngettext() function. |
||||
|
||||
- N_() |
||||
|
||||
A no-op pass-through macro for marking strings inside static |
||||
initializations, e.g.: |
||||
|
||||
static const char *reset_type_names[] = { |
||||
N_("mixed"), N_("soft"), N_("hard"), N_("merge"), N_("keep"), NULL |
||||
}; |
||||
|
||||
And then, later: |
||||
|
||||
die(_("%s reset is not allowed in a bare repository"), |
||||
_(reset_type_names[reset_type])); |
||||
|
||||
Here _() couldn't have statically determined what the translation |
||||
string will be, but since it was already marked for translation |
||||
with N_() the look-up in the message catalog will succeed. |
||||
|
||||
Shell: |
||||
|
||||
- The Git gettext shell interface is just a wrapper for |
||||
gettext.sh. Import it right after git-sh-setup like this: |
||||
|
||||
. git-sh-setup |
||||
. git-sh-i18n |
||||
|
||||
And then use the gettext or eval_gettext functions: |
||||
|
||||
# For constant interface messages: |
||||
gettext "A message for the user"; echo |
||||
|
||||
# To interpolate variables: |
||||
details="oh noes" |
||||
eval_gettext "An error occured: \$details"; echo |
||||
|
||||
In addition we have wrappers for messages that end with a trailing |
||||
newline. I.e. you could write the above as: |
||||
|
||||
# For constant interface messages: |
||||
gettextln "A message for the user" |
||||
|
||||
# To interpolate variables: |
||||
details="oh noes" |
||||
eval_gettextln "An error occured: \$details" |
||||
|
||||
More documentation about the interface is available in the GNU info |
||||
page: `info '(gettext)sh'`. Looking at git-am.sh (the first shell |
||||
command to be translated) for examples is also useful: |
||||
|
||||
git log --reverse -p --grep=i18n git-am.sh |
||||
|
||||
Perl: |
||||
|
||||
- The Git::I18N module provides a limited subset of the |
||||
Locale::Messages functionality, e.g.: |
||||
|
||||
use Git::I18N; |
||||
print __("Welcome to Git!\n"); |
||||
printf __("The following error occured: %s\n"), $error; |
||||
|
||||
Run `perldoc perl/Git/I18N.pm` for more info. |
||||
|
||||
|
||||
Testing marked strings |
||||
---------------------- |
||||
|
||||
Even if you've correctly marked porcelain strings for translation |
||||
something in the test suite might still depend on the US English |
||||
version of the strings, e.g. to grep some error message or other |
||||
output. |
||||
|
||||
To smoke out issues like these Git can be compiled with gettext poison |
||||
support, at the top-level: |
||||
|
||||
make GETTEXT_POISON=YesPlease |
||||
|
||||
That'll give you a git which emits gibberish on every call to |
||||
gettext. It's obviously not meant to be installed, but you should run |
||||
the test suite with it: |
||||
|
||||
cd t && prove -j 9 ./t[0-9]*.sh |
||||
|
||||
If tests break with it you should inspect them manually and see if |
||||
what you're translating is sane, i.e. that you're not translating |
||||
plumbing output. |
||||
|
||||
If not you should replace calls to grep with test_i18ngrep, or |
||||
test_cmp calls with test_i18ncmp. If that's not enough you can skip |
||||
the whole test by making it depend on the C_LOCALE_OUTPUT |
||||
prerequisite. See existing test files with this prerequisite for |
||||
examples. |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
# Icelandic translations for Git. |
||||
# Copyright (C) 2010 Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
||||
# This file is distributed under the same license as the Git package. |
||||
# Ævar Arnfjörð Bjarmason <avarab@gmail.com>, 2010. |
||||
# |
||||
msgid "" |
||||
msgstr "" |
||||
"Project-Id-Version: Git\n" |
||||
"Report-Msgid-Bugs-To: Git Mailing List <git@vger.kernel.org>\n" |
||||
"POT-Creation-Date: 2010-09-20 14:44+0000\n" |
||||
"PO-Revision-Date: 2010-06-05 19:06 +0000\n" |
||||
"Last-Translator: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n" |
||||
"Language-Team: Git Mailing List <git@vger.kernel.org>\n" |
||||
"Language: is\n" |
||||
"MIME-Version: 1.0\n" |
||||
"Content-Type: text/plain; charset=UTF-8\n" |
||||
"Content-Transfer-Encoding: 8bit\n" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.c:5 |
||||
msgid "See 'git help COMMAND' for more information on a specific command." |
||||
msgstr "Sjá 'git help SKIPUN' til að sjá hjálp fyrir tiltekna skipun." |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.c:10 |
||||
msgid "TEST: A C test string" |
||||
msgstr "TILRAUN: C tilraunastrengur" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.c:13 |
||||
#, c-format |
||||
msgid "TEST: A C test string %s" |
||||
msgstr "TILRAUN: C tilraunastrengur %s" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.c:16 |
||||
#, c-format |
||||
msgid "TEST: Hello World!" |
||||
msgstr "TILRAUN: Halló Heimur!" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.c:19 |
||||
#, c-format |
||||
msgid "TEST: Old English Runes" |
||||
msgstr "TILRAUN: ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.c:22 |
||||
#, c-format |
||||
msgid "TEST: ‘single’ and “double” quotes" |
||||
msgstr "TILRAUN: ‚einfaldar‘ og „tvöfaldar“ gæsalappir" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.sh:8 |
||||
msgid "TEST: A Shell test string" |
||||
msgstr "TILRAUN: Skeljartilraunastrengur" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.sh:11 |
||||
#, sh-format |
||||
msgid "TEST: A Shell test $variable" |
||||
msgstr "TILRAUN: Skeljartilraunastrengur með breytunni $variable" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.perl:8 |
||||
msgid "TEST: A Perl test string" |
||||
msgstr "TILRAUN: Perl tilraunastrengur" |
||||
|
||||
#. TRANSLATORS: This is a test. You don't need to translate it. |
||||
#: t/t0200/test.perl:11 |
||||
#, perl-format |
||||
msgid "TEST: A Perl test variable %s" |
||||
msgstr "TILRAUN: Perl tilraunastrengur með breytunni %s" |
||||
|
||||
#. TRANSLATORS: The first '%s' is either "Reinitialized |
||||
#. existing" or "Initialized empty", the second " shared" or |
||||
#. "", and the last '%s%s' is the verbatim directory name. |
||||
#: builtin/init-db.c:355 |
||||
#, c-format |
||||
msgid "%s%s Git repository in %s%s\n" |
||||
msgstr "%s%s Git lind í %s%s\n" |
||||
|
||||
#: builtin/init-db.c:356 |
||||
msgid "Reinitialized existing" |
||||
msgstr "Endurgerði" |
||||
|
||||
#: builtin/init-db.c:356 |
||||
msgid "Initialized empty" |
||||
msgstr "Bjó til tóma" |
||||
|
||||
#: builtin/init-db.c:357 |
||||
msgid " shared" |
||||
msgstr " sameiginlega" |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason |
||||
# |
||||
|
||||
. ./test-lib.sh |
||||
|
||||
GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/locale" |
||||
GIT_PO_PATH="$GIT_BUILD_DIR/po" |
||||
export GIT_TEXTDOMAINDIR GIT_PO_PATH |
||||
|
||||
. "$GIT_BUILD_DIR"/git-sh-i18n |
||||
|
||||
if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON |
||||
then |
||||
# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian |
||||
is_IS_locale=$(locale -a | sed -n '/^is_IS\.[uU][tT][fF]-*8$/{ |
||||
p |
||||
q |
||||
}') |
||||
# is_IS.ISO8859-1 on Solaris and FreeBSD, is_IS.iso88591 on Debian |
||||
is_IS_iso_locale=$(locale -a | sed -n '/^is_IS\.[iI][sS][oO]8859-*1$/{ |
||||
p |
||||
q |
||||
}') |
||||
|
||||
# Export them as an environment variable so the t0202/test.pl Perl |
||||
# test can use it too |
||||
export is_IS_locale is_IS_iso_locale |
||||
|
||||
if test -n "$is_IS_locale" && |
||||
test $GIT_INTERNAL_GETTEXT_SH_SCHEME != "fallthrough" |
||||
then |
||||
# Some of the tests need the reference Icelandic locale |
||||
test_set_prereq GETTEXT_LOCALE |
||||
|
||||
# Exporting for t0202/test.pl |
||||
GETTEXT_LOCALE=1 |
||||
export GETTEXT_LOCALE |
||||
say "# lib-gettext: Found '$is_IS_locale' as an is_IS UTF-8 locale" |
||||
else |
||||
say "# lib-gettext: No is_IS UTF-8 locale available" |
||||
fi |
||||
|
||||
if test -n "$is_IS_iso_locale" && |
||||
test $GIT_INTERNAL_GETTEXT_SH_SCHEME != "fallthrough" |
||||
then |
||||
# Some of the tests need the reference Icelandic locale |
||||
test_set_prereq GETTEXT_ISO_LOCALE |
||||
|
||||
say "# lib-gettext: Found '$is_IS_iso_locale' as an is_IS ISO-8859-1 locale" |
||||
else |
||||
say "# lib-gettext: No is_IS ISO-8859-1 locale available" |
||||
fi |
||||
fi |
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason |
||||
# |
||||
|
||||
test_description='Gettext support for Git' |
||||
|
||||
. ./lib-gettext.sh |
||||
|
||||
test_expect_success "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" ' |
||||
test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME" |
||||
' |
||||
|
||||
test_expect_success 'sanity: $TEXTDOMAIN is git' ' |
||||
test $TEXTDOMAIN = "git" |
||||
' |
||||
|
||||
test_expect_success 'xgettext sanity: Perl _() strings are not extracted' ' |
||||
! grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po |
||||
' |
||||
|
||||
test_expect_success 'xgettext sanity: Comment extraction with --add-comments' ' |
||||
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l >expect && |
||||
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success 'xgettext sanity: Comment extraction with --add-comments stops at statements' ' |
||||
! grep "This is a phony" "$GIT_PO_PATH"/is.po && |
||||
! grep "the above comment" "$GIT_PO_PATH"/is.po |
||||
' |
||||
|
||||
test_expect_success GETTEXT 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease' ' |
||||
test -d "$TEXTDOMAINDIR" && |
||||
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR" |
||||
' |
||||
|
||||
test_expect_success GETTEXT 'sanity: Icelandic locale was compiled' ' |
||||
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo" |
||||
' |
||||
|
||||
# TODO: When we have more locales, generalize this to test them |
||||
# all. Maybe we'll need a dir->locale map for that. |
||||
test_expect_success GETTEXT_LOCALE 'sanity: gettext("") metadata is OK' ' |
||||
# Return value may be non-zero |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "" >zero-expect && |
||||
grep "Project-Id-Version: Git" zero-expect && |
||||
grep "Git Mailing List <git@vger.kernel.org>" zero-expect && |
||||
grep "Content-Type: text/plain; charset=UTF-8" zero-expect && |
||||
grep "Content-Transfer-Encoding: 8bit" zero-expect |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'sanity: gettext(unknown) is passed through' ' |
||||
printf "This is not a translation string" >expect && |
||||
gettext "This is not a translation string" >actual && |
||||
eval_gettext "This is not a translation string" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
# xgettext from C |
||||
test_expect_success GETTEXT_LOCALE 'xgettext: C extraction of _() and N_() strings' ' |
||||
printf "TILRAUN: C tilraunastrengur" >expect && |
||||
printf "\n" >>expect && |
||||
printf "Sjá '\''git help SKIPUN'\'' til að sjá hjálp fyrir tiltekna skipun." >>expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A C test string" >actual && |
||||
printf "\n" >>actual && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "See '\''git help COMMAND'\'' for more information on a specific command." >>actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'xgettext: C extraction with %s' ' |
||||
printf "TILRAUN: C tilraunastrengur %%s" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A C test string %s" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
# xgettext from Shell |
||||
test_expect_success GETTEXT_LOCALE 'xgettext: Shell extraction' ' |
||||
printf "TILRAUN: Skeljartilraunastrengur" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Shell test string" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'xgettext: Shell extraction with $variable' ' |
||||
printf "TILRAUN: Skeljartilraunastrengur með breytunni a var i able" >x-expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" variable="a var i able" eval_gettext "TEST: A Shell test \$variable" >x-actual && |
||||
test_cmp x-expect x-actual |
||||
' |
||||
|
||||
# xgettext from Perl |
||||
test_expect_success GETTEXT_LOCALE 'xgettext: Perl extraction' ' |
||||
printf "TILRAUN: Perl tilraunastrengur" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Perl test string" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'xgettext: Perl extraction with %s' ' |
||||
printf "TILRAUN: Perl tilraunastrengur með breytunni %%s" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Perl test variable %s" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'sanity: Some gettext("") data for real locale' ' |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "" >real-locale && |
||||
test -s real-locale |
||||
' |
||||
|
||||
test_done |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
/* This is a phony C program that's only here to test xgettext message extraction */ |
||||
|
||||
const char help[] = |
||||
/* TRANSLATORS: This is a test. You don't need to translate it. */ |
||||
N_("See 'git help COMMAND' for more information on a specific command."); |
||||
|
||||
int main(void) |
||||
{ |
||||
/* TRANSLATORS: This is a test. You don't need to translate it. */ |
||||
puts(_("TEST: A C test string")); |
||||
|
||||
/* TRANSLATORS: This is a test. You don't need to translate it. */ |
||||
printf(_("TEST: A C test string %s"), "variable"); |
||||
|
||||
/* TRANSLATORS: This is a test. You don't need to translate it. */ |
||||
printf(_("TEST: Hello World!")); |
||||
|
||||
/* TRANSLATORS: This is a test. You don't need to translate it. */ |
||||
printf(_("TEST: Old English Runes")); |
||||
|
||||
/* TRANSLATORS: This is a test. You don't need to translate it. */ |
||||
printf(_("TEST: ‘single’ and “double” quotes")); |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
# This is a phony Perl program that's only here to test xgettext |
||||
# message extraction |
||||
|
||||
# so the above comment won't be folded into the next one by xgettext |
||||
1; |
||||
|
||||
# TRANSLATORS: This is a test. You don't need to translate it. |
||||
print __("TEST: A Perl test string"); |
||||
|
||||
# TRANSLATORS: This is a test. You don't need to translate it. |
||||
printf __("TEST: A Perl test variable %s"), "moo"; |
||||
|
||||
# TRANSLATORS: If you see this, Git has a bug |
||||
print _"TEST: A Perl string xgettext will not get"; |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
# This is a phony Shell program that's only here to test xgettext |
||||
# message extraction |
||||
|
||||
# so the above comment won't be folded into the next one by xgettext |
||||
echo |
||||
|
||||
# TRANSLATORS: This is a test. You don't need to translate it. |
||||
gettext "TEST: A Shell test string" |
||||
|
||||
# TRANSLATORS: This is a test. You don't need to translate it. |
||||
eval_gettext "TEST: A Shell test \$variable" |
||||
|
||||
# TRANSLATORS: If you see this, Git has a bug |
||||
_("TEST: A Shell string xgettext won't get") |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason |
||||
# |
||||
|
||||
test_description='Perl gettext interface (Git::I18N)' |
||||
|
||||
. ./lib-gettext.sh |
||||
|
||||
if ! test_have_prereq PERL; then |
||||
skip_all='skipping perl interface tests, perl not available' |
||||
test_done |
||||
fi |
||||
|
||||
"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { |
||||
skip_all="Perl Test::More unavailable, skipping test" |
||||
test_done |
||||
} |
||||
|
||||
# The external test will outputs its own plan |
||||
test_external_has_tap=1 |
||||
|
||||
test_external_without_stderr \ |
||||
'Perl Git::I18N API' \ |
||||
"$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl |
||||
|
||||
test_done |
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/perl |
||||
use 5.008; |
||||
use lib (split(/:/, $ENV{GITPERLLIB})); |
||||
use strict; |
||||
use warnings; |
||||
use POSIX qw(:locale_h); |
||||
use Test::More tests => 8; |
||||
use Git::I18N; |
||||
|
||||
my $has_gettext_library = $Git::I18N::__HAS_LIBRARY; |
||||
|
||||
ok(1, "Testing Git::I18N with " . |
||||
($has_gettext_library |
||||
? (defined $Locale::Messages::VERSION |
||||
? "Locale::Messages version $Locale::Messages::VERSION" |
||||
# Versions of Locale::Messages before 1.17 didn't have a |
||||
# $VERSION variable. |
||||
: "Locale::Messages version <1.17") |
||||
: "NO Perl gettext library")); |
||||
ok(1, "Git::I18N is located at $INC{'Git/I18N.pm'}"); |
||||
|
||||
{ |
||||
my $exports = @Git::I18N::EXPORT; |
||||
ok($exports, "sanity: Git::I18N has $exports export(s)"); |
||||
} |
||||
is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N exports everything by default"); |
||||
|
||||
# prototypes |
||||
{ |
||||
# Add prototypes here when modifying the public interface to add |
||||
# more gettext wrapper functions. |
||||
my %prototypes = (qw( |
||||
__ $ |
||||
)); |
||||
while (my ($sub, $proto) = each %prototypes) { |
||||
is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype"); |
||||
} |
||||
} |
||||
|
||||
# Test basic passthrough in the C locale |
||||
{ |
||||
local $ENV{LANGUAGE} = 'C'; |
||||
local $ENV{LC_ALL} = 'C'; |
||||
local $ENV{LANG} = 'C'; |
||||
|
||||
my ($got, $expect) = (('TEST: A Perl test string') x 2); |
||||
|
||||
is(__($got), $expect, "Passing a string through __() in the C locale works"); |
||||
} |
||||
|
||||
# Test a basic message on different locales |
||||
SKIP: { |
||||
unless ($ENV{GETTEXT_LOCALE}) { |
||||
# Can't reliably test __() with a non-C locales because the |
||||
# required locales may not be installed on the system. |
||||
# |
||||
# We test for these anyway as part of the shell |
||||
# tests. Skipping these here will eliminate failures on odd |
||||
# platforms with incomplete locale data. |
||||
|
||||
skip "GETTEXT_LOCALE must be set by lib-gettext.sh for exhaustive Git::I18N tests", 2; |
||||
} |
||||
|
||||
# The is_IS UTF-8 locale passed from lib-gettext.sh |
||||
my $is_IS_locale = $ENV{is_IS_locale}; |
||||
|
||||
my $test = sub { |
||||
my ($got, $expect, $msg, $locale) = @_; |
||||
# Maybe this system doesn't have the locale we're trying to |
||||
# test. |
||||
my $locale_ok = setlocale(LC_ALL, $locale); |
||||
is(__($got), $expect, "$msg a gettext library + <$locale> locale <$got> turns into <$expect>"); |
||||
}; |
||||
|
||||
my $env_C = sub { |
||||
$ENV{LANGUAGE} = 'C'; |
||||
$ENV{LC_ALL} = 'C'; |
||||
}; |
||||
|
||||
my $env_is = sub { |
||||
$ENV{LANGUAGE} = 'is'; |
||||
$ENV{LC_ALL} = $is_IS_locale; |
||||
}; |
||||
|
||||
# Translation's the same as the original |
||||
my ($got, $expect) = (('TEST: A Perl test string') x 2); |
||||
|
||||
if ($has_gettext_library) { |
||||
{ |
||||
local %ENV; $env_C->(); |
||||
$test->($got, $expect, "With", 'C'); |
||||
} |
||||
|
||||
{ |
||||
my ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur'); |
||||
local %ENV; $env_is->(); |
||||
$test->($got, $expect, "With", $is_IS_locale); |
||||
} |
||||
} else { |
||||
{ |
||||
local %ENV; $env_C->(); |
||||
$test->($got, $expect, "Without", 'C'); |
||||
} |
||||
|
||||
{ |
||||
local %ENV; $env_is->(); |
||||
$test->($got, $expect, "Without", 'is'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason |
||||
# |
||||
|
||||
test_description="The Git C functions aren't broken by setlocale(3)" |
||||
|
||||
. ./lib-gettext.sh |
||||
|
||||
test_expect_success 'git show a ISO-8859-1 commit under C locale' ' |
||||
. "$TEST_DIRECTORY"/t3901-8859-1.txt && |
||||
test_commit "iso-c-commit" iso-under-c && |
||||
git show >out 2>err && |
||||
! test -s err && |
||||
grep -q "iso-c-commit" out |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'git show a ISO-8859-1 commit under a UTF-8 locale' ' |
||||
. "$TEST_DIRECTORY"/t3901-8859-1.txt && |
||||
test_commit "iso-utf8-commit" iso-under-utf8 && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" git show >out 2>err && |
||||
! test -s err && |
||||
grep -q "iso-utf8-commit" out |
||||
' |
||||
|
||||
test_done |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason |
||||
# |
||||
|
||||
test_description="Gettext reencoding of our *.po/*.mo files works" |
||||
|
||||
. ./lib-gettext.sh |
||||
|
||||
|
||||
test_expect_success GETTEXT_LOCALE 'gettext: Emitting UTF-8 from our UTF-8 *.mo files / Icelandic' ' |
||||
printf "TILRAUN: Halló Heimur!" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: Hello World!" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'gettext: Emitting UTF-8 from our UTF-8 *.mo files / Runes' ' |
||||
printf "TILRAUN: ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: Old English Runes" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_ISO_LOCALE 'gettext: Emitting ISO-8859-1 from our UTF-8 *.mo files / Icelandic' ' |
||||
printf "TILRAUN: Halló Heimur!" | iconv -f UTF-8 -t ISO8859-1 >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_iso_locale" gettext "TEST: Hello World!" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_ISO_LOCALE 'gettext: Emitting ISO-8859-1 from our UTF-8 *.mo files / Runes' ' |
||||
LANGUAGE=is LC_ALL="$is_IS_iso_locale" gettext "TEST: Old English Runes" >runes && |
||||
|
||||
if grep "^TEST: Old English Runes$" runes |
||||
then |
||||
say "Your system can not handle this complexity and returns the string as-is" |
||||
else |
||||
# Both Solaris and GNU libintl will return this stream of |
||||
# question marks, so it is s probably portable enough |
||||
printf "TILRAUN: ?? ???? ??? ?? ???? ?? ??? ????? ??????????? ??? ?? ????" >runes-expect && |
||||
test_cmp runes-expect runes |
||||
fi |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'gettext: Fetching a UTF-8 msgid -> UTF-8' ' |
||||
printf "TILRAUN: ‚einfaldar‘ og „tvöfaldar“ gæsalappir" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: ‘single’ and “double” quotes" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
# How these quotes get transliterated depends on the gettext implementation: |
||||
# |
||||
# Debian: ,einfaldar' og ,,tvöfaldar" [GNU libintl] |
||||
# FreeBSD: `einfaldar` og "tvöfaldar" [GNU libintl] |
||||
# Solaris: ?einfaldar? og ?tvöfaldar? [Solaris libintl] |
||||
# |
||||
# Just make sure the contents are transliterated, and don't use grep -q |
||||
# so that these differences are emitted under --verbose for curious |
||||
# eyes. |
||||
test_expect_success GETTEXT_ISO_LOCALE 'gettext: Fetching a UTF-8 msgid -> ISO-8859-1' ' |
||||
LANGUAGE=is LC_ALL="$is_IS_iso_locale" gettext "TEST: ‘single’ and “double” quotes" >actual && |
||||
grep "einfaldar" actual && |
||||
grep "$(echo tvöfaldar | iconv -f UTF-8 -t ISO8859-1)" actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_LOCALE 'gettext.c: git init UTF-8 -> UTF-8' ' |
||||
printf "Bjó til tóma Git lind" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_locale" git init repo >actual && |
||||
test_when_finished "rm -rf repo" && |
||||
grep "^$(cat expect) " actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_ISO_LOCALE 'gettext.c: git init UTF-8 -> ISO-8859-1' ' |
||||
printf "Bjó til tóma Git lind" >expect && |
||||
LANGUAGE=is LC_ALL="$is_IS_iso_locale" git init repo >actual && |
||||
test_when_finished "rm -rf repo" && |
||||
grep "^$(cat expect | iconv -f UTF-8 -t ISO8859-1) " actual |
||||
' |
||||
|
||||
test_done |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason |
||||
# |
||||
|
||||
test_description='Gettext Shell poison' |
||||
|
||||
. ./lib-gettext.sh |
||||
|
||||
test_expect_success GETTEXT_POISON "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" ' |
||||
test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME" |
||||
' |
||||
|
||||
test_expect_success GETTEXT_POISON 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is poison' ' |
||||
test "$GIT_INTERNAL_GETTEXT_SH_SCHEME" = "poison" |
||||
' |
||||
|
||||
test_expect_success GETTEXT_POISON 'gettext: our gettext() fallback has poison semantics' ' |
||||
printf "# GETTEXT POISON #" >expect && |
||||
gettext "test" >actual && |
||||
test_cmp expect actual && |
||||
printf "# GETTEXT POISON #" >expect && |
||||
gettext "test more words" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_expect_success GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback has poison semantics' ' |
||||
printf "# GETTEXT POISON #" >expect && |
||||
eval_gettext "test" >actual && |
||||
test_cmp expect actual && |
||||
printf "# GETTEXT POISON #" >expect && |
||||
eval_gettext "test more words" >actual && |
||||
test_cmp expect actual |
||||
' |
||||
|
||||
test_done |
Loading…
Reference in new issue