Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Daedalon

    (@daedalon)

    Here’s the translation found in contact-form-7-fi.po, which is not applied here:

    : modules/select.php:88

    msgid “—Please choose an option—”
    msgstr “—Valitse vaihtoehto—”

    The dash, as it’s rendered here, is & #8212; in the file, minus the space.

    • This reply was modified 4 months, 4 weeks ago by Daedalon.
    • This reply was modified 4 months, 4 weeks ago by Daedalon.
    Thread Starter Daedalon

    (@daedalon)

    Thanks a lot for the great free plugin and the continued efforts to keep it amazing!

    • This reply was modified 4 months, 4 weeks ago by Daedalon.
    • This reply was modified 4 months, 4 weeks ago by Daedalon.
    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    cousinr

    (@cousinr)

    Hello,

    confirm. All plugin translations work except for __( '—Please choose an option—', 'contact-form-7' ) The translation with & #8212; for __( '—Please choose an option—', 'contact-form-7' ) does not work! For privacy reasons, I cannot disclose the website address. But here’s what I can share:

    1. The latest version of the plugin 5.9.8 is currently installed.
    2. Steps that have been taken:
      • Deactivation of all plugins.
      • Forced creation of a .pot template that was missing in the languages folder.
      • Download the stable version of all translation files by following the link from the readme in the languages folder.
      • I tried removing the & #8212; characters in the original code, but that didn’t work either.

    The suggestion “Replace text with a snippet” is not acceptable to me.

    Thanks

    • This reply was modified 2 months ago by cousinr.
    • This reply was modified 2 months ago by cousinr.
    • This reply was modified 2 months ago by cousinr.
    • This reply was modified 2 months ago by cousinr.
    • This reply was modified 2 months ago by cousinr.
    cousinr

    (@cousinr)

    I added this code snippet for debugging purposes:

    add_filter('gettext', function($translated_text, $untranslated_text, $domain) {
    if ($domain === 'contact-form-7') {
    error_log('—Please choose an option—' . $untranslated_text); // Логируем оригинальный текст
    }
    return $translated_text;
    }, 20, 3);

    журнал:

    Here’s what I see in the error.log (I put a space to demonstrate & #8212;) since the site’s system turns into a long tere:

    [25-Sep-2024 11:58:29 UTC] & #8212;Please choose an option& #8212;Contact Forms
    [25-Sep-2024 11:58:29 UTC] & #8212;Please choose an option& #8212;Contact Form
    [25-Sep-2024 11:58:29 UTC] & #8212;Please choose an option& #8212;Spam protection
    [25-Sep-2024 11:58:29 UTC] & #8212;Please choose an option& #8212;Email marketing
    [25-Sep-2024 11:58:29 UTC] & #8212;Please choose an option& #8212;Payments
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Contact Forms
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Contact Form
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Spam protection
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Email marketing
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Payments
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;text
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;email
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;URL
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;tel
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;number
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;date
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;text area
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;drop-down menu
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;checkboxes
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;radio buttons
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;acceptance
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;quiz
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;file
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;submit
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Contact Forms
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Contact Form
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Spam protection
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Email marketing
    [25-Sep-2024 11:58:30 UTC] & #8212;Please choose an option& #8212;Payments
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;text
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;email
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;URL
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;tel
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;number
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;date
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;text area
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;drop-down menu
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;checkboxes
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;radio buttons
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;acceptance
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;quiz
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;file
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;submit
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;text
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;email
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;URL
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;tel
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;number
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;date
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;text area
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;drop-down menu
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;checkboxes
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;radio buttons
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;acceptance
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;quiz
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;file
    [25-Sep-2024 11:58:31 UTC] & #8212;Please choose an option& #8212;submit

    It appears that the string & #8212;Please choose an option& #8212; (& #8212;) is indeed being passed as raw text through the translation function. This indicates that this line is somehow either missing in the translation file, or not properly registered for translation in the template.

    Try a more aggressive approach via str_replace: If for some reason gettext can’t handle this string, you can use a more aggressive approach using the str_replace function to replace the string right in its raw form:

    add_filter('gettext', function($translated_text, $untranslated_text, $domain) {
    if ($domain === 'contact-form-7') {
    $translated_text = str_replace('& #8212;Please choose an option& #8212;', 'Пожалуйста, выберите опцию', $translated_text);
    }
    return $translated_text;
    }, 20, 3);

    Great that the aggressive approach via str_replace worked! This confirms that the string was processed correctly, but the standard translation mechanism via gettext was not able to handle it. Let’s look into why this might have happened.Possible reasons why the original translation didn’t work:

    1. HTML-энкодированные символы (& #8212;):
      • One of the main reasons is the use of HTML-encoded characters — ( & #8212;) for a long dash in a string. When the string goes through the standard gettext function, these characters are not decoded and WordPress sees the string as different from regular text with a dash. This is why the string was not matched with the translation, even though it was in the file.
      • The gettext function expects the string in its pure form, and the encoded characters can prevent the string from being processed correctly.
      • String processing mechanism in Contact Form 7:
        • In some plugins, strings can be processed through special functions before they gettext. This may include operations such as filtering or character replacement. If a string goes through a filter or function that modifies it before passing it to gettext, the translation mechanism will not work. In this case, it could be due to encoded characters.

    How to solve this in the future:

    1. Use pure characters instead of encoded characters:
      • If possible, avoid using encoded characters such as — (& #8212;) in strings that need to be translated. Instead, use normal characters (such as a long dash -) so that the string is processed correctly through gettext.

    So what does the plugin author @takayukister think about this? Can you fix it?

    After all, I would like users who display content in different languages to see each of their translations from the corresponding translation file.

    Thanks

    • This reply was modified 2 months ago by cousinr.
    cousinr

    (@cousinr)

    @takayukister 

    I tried another method

    add_filter('gettext', function($translated_text, $untranslated_text, $domain) {
    if ($domain === 'contact-form-7' && $untranslated_text === '—Please choose an option—') {
    return __('Please choose an option', 'theme-child');
    }
    return $translated_text;
    }, 20, 3);

    This changed the result to Please choose an option. But! The translation didn’t pull up even from the child theme!

    Then I tried the following

    functions.php:
    add_action('wp_enqueue_scripts', 'localize_select_translation');
    function localize_select_translation() {
    // Make sure jQuery is connected
    wp_enqueue_script('jquery');

    // Let's check if Contact Form 7 is used on the page
    if (is_singular() && has_shortcode(get_post()->post_content, 'contact-form-7')) {
    // Connect your JS file
    wp_enqueue_script('select-translation', get_stylesheet_directory_uri() . '/assets/js/select-translation.js', array('jquery'), null, true);

    // Localize translation for use in JS
    wp_localize_script('select-translation', 'selectTranslations', array(
    'pleaseChoose' => __('Please choose an option', 'theme-child'),
    ));
    }
    }

    select-translation.js:
    jQuery(document).ready(function($) {
    // We use the translation passed from PHP
    $('select option').each(function() {
    if ($(this).text() === 'Please choose an option') {
    $(this).text(selectTranslations.pleaseChoose);
    }
    });
    });

    As a result of this manipulation, I got a translated string from the translation file of the child theme. Therefore, the problem lies at the stage of shortcode step processing or contact-form-7 plugin script processing. Something is interfering with translation.

    • This reply was modified 2 months ago by cousinr.
    • This reply was modified 2 months ago by cousinr.
    Hyppolite T.

    (@hyppolitak)

    I encountered the same issue. CF7 plugin author @takayukister recommends using first_as_label option instead of include_blank. I ended up replacing include_blank with first_as_label "—Please choose an option—" to have the exact same placeholder but which can now be translated ??

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