Skip to content

Commit

Permalink
preparing gettext infra eclipse-sumo#11237
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Oct 9, 2022
1 parent b0738cf commit 832d06d
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
/bin/liblibtracijni.jnilib
/bin/libsumofmi2.dylib
# data dir
/data/locale
/data/po/*.pot
/data/proj
# docs dir, make artifacts
/docs/doxygen
Expand Down
23 changes: 23 additions & 0 deletions data/po/de_gui.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# German translations for sumo package.
# Copyright (C) 2022 THE sumo'S COPYRIGHT HOLDER
# This file is distributed under the same license as the sumo package.
# Automatically generated, 2022.
#
msgid ""
msgstr ""
"Project-Id-Version: sumo\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2022-10-09 18:08+0200\n"
"PO-Revision-Date: 2022-10-09 17:46+0200\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: de\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/micha/sumo/src/guisim_main.cpp:59
msgid "GUI version of the microscopic, multi-modal traffic simulation SUMO."
msgstr ""
"Grafische Version der mikroskopischen, multimodalen Verkehrssimulation SUMO."
39 changes: 39 additions & 0 deletions data/po/de_sumo.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# German translations for sumo package.
# Copyright (C) 2022 THE sumo'S COPYRIGHT HOLDER
# This file is distributed under the same license as the sumo package.
# Automatically generated, 2022.
#
msgid ""
msgstr ""
"Project-Id-Version: sumo\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2022-10-09 18:08+0200\n"
"PO-Revision-Date: 2022-10-09 17:46+0200\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: de\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/micha/sumo/src/sumo_main.cpp:49
msgid "Another interrupt signal received, hard exit."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:52
msgid "Interrupt signal received, trying to exit gracefully."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:88
msgid "A microscopic, multi-modal traffic simulation."
msgstr "Eine mikroskopische, multimodale Verkehrssimulation."

#: /home/micha/sumo/src/sumo_main.cpp:116
#: /home/micha/sumo/src/sumo_main.cpp:125
msgid "Quitting (on error)."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:128
msgid "Quitting (on unknown error)."
msgstr ""
22 changes: 22 additions & 0 deletions data/po/fr_gui.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# French translations for sumo package.
# Copyright (C) 2022 THE sumo'S COPYRIGHT HOLDER
# This file is distributed under the same license as the sumo package.
# Automatically generated, 2022.
#
msgid ""
msgstr ""
"Project-Id-Version: sumo\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2022-10-09 18:08+0200\n"
"PO-Revision-Date: 2022-10-09 17:46+0200\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: fr\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/micha/sumo/src/guisim_main.cpp:59
msgid "GUI version of the microscopic, multi-modal traffic simulation SUMO."
msgstr ""
39 changes: 39 additions & 0 deletions data/po/fr_sumo.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# French translations for sumo package.
# Copyright (C) 2022 THE sumo'S COPYRIGHT HOLDER
# This file is distributed under the same license as the sumo package.
# Automatically generated, 2022.
#
msgid ""
msgstr ""
"Project-Id-Version: sumo\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2022-10-09 18:08+0200\n"
"PO-Revision-Date: 2022-10-09 17:46+0200\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: fr\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/micha/sumo/src/sumo_main.cpp:49
msgid "Another interrupt signal received, hard exit."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:52
msgid "Interrupt signal received, trying to exit gracefully."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:88
msgid "A microscopic, multi-modal traffic simulation."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:116
#: /home/micha/sumo/src/sumo_main.cpp:125
msgid "Quitting (on error)."
msgstr ""

#: /home/micha/sumo/src/sumo_main.cpp:128
msgid "Quitting (on unknown error)."
msgstr ""
82 changes: 82 additions & 0 deletions tools/build/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
# Copyright (C) 2011-2022 German Aerospace Center (DLR) and others.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0/
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the Eclipse
# Public License 2.0 are satisfied: GNU General Public License, version 2
# or later which is available at
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later

# @file i18n.py
# @author Michael Behrisch
# @date 2022-10-08

"""
Prepare gettext pot and po files for all languages.
"""
from __future__ import absolute_import
from __future__ import print_function
import os
import subprocess
import difflib
from glob import glob
from argparse import ArgumentParser


SUMO_HOME = os.environ.get("SUMO_HOME", os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))


def get_args(args=None):
arg_parser = ArgumentParser()
arg_parser.add_argument("-l", "--lang", nargs='*', default=["de", "fr"],
help="languages to process")
return arg_parser.parse_args(args)


def main(args=None):
options = get_args(args)
pot_file = SUMO_HOME + "/data/po/sumo.pot"
gui_pot_file = SUMO_HOME + "/data/po/gui.pot"
pots = {pot_file : [], gui_pot_file : []}
for f in glob(SUMO_HOME + "/src/*.cpp") + glob(SUMO_HOME + "/src/*/*.cpp") + glob(SUMO_HOME + "/src/*/*/*.cpp"):
if "gui" in f[len(SUMO_HOME):] or "netedit" in f[len(SUMO_HOME):]:
pots[gui_pot_file].append(f)
else:
pots[pot_file].append(f)
for pot, sources in pots.items():
subprocess.check_call(["xgettext"] + sources +
["--keyword=TL", "--output=" + pot + ".new", "--package-name=sumo",
"[email protected]"])
has_diff = True
if os.path.exists(pot):
with open(pot) as old, open(pot + ".new") as new:
a = [s for s in old.readlines() if not s.startswith(("#", '"POT-Creation-Date:'))]
b = [s for s in new.readlines() if not s.startswith(("#", '"POT-Creation-Date:'))]
has_diff = list(difflib.unified_diff(a, b))
if has_diff:
os.rename(pot + ".new", pot)
else:
os.remove(pot + ".new")
for lang in options.lang:
po_file = "%s/data/po/%s_%s" % (SUMO_HOME, lang, os.path.basename(pot)[:-1])
if os.path.exists(po_file):
subprocess.check_call(["msgmerge", po_file, pot, "--output-file=" + po_file])
else:
subprocess.check_call(["msginit", "--input=" + pot, "--output=" + po_file,
"--no-translator", "--locale=" + lang])
for lang in options.lang:
po_files = ["%s/data/po/%s_%s" % (SUMO_HOME, lang, os.path.basename(pot)[:-1]) for pot in pots]
merged_po_file = "%s/data/po/%s.po" % (SUMO_HOME, lang)
subprocess.check_call(["msgcat"] + po_files + ["--output-file=" + merged_po_file])
d = "%s/data/locale/%s/LC_MESSAGES" % (SUMO_HOME, lang)
os.makedirs(d, exist_ok=True)
subprocess.check_call(["msgfmt", merged_po_file, "--output-file=%s/sumo.mo" % d])
os.remove(merged_po_file)


if __name__ == "__main__":
main()

0 comments on commit 832d06d

Please sign in to comment.