1

I have a bilingual (english/french) website.

I have custom post type and custom taxonomy with the value 'do nothing' in their translation option, this is a decision made to keep this content untranslated and I want to keep it that way.

I was expecting the content to be available in both the english and french version of the site, but it's not the case. The content is always view within the default language version of the site. Talking with WPML support, only confirm my issue and they always use default language for 'do nothing' content.

I notice that if I add ?lang=fr to the url, the content is display in the french version of the site.

My questions are :

  1. How can I detect if a content have the value 'do nothing', base on the url ?
  2. How can I add on-the-fly the '?lang=fr' to their url for these contents ?
  3. It's possible to do this, without slowing down the site ?

Thanks,

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

3 Answers3

0

You can detect, if content have some value from WPML then you use some constatnt for ex:ICL_LANGUAGE_CODE http://wpml.org/documentation/support/wpml-coding-api/

For custom posttype and custom taxonomies i can recomend : http://wpml.org/faq/how-to-translate-custom-types/

  • Hi Ladislav, Thank for your answer, first, I want to keep my CPT and Taxonomy untranslated, this is a choice that give some benefit to my client. I can elaborate more on that decision, but I don't think it's required to understand my problem. If I understand you correctly, you suggest to test an URL against a constant to know if it translation enable? How does it work? I thought ICL_LANGUAGE_CODE was only returning the code of the current language, not property of a post/taxonomy. – Richer St-Amand Apr 28 '14 at 18:20
0

I'm sorry, soo. you probably need something like this:

$id = icl_object_id($post->ID, 'page', false,ICL_LANGUAGE_CODE);
$page  = is_page($id);

http://wpml.org/documentation/support/creating-multilingual-wordpress-themes/language-dependent-ids/

0

Thanks Ladislav for your proposition,

Using icl_object_id was a good idea, but working on the issue, I realise that I didn't have to bother much about if or not the content had the value 'do nothing' set, because I already knew that, and it won't change. The documentation state that you have to turn off the 'Make themes work multilingual', and it's hard to tell how this will affect the theme, since it's a ThemeForest theme.

I will like to have a truly flexible solution, because that will fixed what I found is an issue with how WPML manage content that doesn't need to be translated.

But, with your suggestion, I continued to look for an answer, and find a beginning of a solution to my issue.

First, to edit the link, I had to set a 'add_filter' that correspond to the type of link I wanted to edit.

add_filter( 'post_type_link', 'add_lang_fr', 10, 2 );
add_filter( 'term_link', 'add_lang_fr', 10, 2 );

And then, I test the url to make sure they match the content that need to have ?lang=fr added.

function add_lang_fr( $url, $post ) {

    if ('fr' == ICL_LANGUAGE_CODE) { // if current language is fr

        if ( 'article' == get_post_type( $post ) || FALSE !== strpos($url, 'article-tag') ) {   // if link goes to a CPT 'article' or have 'article-tag' in url

            return add_query_arg('lang', 'fr', $url); 
        } 
    }

    return ($url);

}

To answer my initial question :

  1. How can I detect if a content have the value 'do nothing', base on the url ? - I use a different way to filter the url that need the ?lang=fr added
  2. How can I add on-the-fly the '?lang=fr' to their url for these contents ? - add_query_arg was the key, since it allows to add query argument on url...which was exactly what I needed.
  3. It's possible to do this, without slowing down the site ? - with this solution I have 150 extra request and +16 sec of loading (the page tested have about 2000 url that have been edited).

It's there a way to reduce the number of call and improve the page loading ?