csv limits – 504 error
-
I selected the plugins and exported them.
First I tried to import 8000 lines with 8 languages but I got a 504 error.
When I upload a csv file with 500 lines and 1 language I see “Translations updated. Items: 0.”In order not to get a 504 error;
How many languages can be imported at the same time?
How many lines should the CSV file have at most?Some plugins (not all) appear to be translated but I don’t know which ones were imported because I keep getting a 504 error.
-
my two cents
Export target langs .po from translations tabpip install polib googletrans==4.0.0-rc1
python translate_po_files.py
import os
import polib
from googletrans import Translator
# Define directories
input_dir = './input/de'
output_dir = './output/de'
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)
# Initialize the Google Translator
translator = Translator()
# Function to translate a .po file
def translate_po_file(input_path, output_path):
po = polib.pofile(input_path)
for entry in po:
if entry.msgstr == entry.msgid or not entry.msgstr: # Translate if msgstr is empty or same as msgid
print(f"Translating: {entry.msgid}")
translated = translator.translate(entry.msgid, src='en', dest='de').text
entry.msgstr = translated
print(f"Translated to: {translated}")
else:
print(f"Skipped (Already translated): {entry.msgid}")
po.save(output_path)
print(f"Translated file saved: {output_path}\n")
# Translate all .po files in the input directory
for filename in os.listdir(input_dir):
if filename.endswith(".po"):
input_path = os.path.join(input_dir, filename)
output_path = os.path.join(output_dir, filename)
print(f"Processing file: {filename}")
translate_po_file(input_path, output_path)
print("Translation complete!")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.
Hello @kiralikbeyin , How much ram do you have available for the PHP process?
It is impossible to manage 8 languages with 512mb ram. I have been using wordpress.com for a long time but this is the first time I am translating.
I tried all of them for this project: google, aws, digitalocean, vultr, elementor hosting, cloudways.
I was able to set up a real speed (they use litespeed server) and smooth running wp only with hostinger. I had some prejudice before but cloud hosting is really good, I recommend it to everyone.
It said there was a 20% discount; https://cart.hostinger.com/pay/2acbfd6f-2ee3-4567-a81b-8ef037d9ae8a?_ga=GA1.3.942352702.1711283207…
Now there is something I don’t understand, if I make translations with the ttfb plugin and then disable ttfb, the translations disappear, is this normal? Does the ttfb plugin need to be active all the time after making a translation?
I will try to put the .po .mo files in the language folder of the plugins I am translating in a bit.
I have optimised the translation import process.
Please check in the latest version of the plugin: 3.4.8
- The topic ‘csv limits – 504 error’ is closed to new replies.