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.