• GREAT PROJECT ! (sorry for shouting, but it is 😉 )

    However, I ran into an issue:

    I have a static page as homepage and when setting the language option ‘Add language info to all URLS’s including…’ the site home page accessed via mysite.tld/ gets redirected to the static page URL without language info and then returns a 404 page. The home pages are only available via their respective URLs with language info in it.

    For example mysite.tld gets redirected to mysite.tld/home with a 404 while mysite.tld/en/home/ and mysite.tld/fr/accueil/ are listed in their respective language menus as home pages and can be accessed via those URLs just fine…

    Am I missing something here?

    http://wordpress.org/extend/plugins/polylang/

Viewing 15 replies - 16 through 30 (of 53 total)
  • Plugin Author Chouby

    (@chouby)

    This is almost the only thing Polylang does 😉

    Hmmm… that seems to return the default language rather than the language of the post in the loop.

    Take a look at the news sitemap — created by my plugin, using using your code to get the language; it is actually a feed with special permalink — on http://valentheze.fr/sitemap-news.xml ( or http://valentheze.fr/?feed=sitemap-news ) where the test post is set to FR and the default language is set to NL. In the source of the feed you can see the tag <news:language>nl</news:language> which is not the correct language for this post 🙁

    Correction: it does not seem to be the site default language in the Polylang settings but WPs own Settings > General > Site Language settings that is being returned there…

    Plugin Author Chouby

    (@chouby)

    There is a bug for feeds language since the beginning. The content is filtered by language but the language code is not the right one. I discovered that some days ago.

    The problem was because WordPress does use the option ‘rss_language’ instead of get_locale to set it and I was not aware of this… I know that it will change in WP 3.4.

    Before that, I decided to filter the option ‘rss_language’ to send the right language code. You can download the development version to test and tell me if it solves the issue.

    OK, will revert to get_option(‘rss_language’) and test your dev version! 🙂

    UPDATE: using Polylang 0.8dev1 and standard get_option('rss_language') I get ‘en’ instead of the post language in my custom feed. Despite of the global site language (NL or FR) and the Polylang default language setting…

    Plugin Author Chouby

    (@chouby)

    Sorry… In fact I believed that the issue was coming from this get_option('rss_language') called instead of get_locale() in WordPress feeds.

    But your case is different. You are most probably looking for the language to soon. Since in most cases Polylang does not rely on language code in url to define the language, it is defined quite late, in the ‘wp’ hook.

    But the wp action is run right after the WP object is populated and well before the loop… Or am I msitaken? And in my template, I’m calling get_option(‘rss_language’) from inside the loop.

    Anyway, even if it would show the correct value the first time, the question is if this value would get changed for each post in the loop anyway.

    Plugin Author Chouby

    (@chouby)

    Yes you are right, the wp action is called much before the loop. Here the language is set based on the request. For example, for a post, the language is set to the post’s language.

    For archives and feeds, I need the language code to be included in the url (otherwhise, I could not know if you request archives in English or French…).

    I want to help. Could you explain what is your intended goal?

    OK, to explain: my plugin http://wordpress.org/extend/plugins/xml-sitemap-feed/ creates two custom feeds. One XML Sitemap (/sitemap.xml) and one Google News Sitemap (/sitemap-news.xml) based on two different feed templates. I have made the plugin compatible with qTranslate and xLanguage before but seem to have some trouble with Polylang.

    The standard XML Sitemap template generates a list of all posts and pages on the site with the proper markup for an xml sitemap. With Polylang enabled, the sitemap lists post/pages of different languages in the same feed. This works differently with the other multi-lingual plugins (where the language is part of the URL and so it creates /fr/sitemap.xml listing only French post for example) but that is not a problem. The sitemap protocol does NOT state only links to posts in the same language can be in one sitemap. It behaves the same as a normal feed with Polylang and all is fine.

    The problem arrises when generating the Google News sitemap. The protocol states a language tag needs to be there, reflecting the language of each post… With the other language plugins, several Google News sitemaps get created, one for each language, and using get_option('rss_language') generates the proper tag value for each post (always the same since all posts in each sitemap have the same language). But in Polylang, this method does not work out of the box as it did with the other language plugins ;(

    Fistly, get_option('rss_language') does not return the correct language and secondly, since with Polylang posts of different language will end up in the same feed, I need something that will change when running the loop, depending on the language set for each post.

    Is there a function in Polylang that does this already which I can call from withing my feed template inside the loop? Or a variable like $post->language; for example? Or a post meta value?

    Your help is greatly appreciated. The power of Polylang is its relative simplicity and low impact on resources and as such, a good alternative to other multi-lingual solutions for some of my multi-site installations. That same philosophy caused me to create the XML Sitemap plugin and it would be great if the two could be made to work together. 🙂

    Plugin Author Chouby

    (@chouby)

    I did write the plugin to make things easy and finally you believe it’s more complex with Polylang than with other plugins 🙁

    Well I propose that we work in two times, first with the default permalink structure and second with url rewriting.

    The ‘language’ is a custom taxonomy in Polylang, so I guess that the correct way to get your sitemap in the right language is to look for: my-site/?feed=sitemap&lang=fr

    I made tests:

    my-site/?feed=sitemap&lang=fr is broken except if I set it as the default language in Polylang (don’t understand why yet).

    However, I started debugging. Polylang does not modify the query (it sometimes do in some cases, but not here) and the program leaves my ‘wp’ filter with all posts and pages in the right language (whatever the language, whatever the choice for the default language). Up to here everything works as it should. Here is the SQL query:

    SELECT   wptest_posts.* FROM wptest_posts  INNER JOIN wptest_term_relationships ON (wptest_posts.ID = wptest_term_relationships.object_id) WHERE 1=1  AND ( wptest_term_relationships.term_taxonomy_id IN (4) ) AND wptest_posts.post_type IN ('post', 'page', 'attachment') AND (wptest_posts.post_status = 'publish' OR wptest_posts.post_author = 1 AND wptest_posts.post_status = 'private') GROUP BY wptest_posts.ID ORDER BY wptest_posts.post_modified DESC

    Here the language comes from: the term_taxonomy_id IN (4)

    So something breaks after may wp filter. I will go on debugging this…

    So I guess that when everything will work as expected, knowing the language of a post will not be useful. However there is a method: $polylang->get_post_language($post_id) returns the complete language object (in fact a term object). $polylang is global.

    Plugin Author Chouby

    (@chouby)

    I understand what happens. You get the right posts when you enter the loop but everything is broken by the line:

    if(!preg_match('/^' . preg_quote(get_bloginfo('url'), '/') . '/i', get_permalink())) continue;

    The reason for this is that Polylang filters get_bloginfo(‘url’) to send you on the homepage in the right language. You expect it to be my-site/ but you receive my-site/?lang=fr except for the default language if you choose to hide the language for it 🙂

    If you replace get_bloginfo(‘url’) by get_option(‘home’) then everything works well 🙂

    Now we have to focus on rewrite rules

    Plugin Author Chouby

    (@chouby)

    You create your rewrite rules before Polylang filters them. I believe it’s the best.

    Rewrite rules work perfect when adding the language code to all url. Otherwise Polylang left your rules unchanged. I can change this. I believe it’s better than I do this rather than you (due to the options included in Polylang)

    Do you know if other plugins creating sitemaps are using the same rules than you ?

    'sitemap.xml$' => $wp_rewrite->index . '?feed=sitemap',
    'sitemap-news.xml$' => $wp_rewrite->index . '?feed=sitemap-news',

    Do you know if other plugins creating sitemaps are using the same rules than you ?

    Most other sitemap plugins create physical files, so there is no need for any rewrite rules. For others, I don’t really know if they started using the same rules…

    But before you continue: I don’t really see the need for seperate google news sitemaps per language. Using the $polylang->get_post_language($post_id) I should get the correct language per post and as long as the URL is correct ( with or without language code in it ) it should be just fine… Multiple google news sitemaps will only complicate things for the user. The fact that this is how it worked out of the box for qTranslate, does not mean it should be the same in Polylang.

    Or would you prefer adding the language code to the google news sitemap and xml sitemap URLs if that option is checked in Polylang?

    Adding the language string ?lang=fr will indeed cause the default value for get_option(‘rss_language’) “en” to change. Par contre, it changes to “fr_FR”… This is not the correct language markup for RSS. It should become “fr”. But in principle it works 🙂

    I adopted the get_option(‘home’) method in the development version within that code snippet that is meant for verifying the domain ( there are plugins that allow external URLs as permalinks ) so it should work. All that is needed next is an extra filter in the feed tamplate for $polylang->get_post_language($post_id) to be inserted…

    @suivre

    On second thought… using the development version, I notice that the mixed sitemap with all languages in one, in combination with a page as homepage, has the following effect:

    The xml sitemap always starts with the main URL and then starts looping through pages and posts. During this loop, there is a small check to see if the page that is in the loop is not set as front page. If so, that URL is skipped because it will be the same as the main site URL at the start of the xml sitemap. This check is done with

    if ($post->ID == get_option('page_on_front'))

    However, in the mixed (un-languaged) sitemap, this check does not work. You can see the effect on http://valentheze.fr/sitemap.xml … Whether this is actually a problem (different URLs but same content == duplicate content) or not, I’m not sure. On the single-language sitemaps, it does work just fine since the home URL gets translated to the corresponding page URL. See http://valentheze.fr/sitemap.xml?lang=fr (or =nl or =en)

    So now I’m hesitating: use the mixed sitemap and try to fix it, or use the single-language sitemaps and fix it so that the main sitemap redirect to the default language sitemap… Both are viable options. What do you think is best?

    ===

    Two other things I noticed using the Polylang dev version:

    1. The home page redirection seems a bit messed up on http://valentheze.fr/ :
    When I visit the site in a Dutch browser, I get redirected to http://valentheze.fr/nl/ and see a blog page listing latest posts instead of the static home page http://valentheze.fr/welkom/ … Same for other languages. I do not want this (I did not set a static page as front page for nothing 😉 ) so I check the Languages option ‘Redirect the language page to the homepage in the right language’. I’d make this option default but it has one downside: since it does not actually redirect but instead show the front page content, we’ve now got a duplicate content issue 🙁

    Unless I check ‘Hide URL language information for the default language’…

    2. Next, still with the ‘Hide URL language information for the default language’ option unchecked, I browse to the French homepage. This time, trying to get back to the Dutch homepage via the flags, it turns out I get redirected back to the French homepage!

    Unless, again, I check ‘Hide URL language information for the default language’…

    Would it be possible to get rid of these ‘language pages’ ( /en/ , /fr/ , /nl/ etc. ) completely?

Viewing 15 replies - 16 through 30 (of 53 total)
  • The topic ‘[Plugin: Polylang] Static home page 404 issue’ is closed to new replies.