• Plugin Author Tim W

    (@timwhitlock)


    Short version:

    If you have translations in Loco Translate’s “Custom” directory, but NOT ALSO installed in the “System” location, Just-in-time text domain loading will NOT LOAD your custom translations.

    Long version:

    When WordPress loads a text domain via _load_textdomain_just_in_time, the “System” translations must exist, or the text domain loading process stops dead. This prevents Loco Translate (or any plugin) from loading alternative files.

    There is no fix for this, other than to install the community translations in addition to your custom ones. This is actually the recommended way to customise translations, as shown in this guide.

    The JIT loading problem won’t occur if a plugin (or theme) loads its text domain in advance (using load_plugin_texdomain, or load_theme_textdomain), However, in the case of popular plugins like woocommerce, dependent plugins sometimes request translations in the woocommerce text domain too early and JIT loading will occur before load_plugin_textdomain is called.

    This post is for information only.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Tim W

    (@timwhitlock)

    Loco Translate 2.6.11 uses a new filter in WordPress 6.6 to get around this problem in some circumstances. Specifically, when JIT loading finds no system paths, Loco Translate’s custom folder will be used if it contains any files.

    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.

    #!/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 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.