• Resolved Lovro Hrust

    (@lovor)


    Hello,
    how to get category title in another language in php? I am using get_category_by_slug($category_slug)->name to get category name and it functions in default language, but in another not.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Lovro Hrust

    (@lovor)

    I managed to solve the problem. It was an AJAX call, so language was not set correctly, due to hack employed to use always default language first, regardless of browser settings.
    However, I passed original language value from javascript back into PHP and set current language to one that was active when page was loaded

    
    	$language_slug = $_GET['lang'];
    	$language = nLingual\Registry::get_language($language_slug);
    	nLingual\Registry::set_language($language);
    

    however, I have another problem, I have to get post (post object or id) in default language if I know $post object from another language. Is there any method for that?

    Plugin Author Doug Wollison

    (@dougwollison)

    I have to get post (post object or id) in default language if I know $post object from another language. Is there any method for that?

    Sorry, can you rephrase that? I don’t quite understand the question.

    Thread Starter Lovro Hrust

    (@lovor)

    I was wondering how to get post content in default language by using get_post function. For that, I needed an ID of post in default language and I had $post object in another language.

    I managed to solve that and the rest of problems that I had. However, I had to inspect code for quite a while to do that. I am considering adding most needed functions as a interface to existing objects and methods and documenting that.

    Plugin Author Doug Wollison

    (@dougwollison)

    Sorry about the delay.

    To get the translation of a given post in a given language, you can use the following code:

    
    $default_language = nLingual\Registry::default_language();
    $translated_post_id = nLingual\Translator::get_post_translation( $post_id, $default_language );
    

    The latter method is a shortcut to the get_object_translation method, since I went a bit overboard future proofing this to handle objects other than posts. I apparently also did a poor job tagging the code so your editor’s autocomplete can’t event recognize it. I’ll brush up on my phpDoc stuff and see about at least fixing that.

    I’m going to also try and finally start writing a codex/wiki for the plugin; documenting all the public-use functions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Translated category’ is closed to new replies.