-
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
576e40b
commit a5545d4
Showing
11 changed files
with
3,653 additions
and
8 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
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
Binary file not shown.
1,779 changes: 1,779 additions & 0 deletions
1,779
MethodicConfigurator/locale/pt/LC_MESSAGES/MethodicConfigurator.po
Large diffs are not rendered by default.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
MethodicConfigurator/locale/pt/LC_MESSAGES/extract_missing_translations.py
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,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
45
MethodicConfigurator/locale/pt/LC_MESSAGES/insert_translations.py
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,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') |
Oops, something went wrong.