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 7 replies, has 2 voices.

Last updated by tsahiR 1 month, 4 weeks ago.

Assigned support staff: Bruno Kos.

Author Posts
August 26, 2019 at 8:30 am #4456825

tsahiR

Hello,

I'm trying to make a custom written plugin show specific data depending on user selection.

In it I have this code:

if(ICL_LANGUAGE_CODE=='nl'){$this->title = ucfirst($this->top->shape) . ' things ';}

I have translated this option (top shape) but it still appears in English.

How do I use WPML here to show the current language's proper input.

Thanks in advance.

August 26, 2019 at 9:35 am #4457203

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

I'm afraid that is a way this is currently coded, it will not work. There are no gettext calls in your code either:
https://wpml.org/forums/topic/using-gettext-for-hard-coded-strings-what-else/
hidden link

While this is how string translations should be retrieved
https://wpml.org/wpml-hook/wpml_translate_single_string/

Your approach with using “ICL_LANGUAGE_CODE”, despite being not wrong, might not work in all situations and might not be reliable.

So I'm afraid there is no quick answer or solution for this, apart from redoing it all or for the most part of it.

At this point, I can only suggest to reach out to our contractors for additional help, as they or specialized in developing multilingual sites and working with WPML:
https://wpml.org/contractors/

Regards,
Bruno Kos

August 26, 2019 at 11:26 am #4457949

tsahiR

Bruno,

Thank you for your response.

Thanks for telling me my choice is not ideal, I'll keep it in mind.

I'd rather do this myself. I have some basic skills. I do not wish to hire a contractor and doubt I will do so.

Either way, what you have said is not very helpful. All I want to do is call the attribute specific selection in the language it is running. It's a very specific function.

August 26, 2019 at 11:49 am #4458143

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

I wish I had some better news for you. However, we do not see that there could be either quickfix for this for some other suggestion, apart from what we already mentioned (using different functions as per our API).

Regards,
Bruno Kos

August 26, 2019 at 12:16 pm #4458353

tsahiR

The solution is __() adding only these lines. I am displeased you say there is no quick fix but this works perfectly. I am also displeased that supposedly you a developer, and another "higher up", could not find the solution.

if(ICL_LANGUAGE_CODE=='es'){$this->title = ucfirst($this->top->shape) . ' unicorns';}

->

if(ICL_LANGUAGE_CODE=='es'){$this->title = __(ucfirst($this->top->shape)) . ' unicorns';}

I have edited this message to be a bit more friendly but I am very displeased I was not sent in the right direction when solution was so simple! I didn't even have to share more of the code than I already did, the few lines I sent were enough and the problem could have been tackled from there.

August 26, 2019 at 12:31 pm #4458499

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Since we don't have the full plugin but only a chunk of it (let alone the full site setup and all the content, including the theme and translations) we can not test it and weren't able to provide any quick solution because we have no guarantees or tests that it would work.

I am very happy that it works now (which is in line with our mentioning gettext calls), however we still need to adhere to this:

Your approach with using “ICL_LANGUAGE_CODE”, despite being not wrong, might not work in all situations and might not be reliable.

Because filters are a way to go and we need to encourage other clients to do the same.

Regards,
Bruno Kos

August 26, 2019 at 1:14 pm #4459089

tsahiR

I'm not going to argue.

I appreciate WPML enough.

Thank you for your help. I appreciate it. I genuinely wish you the best.

August 26, 2019 at 1:28 pm #4459249

tsahiR

Thank you for your help