• Resolved learnee

    (@learnee)


    Here is a quick solution to the problem with the location of language files with translation in WordPress 6.7 – which I myself have successfully used:
    A ready-made bash script that automatically moves the language files on the whole server from the plugin folder, to the system folders.

    As a result, you don’t need to do anything else on the sites themselves (even if there are a lot of them)? ??
    Place in the root of the server (or user directory) and run.

    All processes are logged.

    P.S. Or just move your files manually: from ‘/wp-content/languages/loco/plugins/’ to ‘/wp-content/languages/plugins/’, and from ‘/wp-content/languages/loco/themes/’ to ‘/wp-content/languages/themes/’

    #!/bin/bash

    # Set the log file to the current directory
    LOG="$(pwd)/logfile.log"

    # Function for logging
    log_message() {
    echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >> "$LOG"
    }

    # Recursive directory traversal
    find . -type d -path "*/wp-content/languages/loco/plugins" | while read -r dir; do
    # Move files from /wp-content/languages/loco/plugins/ to /wp-content/languages/plugins/
    target_dir="$(echo "$dir" | sed 's|wp-content/languages/loco/plugins|wp-content/languages/plugins|')"
    mkdir -p "$target_dir"
    mv "$dir"/* "$target_dir"
    log_message "Moved files from $dir to $target_dir"
    done

    find . -type d -path "*/wp-content/languages/loco/themes" | while read -r dir; do
    # Move files from /wp-content/languages/loco/themes/ to /wp-content/languages/themes/
    target_dir="$(echo "$dir" | sed 's|wp-content/languages/loco/themes|wp-content/languages/themes|')"
    mkdir -p "$target_dir"
    mv "$dir"/* "$target_dir"
    log_message "Moved files from $dir to $target_dir"
    done

    echo "Script completed."
Viewing 9 replies - 16 through 24 (of 24 total)
  • Plugin Author Tim W

    (@timwhitlock)

    The theme is being translated. Unfortunately, plugins are not translated

    Can you please provide details of the plugin problem.

    Thread Starter learnee

    (@learnee)

    Testing on the Eagle Booking plugin.
    I create a new language for it (Ru).
    I edit the text I need.
    If I move (inside the Loco plugin) the language file to the system or author’s – then the translation is pulled. If to the individual (languages/loco/plugins/) – then no.

    • This reply was modified 3 months, 2 weeks ago by learnee.
    Plugin Author Tim W

    (@timwhitlock)

    The first thing I notice is this –

    Notice: Function _load_textdomain_just_in_time was called?incorrectly. Translation loading for the?eagle-booking?domain was triggered too early.

    The warning is new in WordPress 6.7, but the problem has always existed in Loco Translate. It can’t do its job, if it’s not started yet.

    Plugin Author Tim W

    (@timwhitlock)

    You can see from the string debugger that Loco Translate can load the files. But it can’t if the plugin tries to use them too soon.

    /wp-admin/admin.php?page=loco-debug&msgid=Bookings&msgctxt&msgid_plural&n&domain=eagle-booking&locale=ru_RU
    Thread Starter learnee

    (@learnee)

    A working ‘crutch’ that restores the plugin to work.
    Add this code to the end of the /wp-content/plugins/loco-translate/loco.php file
    By changing if(true) to if(false) (at the beginning of the code) – it is easy to enable/disable the script

    if(true) add_action('init', function()
    {
    // Paths for language files
    $plugin_custom_path = WP_CONTENT_DIR . '/languages/loco/plugins/';
    $theme_custom_path = WP_CONTENT_DIR . '/languages/loco/themes/';

    // Array for storing found domains
    $textdomains = [];

    // Function for searching and adding domains based on .mo files
    function find_textdomains_from_files($directory, $locale, &$textdomains)
    {
    // Open the directory and look for all .mo files
    $mo_files = glob($directory . '*.mo');

    // If files are found
    if ($mo_files) {
    foreach ($mo_files as $file) {
    // Checking if the file exists
    if (file_exists($file))
    {
    // Get the file name without extension
    $domain_with_locale = basename($file, '.mo');

    $domain_parts = explode('-', $domain_with_locale); // We split the domain by the '-' symbol

    // If there is a locale at the end, remove the last element of the array
    if (count($domain_parts) > 1 && end($domain_parts) === $locale) {
    array_pop($domain_parts); // Remove the last element (locale)
    }

    // We assemble the domain back from the array
    $domain = implode('-', $domain_parts);

    // Add the domain to the array if it doesn't exist yet
    if (!in_array($domain, $textdomains)) {
    $textdomains[] = $domain;
    }
    }
    }
    }
    }
    $locale = determine_locale(); // Determining the current locale
    //error_log("locale: ".$locale);

    // Trying to find text domains for plugins and themes
    find_textdomains_from_files($plugin_custom_path, $locale, $textdomains);
    find_textdomains_from_files($theme_custom_path, $locale, $textdomains);

    if (!empty($textdomains)) {
    // error_log("Found text domains: " . implode(', ', $textdomains));
    } else {
    //error_log("No text domains registered.");
    return;
    }

    // We go through all registered text domains
    foreach ($textdomains as $domain)
    {
    //error_log("domain: ".$domain);

    // Skipping already loaded domains
    if (is_textdomain_loaded($domain)) {
    //error_log("Text domain '{$domain}' already loaded.");
    continue;
    }

    // Path to translation file for plugins
    $mo_plugin_file = $plugin_custom_path . $domain . '-' . $locale . '.mo';

    if (file_exists($mo_plugin_file)) {
    //error_log("Loading plugin translation for domain '{$domain}' from {$mo_plugin_file}");
    load_textdomain($domain, $mo_plugin_file);
    } else {
    //error_log("No translation file found for plugin domain '{$domain}' at {$mo_plugin_file}");
    }

    // Path to translation file for themes
    $mo_theme_file = $theme_custom_path . $domain . '-' . $locale . '.mo';

    if (file_exists($mo_theme_file)) {
    //error_log("Loading theme translation for domain '{$domain}' from {$mo_theme_file}");
    load_textdomain($domain, $mo_theme_file);
    } else {
    //error_log("No translation file found for theme domain '{$domain}' at {$mo_theme_file}");
    }
    }
    });
    • This reply was modified 3 months, 2 weeks ago by learnee.
    Thread Starter learnee

    (@learnee)

    Good day. Unfortunately, I continue to see a problem on the my test site.

    The plugin sees the language translation file for my plugin (Eagle Booking). But it does not see the theme translation (X Blog).

    I updated to version 2.6.14 – it does not help.

    The test site is pure WordPress. Only two plugins are installed: Loco Translate, Eagle Booking. Only one theme is installed: X Blog

    Is this a problem only for me?

    Plugin Author Tim W

    (@timwhitlock)

    I don’t have a problem with X Blog (Free version) in its own, but I do when I enable eagle booking. Whatever it’s doing, it is the one behaving badly. It invokes early text domain loading as I’ve already pointed out to you.

    There is no fix for this. New FAQ: (please don’t post in it)

    Thread Starter learnee

    (@learnee)

    Tim W, thank you very much for your patience and work.
    For me personally, the solution for now – is to add the find_textdomains_from_files function to my scripts.
    I hope the WordPress developers will also want to look into the situation

    Plugin Author Tim W

    (@timwhitlock)

    Hopefully they will, but actually the fault lies with Eagle Booking, and that should be fixed by them regardless.

    I’m marking this as resolved, because there’s no mystery here. If you want a permanent fix, please contact the Eagle Booking developers and pass on this information.

    Firstly, here’s a stack trace of the plugin trying to retrieve a translation immediately after loading which is wrong behaviour –

    #0 wp-includes/l10n.php(1388): _load_textdomain_just_in_time('eagle-booking') 
    #1 wp-includes/l10n.php(194): get_translations_for_domain('eagle-booking')
    #2 wp-includes/l10n.php(339): translate('370 x 485', 'eagle-booking')
    #3 wp-content/plugins/eagle-booking/core/functions.php(1448): esc_html__('370 x 485', 'eagle-booking')
    #4 wp-content/plugins/eagle-booking/core/functions.php(1468): eb_image_sizes()
    #5 wp-content/plugins/eagle-booking/eagle-booking.php(83): require_once('/home...')
    #6 wp-content/plugins/eagle-booking/eagle-booking.php(42): Eagle_Booking->includes()
    #7 wp-content/plugins/eagle-booking/eagle-booking.php(31): Eagle_Booking->__construct()
    #8 wp-content/plugins/eagle-booking/eagle-booking.php(160): Eagle_Booking::instance()
    #9 wp-content/plugins/eagle-booking/eagle-booking.php(178): Eagle_Booking()

    Worse, it also invokes the same problem in your theme, which in itself is not at fault:

    #1 wp-includes/l10n.php(194): get_translations_for_domain('x-blog') 
    #2 wp-admin/includes/plugin.php(163): translate('X Blog is a sma...', 'x-blog')
    #3 wp-admin/includes/plugin.php(114): _get_plugin_data_markup_translate('home...', Array, true, true)
    #4 wp-content/plugins/eagle-booking/include/licensor.php(126): get_plugin_data('/home...')
    #5 wp-content/plugins/eagle-booking/include/licensor.php(24): EBBase->getCurrentVersion()
    #6 wp-content/plugins/eagle-booking/include/licensor.php(271): EBBase->__construct('/home...')
    #7 wp-content/plugins/eagle-booking/include/licensor.php(547): EBBase::getInstance('/home...')
    #8 wp-content/plugins/eagle-booking/core/admin/license.php(25): EBBase::CheckWPPlugin('', '', NULL, NULL, '/home...')
    #9 wp-content/plugins/eagle-booking/core/admin/license.php(402): EB_LICENSE->__construct()
    #10 wp-content/plugins/eagle-booking/eagle-booking.php(94): require_once('/home...')
    #11 wp-content/plugins/eagle-booking/eagle-booking.php(42): Eagle_Booking->includes()
    #12 wp-content/plugins/eagle-booking/eagle-booking.php(31): Eagle_Booking->__construct()
    #13 wp-content/plugins/eagle-booking/eagle-booking.php(160): Eagle_Booking::instance()
    #14 wp-content/plugins/eagle-booking/eagle-booking.php(178): Eagle_Booking()

    This is why your custom translation files don’t load.

Viewing 9 replies - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.