Skip Navigation

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

Problem:

Taxonomy lables not translated using 'get_taxonomy'

Solution:

Using the following code seems to work.

apply_filters('wpml_translate_single_string', $name, "WordPress", "taxonomy singular name: " . $name)

Relevant Documentation:

https://wpml.org/wpml-hook/wpml_translate_single_string/

100% of people find this useful.

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

Last updated by nicoH 4 years, 7 months ago.

Assisted by: Itamar.

Author Posts
August 17, 2019 at 11:41 am #4409885

nicoH

I am trying to: Get the (translated) taxonomy label by using `get_taxonomy( $taxonomy )->labels->singular_name`.

Link to a page where the issue can be seen: hidden link in index 1, name: "Grösse"

I expected to see: "Taille" as the name of the taxonomy

Instead, I got: "Grösse" as the name of the taxonomy

If I change the line to labels->name "Produit Grösse" is returned which also shows up in string translations but was never manually entered anywhere. It seems this is some kind of automatic translation as the first word is in french and the second in german. I've found multiple similar entries such as https://wpml.org/forums/topic/how-do-i-retrieve-translated-taxonomy-labels/ but they either never explained how the resolved it (https://wpml.org/forums/topic/unable-to-get-the-translated-label-of-a-taxonomy/) or the provided solution doesn't work anymore (like in the first link).

Is this a bug or am I doing something wrong? Thank you for your help!

Screen Shot 2019-08-17 at 13.35.38.png
Screen Shot 2019-08-17 at 13.35.15.png
Screen Shot 2019-08-17 at 13.34.29.png
August 18, 2019 at 7:35 pm #4412673

Itamar
Supporter

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

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

Hi.

Please check our following filter hook.
https://wpml.org/wpml-hook/wpml_translate_single_string/
You should apply this hook in your code in order to retrieve the correct translation of the taxonomy label.

Please let me know if this information is helpful to you.

Regards,
Itamar.

August 21, 2019 at 8:16 pm #4434927

nicoH

I'm sorry for my late reply, there seems to be an issue with sending emails on support responses as I didn't receive an email even tough the setting is "Email notifications only when WPML support posts an answer ". Whatever, back to the main issue: Yes, using

apply_filters('wpml_translate_single_string', $name, "WordPress", "taxonomy singular name: " . $name)

seems to work. Is the prefix "taxonomy singular name" part of the official API for taxonomy label strings or will this code break in a few releases? Thank you very much for you assistance!

August 24, 2019 at 4:48 pm #4452079

Itamar
Supporter

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

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

Hi.

It seems that "taxonomy singular name" in your code is not a label that is coming from WPML. It is probably coming from WordPress itself. I do not think that this label is going to change soon.

Regards,
Itamar.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.