Feed on
Posts
Comments

[, ] Force to append lang-code to feed links

I think rss feeds should always have language code, no matter what the Gengo setting is.

So, I made a patch.

[before]
http://wp.reedom.com/feed
[after]
http://wp.reedom.com/feed/ja/
Index: gengo.php
===================================================================
— gengo.php   (revision 106)
+++ gengo.php   (working copy)
@@ -175,7 +175,7 @@
                                add_filter(’year_link’, array(& $this,’append_links’));
                                add_filter(’month_link’, array(& $this,’append_links’));
                                add_filter(’day_link’, array(& $this,’append_links’));
-                               add_filter(’feed_link’, array(& $this,’append_links’));
+                               add_filter(’feed_link’, array(& $this,’append_feed_links’));
                                add_filter(’post_comments_feed_link’, array(& $this,’post_comments_feed_link’));

                                // SQL control.
@@ -654,6 +654,12 @@
                return $this->append_link_language($link, $this->viewable_code_string);
        }

+       // Append language codes to other links.
+       function append_feed_links($link) {
+        $this->forced_append = true;
+               return $this->append_link_language($link, $this->viewable_code_string);
+       }
+
        // Called from wp_list_pages.
        function get_pages($pages, $arguments) {
          global $wpdb;
@@ -730,7 +736,8 @@
        function post_comments_feed_link($url) {
          global $post;
          if (get_option(’permalink_structure’)) $url = preg_replace("|/$post->code/$|", ‘/’, $url);
-               return $this->append_link_language($url, $post->code);
+      $this->forced_append = true;
+      return $this->append_link_language($url, $post->code, false);
        }

        // Define the language query variable.

 

Download the patch »

[, ] Redirect loop

Days before I experienced redirect loops when I tested the `tag search’ feature of SimpleTagging. I thought `Gengo should be worked something wrong.’ then I looked around Gengo’s setting pages and found that disabling `”Gengo should append language codes to permalinks automatically.’ feature could hide the problem.

Till today, I’ve killed off bugs in Gengo I’ve seen. I’ve got some knowledge of Gengo.

And finally I found `the solution’ to the issue.

open `Gengo Exclusions' page in admin panel, 
add "/tag" to `Exclusions' box.

Oh, yeah, the exact way is provided by the author.

After activating SimpleTagging plugin I faced some problem. To avoid that I disabled the Gengo’s feature `Gengo should append language codes to permalinks automatically.’.

Days later I noticed a WordPress’ strange behavior.

I have pages having translations and when I clicked a link to the another language’s page then I saw a `404 Error’ page.

That’s strange.

Went further investigation I found a bad smelling code in the `locale’ filter.

Index: gengo.php
===================================================================
— gengo.php   (revision 80)
+++ gengo.php   (working copy)
@@ -1222,7 +1222,7 @@
  } else {
    $value = $parser->query_vars[’pagename’];
    if (($position = strpos($parser->query_vars[’pagename’], ‘/’)) !== false) {
-     $value = substr($value, $position + 1);
+     $value = substr($value, 0, $position);
    }
    $where = "p.post_name = ‘$value’";
    $join = "INNER JOIN $wpdb->posts AS p ON p.ID = p2l.post_id";

One of the pair pages I faced 404 error have 3 depth hierarchy.

software/wordpress-plugins/l10n-helper.html    <English>
software_ja/wordpress-plugins/l10n-helper.html <Japanese>

Before modification the value of $value was set as:

wordpress-plugins/l10n-helper.html <English>
wordpress-plugins/l10n-helper.html <Japanese>

$wpdb->posts.post_name only have a post name for 1 depth of hierarchy but the code got of 2 depth. And the code does not seem to care of WordPress feature that it allows to have same post name among pages while the top of ancestors of those page’s are not same.

I fixed the code to obtain the first part of uri.

[, ] Gengo and cache

It seems that Gengo cares WordPress’ cache feature a bit but not entirely.
I don’t know it comes from the fact that the cache feature is disabled by default.

Anyway there must be some bugs on it.

Past days I saw a kind of it on category listing then I gave away the category listing and replaced by SimpleTagging.

After that I noticed that there was similar thing on page listing. I couldn’t throw away this feature. I needed it.

The problem was that the page list block in the sidebar could be empty for all locales but the one visited firstly after cache feature had been enabled or cache for the page listing had expired.

I tried to fix the bug and have done.

I made a function gengo_list_pages(), which is to be replaced by wp_list_pages() in sidebar.php, in general.

<?php
if (!function_exists(gengo_list_pages)) {
function gengo_list_pages($args =) {
    if (is_array($args)) {
        $r = &$args;
    } else {
        parse_str($args, $r);
    }
    $r = array_merge(array(language=> the_language(true)), $r);
    return wp_list_pages($r);
}
}
?>

There is also a related bug in the core code of WordPress 2.2.1.

Index: post.php
===================================================================
— post.php    (revision 3)
+++ post.php    (working copy)
@@ -1070,9 +1070,14 @@
        extract($r, EXTR_SKIP);

        $key = md5( serialize( $r ) );
-       if ( $cache = wp_cache_get( ‘get_pages’, ‘page’ ) )
-               if ( isset( $cache[ $key ] ) )
-                       return apply_filters(’get_pages’, $cache[ $key ], $r );
+       if ( $cache = wp_cache_get( ‘get_pages’, ‘page’ ) ) {
+               if ( isset( $cache[ $key ] ) ) {
+                       $pages = apply_filters(’get_pages’, $cache[ $key ], $r );
+            if ( $pages && ( $child_of || $hierarchical ) )
+                $pages = & get_page_children($child_of, $pages);
+            return $pages;
+        }
+    }

        $inclusions = ”;
        if ( !empty($include) ) {

[] Installed `Gengo’

I installed Gengo, a WordPress plugin, which enables WordPress to write blog/Pages in multi languages.

But its installation was painful. Very poor document - there’s only FAQ but not manual. What’s `Summary’? What’s `Group’ in Gengo context? Force users to build installation knowledge from a tiny pieces in FAQ. Just nonsense.