This thread is resolved. Here is a description of the problem and solution.
Problem:
The client needs to get the translated name of a product attribute/taxonomy using PHP.
Solution:
Taxonomies such as in your example have a singular name ("Materiaal"), and a general name ("Product Materiaal").
You can get the translation of either the singular name or the general name, starting with the name in the default language, using the WPML API, specifically the wpml_translate_single_string hook: https://wpml.org/wpml-hook/wpml_translate_single_string/
That takes 4 arguments:
$original_value : in your example, "Materiaal"
$domain : for taxonomies, is "WordPress"
$name : for the singular name of Materiaal it would be "taxonomy singular name: Materiaal"; for the general name of Product Materiaal it would be "taxonomy general name: Product Materiaal"
$language_code : in your example it would be "en" or "de"
Here's a simple function you can define and then call as required:
/** * Function that takes the original name of a taxonomy and returns its translation * * @param $original string : the default language taxonomy name to be translated * @param $singular_or_general string : "singular" or "general" name being translated * @param $language string : language code to translate to */ function wpmlsupp_translate_taxonomy_name( string $original, string $singular_or_general, string $language ) { return apply_filters( 'wpml_translate_single_string', $original, 'WordPress', "taxonomy $singular_or_general name: $original", $language ); }
So to translate "Product Materiaal" to German you would use:
$translated = wpmlsupp_translate_taxonomy_name( 'Product Materiaal', 'general', 'de' );
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.