diff --git a/MethodicConfigurator/frontend_tkinter_connection_selection.py b/MethodicConfigurator/frontend_tkinter_connection_selection.py index b56c3ed..9e88d85 100644 --- a/MethodicConfigurator/frontend_tkinter_connection_selection.py +++ b/MethodicConfigurator/frontend_tkinter_connection_selection.py @@ -132,7 +132,7 @@ def reconnect(self, selected_connection: str = "") -> bool: # defaults to auto- self.previous_selection = self.flight_controller.comport.device if self.destroy_parent_on_connect: self.parent.root.destroy() - if self.download_params_on_connect and hasattr(self.parent, _("download_flight_controller_parameters")): + if self.download_params_on_connect and hasattr(self.parent, "download_flight_controller_parameters"): self.parent.download_flight_controller_parameters(redownload=False) return False diff --git a/MethodicConfigurator/locale/MethodicConfigurator.pot b/MethodicConfigurator/locale/MethodicConfigurator.pot index 06785d2..a7e89e8 100644 --- a/MethodicConfigurator/locale/MethodicConfigurator.pot +++ b/MethodicConfigurator/locale/MethodicConfigurator.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2024-11-20 18:33+0100\n" +"POT-Creation-Date: 2024-11-20 21:54+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -821,10 +821,6 @@ msgstr "" msgid "Connection step {} of {}" msgstr "" -#: MethodicConfigurator/frontend_tkinter_connection_selection.py:135 -msgid "download_flight_controller_parameters" -msgstr "" - #: MethodicConfigurator/frontend_tkinter_connection_selection.py:151 msgid "Flight controller connection" msgstr "" diff --git a/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.mo b/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.mo index e2b3350..4914270 100644 Binary files a/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.mo and b/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.mo differ diff --git a/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po b/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po index c9b05f9..e38171d 100644 --- a/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po +++ b/MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: 0.9.9\n" -"POT-Creation-Date: 2024-11-20 18:33+0100\n" -"PO-Revision-Date: 2024-11-20 19:23+0100\n" +"POT-Creation-Date: 2024-11-20 21:54+0100\n" +"PO-Revision-Date: 2024-11-20 21:55+0100\n" "Last-Translator: Dr.-Ing. Amilcar do Carmo Lucas \n" "Language-Team: \n" "Language: pt\n" @@ -997,10 +997,6 @@ msgstr "Conectando com o FC" msgid "Connection step {} of {}" msgstr "Passo de conexão {} de {}" -#: MethodicConfigurator/frontend_tkinter_connection_selection.py:135 -msgid "download_flight_controller_parameters" -msgstr "download_flight_controller_parameters" - #: MethodicConfigurator/frontend_tkinter_connection_selection.py:151 msgid "Flight controller connection" msgstr "Conexão do controlador de voo" @@ -1573,7 +1569,7 @@ msgstr "Não disponível" #: MethodicConfigurator/frontend_tkinter_parameter_editor.py:253 msgid "This parameter is not available on the connected flight controller" -msgstr "Este parâmetro não está dísponivel no controlador de voo conectado." +msgstr "Este parâmetro não está dísponivel no controlador de voo conectado" #: MethodicConfigurator/frontend_tkinter_parameter_editor.py:255 msgid "Not editable" @@ -1693,7 +1689,7 @@ msgstr "3. Use " #: MethodicConfigurator/frontend_tkinter_parameter_editor.py:362 #: MethodicConfigurator/frontend_tkinter_parameter_editor_table.py:238 msgid "Del" -msgstr "Del" +msgstr "Rem" #: MethodicConfigurator/frontend_tkinter_parameter_editor.py:363 msgid " and " diff --git a/MethodicConfigurator/locale/pt/LC_MESSAGES/extract_missing_translations.py b/MethodicConfigurator/locale/pt/LC_MESSAGES/extract_missing_translations.py deleted file mode 100644 index f57672d..0000000 --- a/MethodicConfigurator/locale/pt/LC_MESSAGES/extract_missing_translations.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 - -""" -This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator - -SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas - -SPDX-License-Identifier: GPL-3.0-or-later -""" - -import gettext -import os - - -def extract_missing_translations(po_file, output_file) -> None: - # Set up the translation catalog - language = gettext.translation("messages", localedir=os.path.dirname(po_file), languages=["zh_CN"], fallback=True) - - # Read the .po file entries - with open(po_file, encoding="utf-8") as f: - lines = f.readlines() - - missing_translations = [] - - # Iterate through lines to find untranslated msgid - for i, f_line in enumerate(lines): - line = f_line.strip() - - if line.startswith("msgid"): - msgid = line.split('"')[1] # Get the msgid string - - # Check if the translation exists - if language.gettext(msgid) == msgid: # If translation is the same as msgid, it's missing - missing_translations.append((i, msgid)) - - # Write untranslated msgids along with their indices to the output file - with open(output_file, "w", encoding="utf-8") as f: - for index, item in missing_translations: - f.write(f"{index}:{item}\n") - - -if __name__ == "__main__": - extract_missing_translations("MethodicConfigurator.po", "missing_translations.txt") diff --git a/extract_missing_translations.py b/extract_missing_translations.py new file mode 100644 index 0000000..3aa4b06 --- /dev/null +++ b/extract_missing_translations.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 + +""" +This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator + +SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas + +SPDX-License-Identifier: GPL-3.0-or-later +""" + +import argparse +import gettext +import glob +import os + + +def parse_arguments() -> argparse.Namespace: + parser = argparse.ArgumentParser(description="Extract missing translations from a .po (GNU gettext) file.") + + # Add argument for language code + parser.add_argument( + "--lang-code", + default="zh_CN", + type=str, + help="The language code for which to extract missing translations (e.g., 'zh_CN', 'pt'). Defaults to %(default)s", + ) + + # Add argument for output file + parser.add_argument( + "--output-file", + default="missing_translation", + type=str, + help="The base name of the file(s) where the missing translations will be written. " + "This file will contain lines in the format 'index:msgid'. Defaults to %(default)s", + ) + + # Add argument for maximum number of translations per output file + parser.add_argument( + "--max-translations", + default=80, + type=int, + help="The maximum number of missing translations to write to each output file. Defaults to %(default)s", + ) + + return parser.parse_args() + + +def extract_missing_translations(lang_code: str) -> list[tuple[int, str]]: + # Set up the translation catalog + po_file = os.path.join("MethodicConfigurator", "locale", lang_code, "LC_MESSAGES", "MethodicConfigurator.po") + language = gettext.translation( + "MethodicConfigurator", localedir="MethodicConfigurator\\locale", languages=[lang_code], fallback=True + ) + + # Read the .po file entries + with open(po_file, encoding="utf-8") as f: + lines = f.readlines() + + missing_translations: list[tuple[int, str]] = [] + + # Iterate through lines to find untranslated msgid + msgid = "" + in_msgid = False + for i, f_line in enumerate(lines): + line = f_line.strip() + + if line.startswith("msgid "): + msgid = "" + in_msgid = True + + if in_msgid and not line.startswith("msgstr "): + line_split = line.split('"') + if len(line_split) > 1: + msgid += '"'.join(line_split[1:-1]) # Get the msgid string + else: + print(f"Error on line {i}") + continue + + if in_msgid and line.startswith("msgstr "): + in_msgid = False + # escape \ characters in a string + msgid_escaped = msgid.replace("\\", "\\\\") + # Check if the translation exists + if language.gettext(msgid_escaped) == msgid: # If translation is the same as msgid, it's missing + missing_translations.append((i - 1, msgid)) + + return missing_translations + + +def output_to_files(missing_translations: list[tuple[int, str]], output_file_base_name: str, max_translations: int) -> None: + # Remove any existing output files with the same base name + existing_files = glob.glob(f"{output_file_base_name}.txt") + existing_files += glob.glob(f"{output_file_base_name}_*.txt") + + for existing_file in existing_files: + os.remove(existing_file) + + # Determine the number of files needed + total_missing = len(missing_translations) + num_files = (total_missing // max_translations) + (1 if total_missing % max_translations else 0) + + # Write untranslated msgids along with their indices to the output file(s) + for file_index in range(num_files): + start_index = file_index * max_translations + end_index = start_index + max_translations + + # Set the name of the output file based on the index + current_output_file = output_file_base_name + current_output_file += f"_{file_index + 1}" if num_files > 1 else "" + current_output_file += ".txt" + + # Write untranslated msgids along with their indices to the output file + with open(current_output_file, "w", encoding="utf-8") as f: + for index, item in missing_translations[start_index:end_index]: + f.write(f"{index}:{item}\n") + + +def main() -> None: + args = parse_arguments() + missing_translations = extract_missing_translations(args.lang_code) + output_to_files(missing_translations, args.output_file, args.max_translations) + + +if __name__ == "__main__": + main()