Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

aigarinsh on "[Plugin: Polylang] Translating Custom Post Type & Taxonomy Slugs"

$
0
0

I agree with everybody on this one. Such a feature would make the plugin almost perfect. I have tried others and qTranslate Slug does it.

But with it I ran into a problem that it didn't work on pages as custom post type archives. And the main difference of keeping posts in one or separated depends more on client and website, both versions have bonuses and drawbacks.

For testing purposes I have managed to use different slugs depending on conditions. And the links in menu appear as I want, but I suppose the rewrite is not happening.

For example here is how I register my custom taxonomy:

<br />
function register_my_cpt() {<br />
	$labels = array(<br />
		...<br />
	);<br />
	$args = array(<br />
		'labels'		=> $labels,<br />
		'public'		=> true,<br />
		'menu_position'	=> 5,<br />
		'supports'		=> array( 'title', 'editor', 'thumbnail' ),<br />
		'has_archive'	=> true,<br />
		'rewrite'		=> array( 'slug' => 'menu' )<br />
	);<br />
	register_post_type( 'my_cpt', $args );<br />
}</p>
<p>function register_my_taxonomy() {<br />
	$labels = array(<br />
		...<br />
	);<br />
	$cat_slug = get_translated_cat_slug();<br />
	$args = array(<br />
		'labels'		=> $labels,<br />
		'hierarchical'	=> true,<br />
		'rewrite'		=> array( 'slug' => $cat_slug )<br />
	);<br />
	register_taxonomy( 'my_taxonomy', 'my_cpt', $args );<br />
}</p>
<p>function get_translated_cat_slug() {<br />
	$current_ln = get_bloginfo('language');<br />
	if( empty( $current_ln ) ) return 'default_taxonomy';<br />
	$slugs = array(<br />
		'lv'	=> 'slug-language-lv',<br />
		'en-US'	=> 'slug-language-en',<br />
		'ru-RU'	=> 'slug-language-ru'<br />
	);<br />
	return $slugs[$current_ln];<br />
}<br />

Not the best solution as it changes also slugs for the links to contents in other languages, but that is just for testing. Anyway, I found out that the slugs of the links changed depending on the condition, but the rewrite doesn't happen. Why so? The CPT archive page can be accessed with default slug for all languages (en/slug/). When do the rewrite functions take place? And where are they?

For the current project I could get away even with some hardcoded stuff, but for the future it would be nice to have a place in Admin where you could enter slug translations for all custom post types and taxonomies.


Viewing all articles
Browse latest Browse all 11471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>