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

Last updated by Itamar 2 months, 2 weeks ago.

Assigned support staff: Itamar.

Author Posts
July 21, 2019 at 2:02 am #4250659

alexanderK-80

I am implementing a persistent WPML configuration to avoid user errors, allow quick setup of sandboxing environment, rapid prototyping, etc.

I have found WP hook "wpml_set_translation_mode_for_post_type" but it is for cpt (custom post type) only. Any way to _programmatically_ set translation mode for custom taxonomies?

Regards,
Alexander.

July 21, 2019 at 9:47 am #4251933

Itamar
Supporter

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

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

Hi, Alexander.

Searching our hooks page, I couldn't find any hook that fits your needs. It might be custom work what you need to achieve here. In any case, I'm consulting our second tier supporters on this issue to see if they have an idea about or if I'm missing anything.

I'll keep you updated here when I have an answer from them.

Thank you for your patience.
Itamar.

July 22, 2019 at 12:35 pm #4257195

Itamar
Supporter

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

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

Hi, Alexander.

Our second tier supporter says that there is no hook to achieve what you want to accomplish with taxonomies. But we can point you to the file where you can find the internal functions \sitepress-multilingual-cms\inc\setup\wpml-settings-helper.class.php
$sitepress is a global object which can be used instead of $this->sitepress

If you are familiar with PHP, you might be able to achieve that with some custom code. But please be aware that it is on your own risk of breaking this in future things will change. Otherwise, at this point, I would suggest you consider contacting one of our certified partners from this link: https://wpml.org/contractors/
Before doing so, please have a look also here:
https://wpml.org/documentation/about-wpml-contractors/what-type-of-work-you-can-expect-from-contractors/

With our contractors, you might get the custom assistance you need to get on with your project.

Best Regards,
Itamar.

July 26, 2019 at 1:35 pm #4289947

alexanderK-80

So for setting taxonomy translation mode, all functions are there and the only thing is missing is a WordPress hook. I was able to fix that in the file class-wpml-api-hook-translation-mode.php:

public function add_hooks() {
		if ( is_admin() ) {
			...
			add_action( 'wpml_set_translation_mode_for_taxonomy', array( $this, 'set_mode_for_taxonomy_type' ), 10, 2 );
		}
	}
/**
	 * @param string $taxonomy_type
	 * @param string $translation_mode any of
	 *                                 `WPML_API_Hook_Translation_Mode::DO_NOT_TRANSLATE`,
	 *                                 `WPML_API_Hook_Translation_Mode::TRANSLATE`,
	 *                                 `WPML_API_Hook_Translation_Mode::DISPLAY_AS_TRANSLATED`
	 */
	public function set_mode_for_taxonomy_type( $taxonomy_type, $translation_mode ) {
		switch ( $translation_mode ) {
			case self::DO_NOT_TRANSLATE:
				$this->settings->set_taxonomy_not_translatable( $taxonomy_type );
				break;

			case self::TRANSLATE:
				$this->settings->set_taxonomy_translatable( $taxonomy_type );
				break;

			case self::DISPLAY_AS_TRANSLATED:
				$this->settings->set_taxonomy_display_as_translated( $taxonomy_type );
				break;
		}
	}

I find it really strange that devs didn't complete this functionality when the fix takes less than 1 minute.

July 28, 2019 at 3:29 pm #4295609

Itamar
Supporter

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

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

Thanks a lot for sharing this solution here.

I'll present it to our second tier supporter, and he'll decide whether to send it to our developers.
Please let me know if you have any other questions about this issue or mark this ticket as resolved.

Thanks,
Itamar.

July 30, 2019 at 8:56 am #4305893

Itamar
Supporter

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

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

Hi.

After consulting our second-tier supporter about this issue, our suggestion to you is to add this as a feature request. You can do it at the following link.
https://wpml.org/suggest-a-new-feature-for-wpml/

Thanks a lot,
Itamar.