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 a5545d4
Show file tree
Hide file tree
Showing 11 changed files with 3,653 additions and 8 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
2 changes: 1 addition & 1 deletion MethodicConfigurator/internationalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# 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 Down
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,779 changes: 1,779 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')
Loading

0 comments on commit a5545d4

Please sign in to comment.