From 832d06debd02b56b22923c6d4063ea6acd9a854f Mon Sep 17 00:00:00 2001 From: Michael Behrisch Date: Sun, 9 Oct 2022 18:16:37 +0200 Subject: [PATCH] preparing gettext infra #11237 --- .gitignore | 2 ++ data/po/de_gui.po | 23 +++++++++++++ data/po/de_sumo.po | 39 +++++++++++++++++++++ data/po/fr_gui.po | 22 ++++++++++++ data/po/fr_sumo.po | 39 +++++++++++++++++++++ tools/build/i18n.py | 82 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 207 insertions(+) create mode 100644 data/po/de_gui.po create mode 100644 data/po/de_sumo.po create mode 100644 data/po/fr_gui.po create mode 100644 data/po/fr_sumo.po create mode 100755 tools/build/i18n.py diff --git a/.gitignore b/.gitignore index 22c86a95ee21..256c9a3e47e9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/data/po/de_gui.po b/data/po/de_gui.po new file mode 100644 index 000000000000..09b656e9f700 --- /dev/null +++ b/data/po/de_gui.po @@ -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: sumo-dev@eclipse.org\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." diff --git a/data/po/de_sumo.po b/data/po/de_sumo.po new file mode 100644 index 000000000000..1b68142828c1 --- /dev/null +++ b/data/po/de_sumo.po @@ -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: sumo-dev@eclipse.org\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 "" diff --git a/data/po/fr_gui.po b/data/po/fr_gui.po new file mode 100644 index 000000000000..ab6322702bc0 --- /dev/null +++ b/data/po/fr_gui.po @@ -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: sumo-dev@eclipse.org\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 "" diff --git a/data/po/fr_sumo.po b/data/po/fr_sumo.po new file mode 100644 index 000000000000..009949185c31 --- /dev/null +++ b/data/po/fr_sumo.po @@ -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: sumo-dev@eclipse.org\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 "" diff --git a/tools/build/i18n.py b/tools/build/i18n.py new file mode 100755 index 000000000000..3bea80c7d97d --- /dev/null +++ b/tools/build/i18n.py @@ -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", + "--msgid-bugs-address=sumo-dev@eclipse.org"]) + 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()