Skip to content

Commit

Permalink
FEATURE: Add portuguese translation
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Nov 1, 2024
1 parent 576e40b commit 082577f
Show file tree
Hide file tree
Showing 10 changed files with 1,988 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def rename_fc_connection(self, selected_file):
self.local_filesystem.file_parameters[selected_file].pop(old_name)
logging_info(_("Renaming parameter %s to %s"), old_name, new_name)
info_msg = _("The parameter '{old_name}' was renamed to '{new_name}'.\n"
"to follow the flight controller connection defined in the component editor window.")
"to obey the flight controller connection defined in the component editor window.")
messagebox.showinfo(_("Parameter Renamed"), info_msg.format(**locals()))

def __update_table(self, params, fc_parameters):
Expand Down
11 changes: 8 additions & 3 deletions MethodicConfigurator/internationalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import argparse
import gettext
from os import path as os_path
import builtins

# Do not import nor use logging functions in this file.
# Logging is not yet configured when these functions are called

LANGUAGE_CHOICES = ['en', 'zh_CN']
LANGUAGE_CHOICES = ['en', 'zh_CN', 'pt']


def identity_function(s):
Expand All @@ -39,6 +40,10 @@ def load_translation() -> callable:
locale_dir = os_path.join(script_dir, 'locale')
translation = gettext.translation('MethodicConfigurator', localedir=locale_dir,
languages=[pre_args.language], fallback=False)
translation.install()
# Do not use logging functions here the logging system has not been configured yet
# Do not translate this message, the translation will not work here anyways
print("Loaded %s translation.", pre_args.language)
return translation.gettext
except FileNotFoundError:
# Do not use logging functions here the logging system has not been configured yet
Expand All @@ -48,5 +53,5 @@ def load_translation() -> callable:


# Default to identity function if _ is not already defined
if '_' not in globals():
_ = identity_function
if '_' not in globals() and '_' not in locals() and '_' not in builtins.__dict__:
_ = load_translation()
6 changes: 3 additions & 3 deletions MethodicConfigurator/locale/MethodicConfigurator.pot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# ArduPilot Methodic Configurator.
# Copyright (C) 2024 Amilcar Lucas, ArduPilot.org
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
Expand Down Expand Up @@ -1629,7 +1629,7 @@ msgstr ""
#: MethodicConfigurator/frontend_tkinter_parameter_editor_table.py:179
msgid ""
"The parameter '{old_name}' was renamed to '{new_name}'.\n"
"to follow the flight controller connection defined in the component editor window."
"to obey the flight controller connection defined in the component editor window."
msgstr ""

#: MethodicConfigurator/frontend_tkinter_parameter_editor_table.py:181
Expand Down
Binary file not shown.
1,886 changes: 1,886 additions & 0 deletions MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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 os
import gettext

def extract_missing_translations(po_file, output_file):
# 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, 'r', encoding='utf-8') as f:
lines = f.readlines()

missing_translations = []

# Iterate through lines to find untranslated msgid
for i, line in enumerate(lines):
line = 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')
45 changes: 45 additions & 0 deletions MethodicConfigurator/locale/pt/LC_MESSAGES/insert_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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
'''

def insert_translations(po_file, translations_file, output_file):
with open(po_file, 'r', encoding='utf-8') as f:
lines = f.readlines()

with open(translations_file, 'r', encoding='utf-8') as f:
translations_data = f.read().strip().split('\n')

# Prepare to insert translations
translations = []
for data in translations_data:
index, translation = data.split(':', 1) # Split the index and the translation
translations.append((int(index), translation.strip())) # Store index and translation as tuple

insertion_offset = 0 # To track how many lines we've inserted
# To insert the translations correctly
for index, translation in translations:
# Adjust index accounting for previously inserted lines
adjusted_index = index + insertion_offset

# Check if the next line is an empty msgstr
if (adjusted_index + 1 < len(lines) and
lines[adjusted_index + 1].strip() == 'msgstr ""'):
# Overwrite the empty msgstr line
lines[adjusted_index + 1] = f'msgstr "{translation}"\n'
else:
# Otherwise, insert a new msgstr line
lines.insert(adjusted_index + 1, f'msgstr "{translation}"\n')
insertion_offset += 1 # Increment the offset for each insertion

# Writing back to a new output file
with open(output_file, 'w', encoding='utf-8') as f:
f.writelines(lines)

if __name__ == "__main__":
insert_translations('MethodicConfigurator.po', 'translations.txt', 'updated_MethodicConfigurator.po')
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ArduPilot Methodic Configurator.
# Copyright (C) 2024 ArduPilot.org
# Copyright (C) 2024 Amilcar Lucas, ArduPilot.org
# SakuraRC_Yang <[email protected]>, 2024.
#
msgid ""
Expand Down Expand Up @@ -1645,7 +1645,7 @@ msgstr "将参数 %s 重命名为 %s"
#: MethodicConfigurator/frontend_tkinter_parameter_editor_table.py:179
msgid ""
"The parameter '{old_name}' was renamed to '{new_name}'.\n"
"to follow the flight controller connection defined in the component editor window."
"to obey the flight controller connection defined in the component editor window."
msgstr ""
"参数 '{old_name}' 已重命名为 '{new_name}'。\n"
"以遵循组件编辑器窗口中定义的飞行控制器连接。"
Expand Down
3 changes: 2 additions & 1 deletion windows/ardupilot_methodic_configurator.iss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Type: filesandordirs; Name: "{app}\_internal\MethodicConfigurator\ArduPlane_conf
[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"
Name: "zh_CN"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
Name: "pt"; MessagesFile: "compiler:Languages\Portuguese.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
Expand All @@ -74,7 +75,7 @@ Name: "{userappdata}\.ardupilot_methodic_configurator\vehicles"; Flags: uninsnev

[Icons]
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{userappdata}\.ardupilot_methodic_configurator"; Tasks: desktopicon; IconFilename: "{app}\MethodicConfigurator.ico"; Languages: en
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{userappdata}\.ardupilot_methodic_configurator"; Tasks: desktopicon; IconFilename: "{app}\MethodicConfigurator.ico"; Parameters: "--language {language}"; Languages: zh_CN
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{userappdata}\.ardupilot_methodic_configurator"; Tasks: desktopicon; IconFilename: "{app}\MethodicConfigurator.ico"; Parameters: "--language {language}"; Languages: zh_CN pt
Name: "{group}\Documentation"; Filename: "https://github.com/ArduPilot/MethodicConfigurator/blob/master/USERMANUAL.md"
Name: "{group}\Vehicle Templates"; Filename: "{commonappdata}\.ardupilot_methodic_configurator\vehicle_templates"
Name: "{group}\ArduPilot MethodicConfigurator Forum"; Filename: "https://discuss.ardupilot.org/t/new-ardupilot-methodic-configurator-gui/115038/"
Expand Down

0 comments on commit 082577f

Please sign in to comment.