-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c0912d
commit d606483
Showing
6 changed files
with
131 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\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 "" | ||
|
Binary file modified
BIN
-93 Bytes
(100%)
MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.mo
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]>\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 " | ||
|
43 changes: 0 additions & 43 deletions
43
MethodicConfigurator/locale/pt/LC_MESSAGES/extract_missing_translations.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
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() |