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.

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

Problem:

How to translate strings in the theme?

Solution:

At the following link, you can see our documentation on how to achieve compatibility for your themes and plugins.

Relevant Documentation:

https://wpml.org/documentation/support/achieving-wpml-compatibility-for-your-themes-and-plugins/

This topic contains 4 replies, has 2 voices.

Last updated by zsoltE-2 2 months, 1 week ago.

Assigned support staff: Itamar.

Author Posts
August 7, 2019 at 2:44 pm #4356077

zsoltE-2

Hi,
I have developed a theme in PHP, where I do not used gettext, but I included translatable strings into my own function. E.g.
<?php r__('this text is translatable to other language' ). ?>

WPML is capable to collect all these strings so that user can translate with String translation or with translation manager?

Regards, Zsolt

August 7, 2019 at 6:06 pm #4357279

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

I don't think that WPML would be able to pick up this string as you present it up here.

<?php r__('this text is translatable to other language' ). ?>

At the following link, you can see our documentation on how to achieve compatibility for your themes and plugins.
https://wpml.org/documentation/support/achieving-wpml-compatibility-for-your-themes-and-plugins/
Nevertheless, we have register hooks which you can use. Please see them in our Hooks API page.
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/?wpvhookcategory=0&wpv-hook=0&wpv_post_search=register&wpv_filter_submit=Submit

I hope that this information is helpful to you.

Regards,
Itamar.

August 8, 2019 at 5:49 am #4359823

zsoltE-2

Hi,
Supposing that I will rewrite all r__() to __() and add the text domain e.g.
r__( 'Magyar szöveg'); -> __( 'Magyar szöveg', 'mythemedomain');

Then I create a po file with English translation? Should this work? Gettext function can handle accented Hungarian characters like 'éáőö' ?

I am asking this because __() function include English text every time.

If the site's language is English which text would be shown: 'Magyar szöveg' or its English translation in po file?

August 8, 2019 at 4:24 pm #4364755

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

I'm not sure that the following function can work because r__() is not a gettext function.

r__( 'Magyar szöveg'); -> __( 'Magyar szöveg', 'mythemedomain');

Why don't you use a gettext function like this?

_e( 'Magyar szöveg'); -> __( 'Magyar szöveg', 'mythemedomain');

You ask: "Gettext function can handle accented Hungarian characters like 'éáőö' ?"
I think that they can.
You ask: "If the site's language is English, which text would be shown: 'Magyar szöveg' or its English translation in po file?"
If English is the only language, then I think that 'Magyar szöveg' will show.

I hope that this answers your questions.

Regards,
Itamar.

August 9, 2019 at 12:20 pm #4370137

zsoltE-2

My issue is resolved now. Thank you!