filter-repo: enable internationalization

Assuming filter-repo will be merged into git.git, use "git" for the
TEXTDOMAIN, and assume its build system will replace "@@LOCALEDIR@@"
appropriately.

Note that the xgettext command used to grab string translations is
nearly identical to the one for C files in git.git; just use
--language=python instead and add --join-existing to avoid overwriting
the po/git.pot file.  In other words, use the command:
    xgettext -o../git/po/git.pot --join-existing --force-po \
        --add-comments=TRANSLATORS: \
        --msgid-bugs-address="Git Mailing List <git@vger.kernel.org>" \
        --from-code=UTF-8 --language=python \
        --keyword=_ --keyword=N_ --keyword="Q_:1,2" \
        git-filter-repo

To create or update the translation, go to git.git/po and run either of:
    msginit --locale=XX
    msgmerge --add-location --backup=off -U XX.po git.pot

Once you've updated the translation, within git.git just build as
normal.  That's all that's needed.

Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
Elijah Newren 2019-03-16 23:40:01 -07:00
parent 0e8a11aa60
commit 7bc87c7f0b
2 changed files with 27 additions and 1 deletions

View File

@ -35,6 +35,7 @@ from __future__ import print_function
import argparse
import collections
import fnmatch
import gettext
import os
import re
import shutil
@ -51,6 +52,30 @@ __all__ = ["Blob", "Reset", "FileChanges", "Commit", "Tag", "Progress",
"string_to_date", "date_to_string",
"record_id_rename", "GitUtils", "FilteringOptions", "RepoFilter"]
def gettext_poison(msg):
if "GIT_TEST_GETTEXT_POISON" in os.environ: # pragma: no cover
return "# GETTEXT POISON #"
return gettext.gettext(msg)
_ = gettext_poison
def setup_gettext():
TEXTDOMAIN="git"
podir = os.environ.get("GIT_TEXTDOMAINDIR") or "@@LOCALEDIR@@"
if not os.path.isdir(podir): # pragma: no cover
podir = None # Python has its own fallback; use that
## This looks like the most straightforward translation of the relevant
## code in git.git:gettext.c and git.git:perl/Git/I18n.pm:
#import locale
#locale.setlocale(locale.LC_MESSAGES, "");
#locale.setlocale(locale.LC_TIME, "");
#locale.textdomain(TEXTDOMAIN);
#locale.bindtextdomain(TEXTDOMAIN, podir);
## but the python docs suggest using the gettext module (which doesn't
## have setlocale()) instead, so:
gettext.textdomain(TEXTDOMAIN);
gettext.bindtextdomain(TEXTDOMAIN, podir);
def _timedelta_to_seconds(delta):
"""
@ -3116,6 +3141,7 @@ class RepoFilter(object):
print("Completely finished after {:.2f} seconds.".format(time.time()-start))
if __name__ == '__main__':
setup_gettext()
args = FilteringOptions.parse_args(sys.argv[1:])
if args.analyze:
RepoAnalyze.run(args)

View File

@ -415,7 +415,7 @@ test_expect_success 'setup analyze_me' '
)
'
test_expect_success '--analyze' '
test_expect_success C_LOCALE_OUTPUT '--analyze' '
(
cd analyze_me &&