Yesterday, a German AZIndex user asked if it was possible to convert German index headings containing umlauts to their non-accented equivalents when sorting indexes with German names in it. The mappings would be:
Ä => Ae ä => ae
ß => ss
Ö => Oe ö => oe
Ü => Ue ü => ue
Thus Österreich becomes Oesterreich and Müller becomes Mueller. I am told this is a common feature of German telephone directories, for example.
Note: If the mappings are incorrect, please let me know and I will update the plugin.
Well, there is no option in the AZIndex settings to allow you to do this, but you can do it if you use a special WordPress feature, called a filter, to convert the headings in the index before they get sorted. The name of the filter is azindex-heading and is called for every heading in the index whenever the AZIndex plugin is about to sort them.
The filter function is just a few lines of code (see below) and I have decided to put it into a small add-on plugin which people can easily install if they want the feature. The only restriction is that it if you activate it, it will convert the headings in all your indexes. There is no way to select one index to use it on. (I might have to rethink that for a later release of AZIndex).
Here is the download link for the add-on plugin: AZIndex Add-on German Filter
Just download it to your plugins directory and activate it. There is no settings page — the only settings are “Activated” and “Deactivated”.
Here is the code, for those of you who are interested:
/* Tell WordPress that you want to use this filter function with AZIndex */
add_filter('azindex_heading', 'az_german_filter');
/**
* In some German indexes, like telephone directories and place name indexes,
* people prefer to see characters with umlauts (Ä, Ö, and Ü) and ß expanded into
* two characters (Ae, Oe, Ue, and ss) before the items are sorted.
*
* This function replaces performs this substution before the index
* is sorted, so that the items all appear in the expected order.
*
* If you don't want all the substitutions, just remove them from the array.
*
* @param string $heading the heading as it would appear in the index by default
* @return string the heading as modified by this filter
*/
function az_german_filter($heading) {
// Note, the German characters are defined using their UTF-8 character codes
// in the following order: Ä, Ö, Ü, ä, ö, ü, ß
$conversion = array("xC3x84"=>"Ae", "xC3x96"=>"Oe", "xC3x9C"=>"Ue",
"xC3xA4"=>"ae", "xC3xB6"=>"oe", "xC3xBC"=>"ue",
"xC3x9F"=>"ss");
foreach ($conversion as $key => $value) {
$heading = mb_ereg_replace($key, $value, $heading);
}
return $heading;
}