Skip to content

Commit d606483

Browse files
committed
IMPROVEMENT: Portuguse translation
1 parent 1c0912d commit d606483

File tree

6 files changed

+131
-57
lines changed

6 files changed

+131
-57
lines changed

MethodicConfigurator/frontend_tkinter_connection_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def reconnect(self, selected_connection: str = "") -> bool: # defaults to auto-
132132
self.previous_selection = self.flight_controller.comport.device
133133
if self.destroy_parent_on_connect:
134134
self.parent.root.destroy()
135-
if self.download_params_on_connect and hasattr(self.parent, _("download_flight_controller_parameters")):
135+
if self.download_params_on_connect and hasattr(self.parent, "download_flight_controller_parameters"):
136136
self.parent.download_flight_controller_parameters(redownload=False)
137137
return False
138138

MethodicConfigurator/locale/MethodicConfigurator.pot

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
8-
"POT-Creation-Date: 2024-11-20 18:33+0100\n"
8+
"POT-Creation-Date: 2024-11-20 21:54+0100\n"
99
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1010
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1111
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -821,10 +821,6 @@ msgstr ""
821821
msgid "Connection step {} of {}"
822822
msgstr ""
823823

824-
#: MethodicConfigurator/frontend_tkinter_connection_selection.py:135
825-
msgid "download_flight_controller_parameters"
826-
msgstr ""
827-
828824
#: MethodicConfigurator/frontend_tkinter_connection_selection.py:151
829825
msgid "Flight controller connection"
830826
msgstr ""
Binary file not shown.

MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: 0.9.9\n"
8-
"POT-Creation-Date: 2024-11-20 18:33+0100\n"
9-
"PO-Revision-Date: 2024-11-20 19:23+0100\n"
8+
"POT-Creation-Date: 2024-11-20 21:54+0100\n"
9+
"PO-Revision-Date: 2024-11-20 21:55+0100\n"
1010
"Last-Translator: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>\n"
1111
"Language-Team: \n"
1212
"Language: pt\n"
@@ -997,10 +997,6 @@ msgstr "Conectando com o FC"
997997
msgid "Connection step {} of {}"
998998
msgstr "Passo de conexão {} de {}"
999999

1000-
#: MethodicConfigurator/frontend_tkinter_connection_selection.py:135
1001-
msgid "download_flight_controller_parameters"
1002-
msgstr "download_flight_controller_parameters"
1003-
10041000
#: MethodicConfigurator/frontend_tkinter_connection_selection.py:151
10051001
msgid "Flight controller connection"
10061002
msgstr "Conexão do controlador de voo"
@@ -1573,7 +1569,7 @@ msgstr "Não disponível"
15731569

15741570
#: MethodicConfigurator/frontend_tkinter_parameter_editor.py:253
15751571
msgid "This parameter is not available on the connected flight controller"
1576-
msgstr "Este parâmetro não está dísponivel no controlador de voo conectado."
1572+
msgstr "Este parâmetro não está dísponivel no controlador de voo conectado"
15771573

15781574
#: MethodicConfigurator/frontend_tkinter_parameter_editor.py:255
15791575
msgid "Not editable"
@@ -1693,7 +1689,7 @@ msgstr "3. Use "
16931689
#: MethodicConfigurator/frontend_tkinter_parameter_editor.py:362
16941690
#: MethodicConfigurator/frontend_tkinter_parameter_editor_table.py:238
16951691
msgid "Del"
1696-
msgstr "Del"
1692+
msgstr "Rem"
16971693

16981694
#: MethodicConfigurator/frontend_tkinter_parameter_editor.py:363
16991695
msgid " and "

MethodicConfigurator/locale/pt/LC_MESSAGES/extract_missing_translations.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

extract_missing_translations.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator
5+
6+
SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas <[email protected]>
7+
8+
SPDX-License-Identifier: GPL-3.0-or-later
9+
"""
10+
11+
import argparse
12+
import gettext
13+
import glob
14+
import os
15+
16+
17+
def parse_arguments() -> argparse.Namespace:
18+
parser = argparse.ArgumentParser(description="Extract missing translations from a .po (GNU gettext) file.")
19+
20+
# Add argument for language code
21+
parser.add_argument(
22+
"--lang-code",
23+
default="zh_CN",
24+
type=str,
25+
help="The language code for which to extract missing translations (e.g., 'zh_CN', 'pt'). Defaults to %(default)s",
26+
)
27+
28+
# Add argument for output file
29+
parser.add_argument(
30+
"--output-file",
31+
default="missing_translation",
32+
type=str,
33+
help="The base name of the file(s) where the missing translations will be written. "
34+
"This file will contain lines in the format 'index:msgid'. Defaults to %(default)s",
35+
)
36+
37+
# Add argument for maximum number of translations per output file
38+
parser.add_argument(
39+
"--max-translations",
40+
default=80,
41+
type=int,
42+
help="The maximum number of missing translations to write to each output file. Defaults to %(default)s",
43+
)
44+
45+
return parser.parse_args()
46+
47+
48+
def extract_missing_translations(lang_code: str) -> list[tuple[int, str]]:
49+
# Set up the translation catalog
50+
po_file = os.path.join("MethodicConfigurator", "locale", lang_code, "LC_MESSAGES", "MethodicConfigurator.po")
51+
language = gettext.translation(
52+
"MethodicConfigurator", localedir="MethodicConfigurator\\locale", languages=[lang_code], fallback=True
53+
)
54+
55+
# Read the .po file entries
56+
with open(po_file, encoding="utf-8") as f:
57+
lines = f.readlines()
58+
59+
missing_translations: list[tuple[int, str]] = []
60+
61+
# Iterate through lines to find untranslated msgid
62+
msgid = ""
63+
in_msgid = False
64+
for i, f_line in enumerate(lines):
65+
line = f_line.strip()
66+
67+
if line.startswith("msgid "):
68+
msgid = ""
69+
in_msgid = True
70+
71+
if in_msgid and not line.startswith("msgstr "):
72+
line_split = line.split('"')
73+
if len(line_split) > 1:
74+
msgid += '"'.join(line_split[1:-1]) # Get the msgid string
75+
else:
76+
print(f"Error on line {i}")
77+
continue
78+
79+
if in_msgid and line.startswith("msgstr "):
80+
in_msgid = False
81+
# escape \ characters in a string
82+
msgid_escaped = msgid.replace("\\", "\\\\")
83+
# Check if the translation exists
84+
if language.gettext(msgid_escaped) == msgid: # If translation is the same as msgid, it's missing
85+
missing_translations.append((i - 1, msgid))
86+
87+
return missing_translations
88+
89+
90+
def output_to_files(missing_translations: list[tuple[int, str]], output_file_base_name: str, max_translations: int) -> None:
91+
# Remove any existing output files with the same base name
92+
existing_files = glob.glob(f"{output_file_base_name}.txt")
93+
existing_files += glob.glob(f"{output_file_base_name}_*.txt")
94+
95+
for existing_file in existing_files:
96+
os.remove(existing_file)
97+
98+
# Determine the number of files needed
99+
total_missing = len(missing_translations)
100+
num_files = (total_missing // max_translations) + (1 if total_missing % max_translations else 0)
101+
102+
# Write untranslated msgids along with their indices to the output file(s)
103+
for file_index in range(num_files):
104+
start_index = file_index * max_translations
105+
end_index = start_index + max_translations
106+
107+
# Set the name of the output file based on the index
108+
current_output_file = output_file_base_name
109+
current_output_file += f"_{file_index + 1}" if num_files > 1 else ""
110+
current_output_file += ".txt"
111+
112+
# Write untranslated msgids along with their indices to the output file
113+
with open(current_output_file, "w", encoding="utf-8") as f:
114+
for index, item in missing_translations[start_index:end_index]:
115+
f.write(f"{index}:{item}\n")
116+
117+
118+
def main() -> None:
119+
args = parse_arguments()
120+
missing_translations = extract_missing_translations(args.lang_code)
121+
output_to_files(missing_translations, args.output_file, args.max_translations)
122+
123+
124+
if __name__ == "__main__":
125+
main()

0 commit comments

Comments
 (0)