• Resolved balavander

    (@balavander)


    Hello,

    I have a custom .php script which forces translating cyrilic letters to latin.
    I have website on Serbian and Russian and I want complete website to be on latin.

    Script worked before.
    After update I noticed that some fields in checkout page are not on latin any more.
    1. Стан, апартман, локал итд.
    2. Град?*
    3. Округ?*
    4. All regions in Serbian are also on cyrilic

    What is changed and how to fix it?
    I checked with theme support, they claim that this is not theme releated, but probably that something in WooCommerce is changed.

    Im sharing my current script which worked before.

    // Function for transliteration from Cyrillic to Latin within entire HTML content
    function cir_to_lat($text) {
    $cirilica = array(
    'А', 'Б', 'В', 'Г', 'Д', '?', 'Е', 'Ж', 'З', 'И', '?', 'К', 'Л', '?', 'М', 'Н', '?', 'О', 'П', 'Р', 'С', 'Т', '?', 'У', 'Ф', 'Х', 'Ц', 'Ч', '?', 'Ш',
    'а', 'б', 'в', 'г', 'д', '?', 'е', 'ж', 'з', 'и', '?', 'к', 'л', '?', 'м', 'н', '?', 'о', 'п', 'р', 'с', 'т', '?', 'у', 'ф', 'х', 'ц', 'ч', '?', 'ш',
    'Ё', 'Й', 'Ц', 'У', 'К', 'Е', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я',
    'ё', 'й', 'ц', 'у', 'к', 'е', 'н', 'г', 'ш', 'щ', 'з', 'х', 'ъ', 'ы', 'ь', 'э', 'ю', 'я'
    );

    $latinica = array(
    'A', 'B', 'V', 'G', 'D', '?', 'E', '?', 'Z', 'I', 'J', 'K', 'L', 'Lj', 'M', 'N', 'Nj', 'O', 'P', 'R', 'S', 'T', '?', 'U', 'F', 'H', 'C', '?', 'D?', '?',
    'a', 'b', 'v', 'g', 'd', '?', 'e', '?', 'z', 'i', 'j', 'k', 'l', 'lj', 'm', 'n', 'nj', 'o', 'p', 'r', 's', 't', '?', 'u', 'f', 'h', 'c', '?', 'd?', '?',
    'Yo', 'J', 'C', 'U', 'K', 'E', 'N', 'G', 'Sh', 'Shch', 'Z', 'Kh', '"', 'Y', "'", 'E', 'Yu', 'Ya',
    'yo', 'j', 'c', 'u', 'k', 'e', 'n', 'g', 'sh', 'shch', 'z', 'kh', '"', 'y', "'", 'e', 'yu', 'ya'
    );

    return str_replace($cirilica, $latinica, $text);

    }

    // Apply transliteration to WooCommerce AJAX fragments (e.g., mini-cart)
    function transliterate_ajax_fragments($fragments) {
    foreach ($fragments as &$fragment) {
    $fragment = cir_to_lat($fragment);
    }
    return $fragments;
    }
    add_filter('woocommerce_add_to_cart_fragments', 'transliterate_ajax_fragments');

    // Apply transliteration to WooCommerce currency symbol and currency text
    function transliterate_currency_symbol($currency_symbol, $currency) {
    return cir_to_lat($currency_symbol);
    }
    add_filter('woocommerce_currency_symbol', 'transliterate_currency_symbol', 10, 2);

    // Apply transliteration to WooCommerce email content, subject, and heading
    function transliterate_woocommerce_email_content($content) {
    return cir_to_lat($content);
    }
    add_filter('woocommerce_email_content', 'transliterate_woocommerce_email_content');
    add_filter('woocommerce_email_subject', 'transliterate_woocommerce_email_content');
    add_filter('woocommerce_email_heading', 'transliterate_woocommerce_email_content');

    // Apply transliteration to gettext strings (including currency)
    function transliterate_woocommerce_strings($translated_text, $text, $domain) {
    return cir_to_lat($translated_text);
    }
    add_filter('gettext', 'transliterate_woocommerce_strings', 10, 3);
    add_filter('gettext_with_context', 'transliterate_woocommerce_strings', 10, 3);

    // Apply transliteration on wp_mail for broader coverage on all email content
    function transliterate_wp_mail($args) {
    $args['message'] = cir_to_lat($args['message']);
    return $args;
    }
    add_filter('wp_mail', 'transliterate_wp_mail');

    // Transliteracija na latinicu pre nego ?to HTML bude prikazan
    function transliterate_html_output($buffer) {
    return cir_to_lat($buffer);
    }

    // Start output buffering to apply transliteration to the entire HTML content
    function start_transliteration_buffer() {
    ob_start('transliterate_html_output');
    }
    function end_transliteration_buffer() {
    ob_end_flush();
    }
    add_action('wp_loaded', 'start_transliteration_buffer');
    add_action('shutdown', 'end_transliteration_buffer');

    // Ensure email is resent in Latin by applying transliteration
    add_action('woocommerce_before_resend_order_emails', function() {
    add_filter('woocommerce_email_content', 'transliterate_woocommerce_email_content');
    });

    // Apply transliteration specifically in WooCommerce Admin
    function transliterate_woocommerce_admin_text($translated_text, $text, $domain) {
    // Only apply within WooCommerce admin screens
    if (is_admin() && isset($_GET['post_type']) && $_GET['post_type'] === 'shop_order') {
    return cir_to_lat($translated_text);
    }
    return $translated_text;
    }
    add_filter('gettext', 'transliterate_woocommerce_admin_text', 10, 3);
    add_filter('gettext_with_context', 'transliterate_woocommerce_admin_text', 10, 3);

    // Transliterate WooCommerce currency symbol in Admin
    function transliterate_admin_currency_symbol($currency_symbol, $currency) {
    if (is_admin()) {
    return cir_to_lat($currency_symbol);
    }
    return $currency_symbol;
    }
    add_filter('woocommerce_currency_symbol', 'transliterate_admin_currency_symbol', 10, 2);

    // Force transliteration on manual emails sent via WooCommerce
    function transliterate_manual_woocommerce_emails($email) {
    $email->subject = cir_to_lat($email->subject);
    $email->heading = cir_to_lat($email->heading);
    $email->content = cir_to_lat($email->content);
    }
    add_action('woocommerce_email', 'transliterate_manual_woocommerce_emails');

    // Apply transliteration in Admin using output buffering
    function start_admin_transliteration_buffer() {
    if (is_admin()) {
    ob_start('transliterate_html_output');
    }
    }
    function end_admin_transliteration_buffer() {
    if (is_admin()) {
    ob_end_flush();
    }
    }
    add_action('admin_init', 'start_admin_transliteration_buffer');
    add_action('shutdown', 'end_admin_transliteration_buffer');

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    I can understand your concern, Please note that WordPress 6.7, which is likely to be released on?November 12, 2024,?changes the way translations are loaded, aligning with?best practices for internationalization. This shift affects how and when translation strings should be triggered, aiming to prevent potential issues that arise from loading translations too early. For more details you can use this article: https://developer.woocommerce.com/2024/11/11/developer-advisory-translation-loading-changes-in-wordpress-6-7/

    It seems this update may have caused some issues for you as well. Please note that we do not provide support for customizations. If you need more in-depth support or want to consider professional assistance for customization, I can recommend?WooExperts?and?Codeable.io?as options for getting professional help. Alternatively, you can also ask your development questions in the??WooCommerce Community Slack?as custom code falls outside our usual?scope of support.

    Thank you.

    Thread Starter balavander

    (@balavander)

    This custom code is nothing special.
    It adds filter and forces changing letters from cyrilic to latin.

    I just need to understand what changed and how to address this change.
    Since only for those strings filter is not working, which means that they are somehow “special”.

    Do you know which filter needs to be used to select them and apply translation on them as well?
    I also noticed that Loco Translate and Translate Press plugins are not able to force translation on them.
    Which is really annoying.

    Plugin Support Jonayed (woo-hc)

    (@jonayedhosen)

    Hi @balavander ,

    I understand the recent WordPress 6.7 update is causing issues with your custom script for transliterating Cyrillic to Latin characters.

    With WordPress 6.7, translation loading now happens at the?init?action or later to improve compatibility. This means any translation functions or filters applied before?init?may not work properly. To ensure your script works, you’ll need to adjust the timing of your hooks. For example, you can apply your transliteration function to the?gettext?filter like this:

    add_action('init', function() {
    add_filter('gettext', 'transliterate_woocommerce_strings', 10, 3);
    // Add other filters here
    });

    From your notes, it seems that even plugins like Loco Translate or TranslatePress are struggling with these changes. This likely points to the timing of when translations are loaded. Make sure these plugins are updated, as they may have addressed compatibility with WordPress 6.7.

    If adjusting hook priorities doesn’t resolve the issue, you might need to involve a developer. They can help ensure your script aligns with the new translation-loading behavior and troubleshoot any additional conflicts. While we can’t assist directly with custom code, services like WooExperts or Codeable.io are great for professional help.

    I hope this helps! Let us know how it goes.

    Thread Starter balavander

    (@balavander)

    I tried several ways to incorporate your suggestion.
    Those 3 problematic strings stays the same.

    They are somehow different then others.
    I dont understand why.

    Plugin Support Mahfuzur Rahman(woo-hc)

    (@mahfuzurwp)

    Hi @balavander,

    Thank you for sharing the detailed information about the issue and your script! I understand how important it is for your site to be fully displayed in Latin text.

    Please note that we can’t provide support for custom code as per our support policy. Since this involves custom code, I recommend reaching out to one of the experts listed on our WooCommerce Customization page. They can help refine your script to ensure it translates all fields correctly.

    Thread Starter balavander

    (@balavander)

    Ok!

    I understand what are you saying.
    If this is the case, then I would like to send a feature request.
    Please support latin language as default language for Serbian.
    Since many people are strugguling with the same issue and use different 3rd party plugins to do this.

    I just wanted to do it myself and it worked correctly until the latest update.
    That’s why first I was asking for help here.

    Support Serbian latin please.

    Plugin Support Zubair Zahid (woo-hc)

    (@doublezed2)

    Hello balavander,

    Thank you for your reply.

    You can submit a feature request at our portal here.
    Once you submit it will go through the due process.

    Please don’t hesitate to contact us again if you have more questions or concerns.
    We are here to help ??

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.