my four cents
Select plugins, export csv file, export to google sheets, translate google sheet cells with:
=IF(A2=””, “”, GOOGLETRANSLATE(A2, “en”, “de”))
download csv, name: “input.csv”
all po files splited by plugin name in output dir with related translation .po filename.
import os
import csv
import polib
# Define the paths
input_csv = './input.csv'
output_directory = './output'
# Ensure the output directory exists
os.makedirs(output_directory, exist_ok=True)
# Define the language codes and their corresponding columns
languages = {
'de_DE': 'Deutsch (de_DE)',
'fr_FR': 'Fran?ais (fr_FR)',
'it_IT': 'Italiano (it_IT)',
'tr_TR': 'Türk?e (tr_TR)',
'es_ES': 'Espa?ol (es_ES)',
'pt_PT': 'Português (pt_PT)',
'ar': '??????? (ar)'
}
# Store entries for each source
entries_by_source = {}
# Read the CSV and organize entries by source
with open(input_csv, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
source = row['Source (plugin or theme)']
if source not in entries_by_source:
entries_by_source[source] = {lang_code: [] for lang_code in languages}
for lang_code, lang_column in languages.items():
entry = polib.POEntry(
msgid=row['English (en_GB)'],
msgstr=row[lang_column],
comment=f'TTfP: {source}, {row["String"]}'
)
entries_by_source[source][lang_code].append(entry)
# Create .po files for each source and language
for source, entries in entries_by_source.items():
for lang_code, po_entries in entries.items():
po = polib.POFile()
po.metadata = {
'Project-Id-Version': 'Polylang/3.6.4',
'POT-Creation-Date': '2024-09-14 11:53+0000',
'PO-Revision-Date': '2024-09-14 11:53+0000',
'Language': lang_code,
'MIME-Version': '1.0',
'Content-Type': 'text/plain; charset=utf-8',
'Content-Transfer-Encoding': '8bit',
'X-Polylang-Site-Reference': 'https://intelplug.com',
'X-Source-Language': 'en-GB',
}
# Add the entries to the PO file
po.extend(po_entries)
# Create the output directory for the source if it doesn't exist
source_output_dir = os.path.join(output_directory, source)
os.makedirs(source_output_dir, exist_ok=True)
# Save the PO file
po_file_path = os.path.join(source_output_dir, f"{lang_code}.po")
po.save(po_file_path)
print(f"Saved: {po_file_path}")
print("Translation complete!")
I tried to import the PO file with 890 translations and I still got a 504 error, but the translations appear in the translation tab.