Support » Plugin: Polylang » Show posts from other languages

  • My setup is an English and Greek bilingual installation. However since my visitors understand both languages, their browser defaults may prefer either. But they may never visit the second language, therefore certain untranslated posts won’t be visible to them.

    I want to show posts from all languages in the archives, unless they have a proper translation of course. To keep content semantically and visually separated, I am using the lang attribute and CSS3 to style posts differently.

    I have managed to work around it using code from an older post, but cannot get it to work with the default language.

    I’m afraid my obstacle is inherent to how Polylang works. Is there any chance that we can see this functionality in the plugin Settings? Any way to modify my code to make it work?

    add_filter( 'pre_get_posts', 'get_default_language_posts' );
    function get_default_language_posts( $query ) {
    	if ( $query->is_main_query() && is_home() && function_exists('pll_languages_list') && !is_admin()){
    		$languages = pll_languages_list( array( 'hide_empty' => 1 ) );
    		$terms = get_terms('post_translations');
    		$lang_default =  pll_default_language();
    		$lang_current =  pll_current_language();
    		$post_ids = array();
    
    		foreach($terms as $translation){
    			$transPost = unserialize($translation->description);
    			if($transPost[$lang_current] != 0) { //has no translation in $lang_current
    				$post_ids[]=$transPost[$lang_default];
    			}
    		}
    
    		if($lang_default!=$lang_current){ //without this check, default language returns zero posts
    			$query->set('lang' , join( ',', $languages ) );
    			$query->set('post__not_in', $post_ids);
    		}
    	}
    
    	return $query;
    }
Viewing 15 replies - 1 through 15 (of 17 total)
  • I too would very much like to see this code worked into natively into Polylang. Anybody out there?

    Ps. I contacted Syllabic but did not get a response so far. And, by the way, WPML also cannot do this unless page is on index.

    I’m in the same boat, and it has the same leak. My blog is bilingual German and English.

    This is a conceptual problem. Polylang (and other bi/multilanguage plugins) are presuming an edge case: both blog languages should be more or less “mutually agnosic”, like for example language pairs like German/Vietnamese, Italian/Swedish.

    In these cases Polylang’s concept is OK: The amount of German speakers who also understand Vietnamese is negligible, and viceversa. Fine.

    But the real world is different. Most bilingual blogs are serving on one hand a more or less “minority language” (Vietnamese, German, French, Basque, etc.) and on the other hand the lingua franca of the web, English.

    In these cases the blog author assumes that a considarable amount of the native speakers of the “minority language” (e.g. German) also understands English. (But not viceversa, BTW.)

    Unfortunately a Polylang-featured site delivers the impression to the user that the whole site is translated, each and every article, by hitting the language switcher.

    This is OK for articles that realy exist in both languages, but the non-English native reader will miss all the articles that exist only in English, despite the fact that he’s fully capable of reading English texts. This is especially grave for developing-related categories, where you write 95% of your articles in English.

    Currently I have two approaches to solutions to this problem:

    1) There’s a very interesting plugin for Polylang, called Language Mix. Unfortunately not updated in the last years, and I run into some problems and I didn’t investigate further. A nice and promosing approach, though.

    2) Using the plugin Translation Detector (or any selfmade equivalent): It places an hint on every page where a translation is available. Thus, “negativly” informing the visitor about the fact that other articles may not be translated, but still existent.

    The solution, of course, would be one preferred language, but if not present, not excluding the other language (choosable inside Polylang).

    Just thoughts, as always.


    Tom

    Very well put Tom.

    I have a similar request. Now I have a static homepage, 3 languages (FR, EN, DE), and would like to show the latest posts on the front page, but just in EN. Products & pages are translated, but posts are not, and will never be.
    My frontpage is widgets-only, and I would love to pull just all posts from the EN pages to the other pages.
    And also the side-bar widget on the FR and DE version showing the latest EN posts, and link to these posts.
    Would be absolutely great if this could be done, there are as many visitors for the FR and DE version as for the EN, and I don’t want these to miss out, but also do not want to copy all posts..

    Just a thought, but would be great if in the language selector for the posts a ‘all languages’ could be added..
    I’m going to dream about that..

    It seems like a very in-demand feature.. .

    I put feedback but no response. Not sure if anyone is even considering / working on this request.

    As a work-around I’m putting a custom link under the menu-item for the blog, pointing to the EN version, but it is a shame that the ‘latest posts’ widget will not be working.
    Going to have to put some other content on the home pages of the other languages too.
    I really love the polylang plugin for the rest.. will probably dive in myself to see how to get this done at some point.

    Just a thought, but would be great if in the language selector for the posts a ‘all languages’ could be added..
    I’m going to dream about that..

    That’s more or less what the Language Mix plugin does (see post above).

    But the ugly thing is that the posts that are translated will appear twice (or in your case triple), i.e. in each language.

    So, IMO, the main language selector should remain as it is now, but with an option to show the fallback language (most likely English) if a French or German version of that post does not exist.

    This option could either be only admin-selectable or, better, also visitor-selectable in form of a little checkbox ‘Show English version if no translation is available’. This way a visitor who doesn’t want to see any English posts could easily hide them.

    Unfortunately Language Mix does not work any longer, at least not with Divi theme.

    I would propose to have a simple ‘Display all Languages’ or similar checkbox. When the main language post is not available the next one according to language order / priority is displayed.

    Exactly.

    Hi all,

    I have the same problem here and I also like to have some kind of feature to allow posts to appear in the default language.

    In topic how to display all posts in all languages pages in polylang? there is some kind of voting going on. Perhpas you can join that topic and add your vote too?

    Afraid only way to do this is dive into the code and get it done yourself..
    Great plugin, and a big help so far, but.. it is free (for which my thanks) , in which case I don’t want to complain, and just see what’s under the hood, and modify if possible.
    If only I had some time…

    **dreaming on**

    +1 for this feature.

    I have a 2 language site that also includes woocommerce shop. I’d like to have posts and products returns for either language in search results…

    I’m using a static home page, and the Xtheme…

    Has anyone successfully gotten this to work??

    @heyme,

    I don’t think anyone is complaining about this magnificant plugin which I find also really very very good. But like you, also we are dreaming about features that would make it even better.

    You can always make a donation – like I do for all websites I am using this plugin for – to support Chouby in continuing his great job! If everyone using his plugin would donate 10 euros, that would make programming life for Chouby much more interesting 🙂

    I hope Chouby is listening too!

    +1 as well.
    Same scenario as mentioned above : 2-language site, the homepage and general pages are available in both English and French, but I also have course / lesson / topic custom posts (from LearnDash plugin) that need only be available in EN. But if a FR user accesses one of the LMS posts (e.g. a lesson or topic) the site language automatically switches back to EN, which is not the desired behavior. I think WPML has the notion of non-translatable pages/posts which are displayed in every language. What we need is something similar, e.g. as someone said, adding an “ALL LANGUAGES” option in the page/post language selection drop down list in the dashboard.
    I’m ready to donate for this! or try stuff in code.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Show posts from other languages’ is closed to new replies.