Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client was unable to find new strings added to their theme for translation in WPML after updating the theme. The strings were not showing up in the WPML string translation scan.
Solution:
We recommended the following steps:
1. Ensure that the strings in the theme's PHP files are correctly formatted without any preceding backslashes in the function calls.
2. Modify the PHP file where the strings are added, specifically removing incorrect syntax or characters that might prevent WPML from recognizing these strings.
3. Rescan the theme for strings via WPML > Theme and plugins localization > Strings in the themes > Scan selected themes for strings.
4. Once the strings appear in the WPML string translation list, proceed with the translation.

If this solution does not resolve your issue, or if it seems outdated, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Kor 3 weeks, 6 days ago.

Assisted by: Kor.

Author Posts
May 17, 2024 at 8:46 am #15638136

Louise Fox

Hi there,

I'm trying to translate new strings that have been added to the theme, but they are not showing up when I run:
Theme and plugins localization > Strings in the themes >
Scan selected themes for strings

Most of the strings are found, however I recently updated the theme and added the following new ones:
\__('Key info', 'granola')
\__('Eligibility Criteria', 'granola')
\__('Frequently Asked Questions', 'granola')

Why are these new ones not being found?

You still have admin access to the site which I granted on a previous support ticket-
https://wpml.org/forums/topic/cannot-translate-gravityforms/

Many thanks,
Louise

May 17, 2024 at 5:28 pm #15640586

Kor
Supporter

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Hello,

Thank you for contacting us. Could you please inform me where I can find the following items on your website? Kindly provide the URL of the page where I can view them:

- Key information
- Eligibility criteria
- Frequently asked questions

Additionally, please specify where you inserted these items into your theme files.

May 20, 2024 at 9:56 am #15644549

Louise Fox

Hi there,

You can find these 3 strings on any of the 'fund' post types, for example -

hidden link
hidden link
hidden link

From the English version - hidden link

Code is in the 'single-fund.php' file within the theme. I can't attach the file so I'll copy the contents below.
Many thanks!

<?php

get_header();

$content = [];
$object = \Granola\WordPress\PageObject::get();

//List all fields that we want to show in sidebar
$fundlabels = ['value_of_grant', 'applications_open_date', 'applications_close_date'];
$sidebar_content = "";

foreach ($fundlabels as $key => $label) {
$fundfieldobj = \get_field_object($label, $object);

$field_label = \Theme\Plugins\WPML::lookupEligibililtyTranslation($fundfieldobj['label']);
$field_value = $fundfieldobj['value'];

if (!empty($field_value)) {
$sidebar_content .= \Granola\Component::get('element', [
'el' => 'dt',
'content' => $field_label,
'classes' => ['label-' . $label],
]);

$sidebar_content .= \Granola\Component::get('element', [
'el' => 'dd',
'content' => $field_value,
'classes' => ['value-' . $label],
]);
}
}

$sidebar = \Granola\Component::get('sidebar', [
'heading' => \__('Key info', 'granola'),
'content' => '<dl class="sidebar__info">' . $sidebar_content . '</dl>',
'classes' => ['sidebar', 'sidebar__fund'],
]);
$content[] = $sidebar;

// Get the main content after sidebar
while (have_posts()) {
the_post();
$content[] = apply_filters('the_content', get_the_content());
}

// Get eligibility criteria and display in

    $criteria_string = '';
    $eligibility = \get_field('eligibility_criteria', $object);
    if ($eligibility) {
    foreach ($eligibility as $criteria) {
    $criteria_string .= '

  • ' . \Theme\Plugins\WPML::lookupEligibililtyTranslation($criteria['label']) . '
  • ';
    }

    $content[] = \Granola\Component::get('element', [
    'el' => 'h3',
    'content' => \__('Eligibility Criteria', 'granola'),
    'classes' => 'wp-block-heading',
    ]);

    $content[] = \Granola\Component::get('element', [
    'el' => 'ul',
    'content' => $criteria_string,
    ]);
    }

    // Get FAQs and display in accordion
    $faqs = \get_field('accordion_items', $object);
    if ($faqs) {
    $args['heading'] = \__('Frequently Asked Questions', 'granola');
    $args['accordion_items'] = $faqs;
    $args['classes'][] = 'accordion__fund-faqs';
    $content[] = \Granola\Component::get('accordion', $args);
    }

    echo \Granola\Component::get('site-main', [
    'header' => \Granola\Component::get('page-header', [
    'object' => $object,
    ]),
    'object' => $object,
    'content' => implode($content),
    ]);

    get_footer();

May 21, 2024 at 10:35 am #15649685

Kor
Supporter

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thank you for your response.

Here's what I've completed:

1. I've installed the file manager plugin as SFTP isn't functioning for me.

2. I've made adjustments to the single-fund.php file. Specifically, on line 35, I've removed the backslash from the code 'heading' => __('Key info', 'granola').

3. I've conducted a scan of the strings, and the amended phrase appears here: hidden link

4. Subsequently, I've translated it, and it appears to be functioning correctly here: hidden link.

Could you please verify?

May 21, 2024 at 11:18 am #15650113

Louise Fox

That is very strange as strings seem to have been picked up from other files with the prefix \__
However the translations are now working - many thanks!

Louise Fox confirmed that the issue was resolved on 2024-05-21 11:18:58.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.