• Resolved charlie67p

    (@charlie67p)


    Hi,

    Using the Tag cloud block :
    When having the french special character é or é as the first letter of a Tag, the tag is placed at the end of the cloud ! (see the screenshot)

    This is annoying because we (the French) expect to see these words right after the E letter (like in french dictionaries), not after the Z letter

    The only thing I can do is to turn these é é to e E ,
    but it is not a good practice, whether it is capitalized or not * .

    Is there a way to fix that ?

    * From my point of view, but also from the French Academy point of view ??

    [ the language of my website is set to French ]

    • This topic was modified 7 months, 1 week ago by charlie67p.
    • This topic was modified 7 months, 1 week ago by charlie67p.
    • This topic was modified 7 months, 1 week ago by charlie67p.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator bcworkz

    (@bcworkz)

    Did you specify something like wp_tag_cloud(['orderby'=>'name',]); to generate the cloud? (it appears so)

    We would think that since you have your site set to French, that French collation would apply, but there is apparently something off with how PHP locales are configured. (the cloud collation is according to uasort( $tags, 'strnatcasecmp' );, strnatcasecmp() being the native PHP comparison function)

    All I can suggest is you use the ‘tag_cloud_sort’ filter to uasort() the tags using a custom comparison function that properly handles é and similar characters.

    Thread Starter charlie67p

    (@charlie67p)

    Hi @bcworkz ,

    Thanks for your answer

    I just added the Cloud Tag Block to my page,
    I didn’t use any tag cloud function or hook in my functions.php

    Strange

    I will try to deactivate all the plugins, one by one, to see if it could be a conflict

    Thread Starter charlie67p

    (@charlie67p)

    Well, I deactivated the plugins one by one, but it did not change anything.

    I noticed that the Post Tags Block is working fine (not placing é after Z letter)
    I have the problem only with the Tag Cloud Block…

    I tried with Twenty Twenty Four Theme on another website that does not any plugin installed : same problem.

    • This reply was modified 7 months, 1 week ago by charlie67p.
    • This reply was modified 7 months, 1 week ago by charlie67p.
    Thread Starter charlie67p

    (@charlie67p)

    OK, I still don’t know why the Tag Cloud Block does not work,
    but I fixed with this !!

    /*
    Plugin Name: XV Sort Tag Cloud
    Description: Sorts properly tag cloud by name (removing accents)
    Author: Xavi Ivars
    Author URI: https://xavi.ivars.me/
    Version: 1.0
    License: https://www.gnu.org/copyleft/gpl.html GNU General Public License
    */
    add_filter('tag_cloud_sort', function( $tags, $args )
    {
        if( empty( $tags ) || ! is_array( $tags ) ) {
            return $tags;
        }
    
        uasort( $tags, '_xv_sort_term_by_name' );
    
        return $tags;
    }, 10, 2 );
    
    if ( ! function_exists( '_xv_sort_term_by_name' ) ) {
        function _xv_sort_term_by_name($a, $b) {
            return strnatcasecmp( remove_accents($a->name), remove_accents($b->name) );
        }
    }
    • This reply was modified 7 months, 1 week ago by charlie67p.
    Moderator bcworkz

    (@bcworkz)

    Ha! remove_accents() Clever fella you ?? But wouldn’t that possibly wrongly mix é and E words, for example:
    éa, Eb when we want Eb, éa ?
    (unverified and I could be misunderstanding what is “correct”)

    Clearly the post tags block uses a different sort algorithm than cloud tags. This is either a server locale or PHP issue, not WP itself. For example:

    // Desired output: -1
    setlocale(LC_ALL, 'fr_FR');
    print_r(strnatcasecmp('é', 'Z'));
    // Output is 1 :(

    At least there’s a solution and you found it. Or close to it if I’m right about the éa, Eb bit. I hope it’s not an issue, but I suspect it is.

    Thread Starter charlie67p

    (@charlie67p)

    Hey, thanks,

    But wouldn’t that possibly wrongly mix é and E words, for example:
    éa, Eb when we want Eb, éa ?

    No, it is correct, it is like this in the dictionnary, here a little sample :

    écuyers
    eczéma
    (…)
    eczémateux
    édam

    About PHP and locales, sorry but I am totally ignorant about this, I don’t know how it works.
    Should it be fixed by changing some PHP settings. I mean : should I talk to my Hosting provider ? …

    • This reply was modified 7 months, 1 week ago by charlie67p.
    Moderator bcworkz

    (@bcworkz)

    I’m relieved to be wrong ?? So é and E get collated as though they are the same letter. Interesting. The languages I’m familiar with treat each as individual, unrelated letters. Obviously not a universal concept.

    I’m afraid the problem lies deeper than some PHP settings, it has something to do with how different locale configurations are compiled. Your host simply installs the locales on their server, they have no control over how each is configured. I think it’s actually related to the webserver software, likely Apache. I’m not 100% sure though.

    Apache does have a bug reporting system, but it’s intended for hard core developers, not us mere mortals. But the linked page does mention a mailing list where you could ask knowledgeable users for guidance on how to best proceed. If we’re even in the right place.

    Thread Starter charlie67p

    (@charlie67p)

    Thank you for explaining @bcworkz ,

    I’ll ckeck later to use the Tag Cloud Block with a totally fresh WordPress install, but I can’t go much further in investigation because I don’t have any skill with Apache and webservers ??

    Regards

    And still about the é and the E , you can better understand why E and é are placed together in the dictionnary, and why we expect to find them together in a Tag cloud, when knowing that, for example, in “escamoter”, “effilocher” and “esquiver” , the “e” must be pronounced “é” ! [ that’s what I guess, but I do not know the official reasons ]
    …Tricky language, where the words are not always written in accordance with their pronunciation

    • This reply was modified 7 months, 1 week ago by charlie67p.
    • This reply was modified 7 months, 1 week ago by charlie67p.
    Thread Starter charlie67p

    (@charlie67p)

    Last note : I know that some other languages organize things differently : The greek Η, Ι and Υ have the exact same pronunciation, but have totally different places in the alphabet…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Tag cloud alphabetical order and french é special character’ is closed to new replies.