Too many underscores _ _ _ _ _ _ _

Too many underscores _ _ _ _ _ _ _

de Éric Bugnet -
Number of replies: 7
Imachen de Documentation writers Imachen de Plugin developers Imachen de Translators

Hi, all...

I've got this problem : I'm French, and in french language we are using accent (e, é, è, ê...).

I know that, in Internet language, we don't use accent for file name and directory name, and in Moodle all this accents are replace by underscores.

But I'm in a school, and when a teacher post a file named for exemple "l'été est passé", the file name is modified to "l__t__est_pass_".

That's a problem for orthography in school, and for readability.

Can't we replace "é" by "e" and not by "_", the file name will be "l_ete_est_passe" and will be more readable ???

It's not good for orthography, but a little more !

Thank's for your responses.

Eric

Promeyo de puntuacions: -
In reply to Éric Bugnet

Re: Too many underscores _ _ _ _ _ _ _

de Petr Skoda -
Imachen de Core developers Imachen de Documentation writers Imachen de Particularly helpful Moodlers Imachen de Peer reviewers Imachen de Plugin developers
There are many different encodings and national characters - PHP has no proper support for them triste I guess we will have to wait several years till PHP 6 or 7.

IMO it would be bad to solve only French problem, the global solution is quite complicated, though not impossible, but it would need much time, testing and the code would be rather slow.

If you want to do some custom hack, you can modify the cleaning function clean_filename() from lib/moodlelib.php, simply do the character replacement in the beginning of the function clucada


skodak
In reply to Petr Skoda

Re: Too many underscores _ _ _ _ _ _ _

de Éric Bugnet -
Imachen de Documentation writers Imachen de Plugin developers Imachen de Translators

Hi,

I think I should do that... (thanks for says me what function it is !)

I know that is not only a "Frenchy" problem, but perhaps it's possible to made that for the next Moodle version ? And not only for me and my country ??? I post here for explain my idea...

I prefer not modifying my Moodle and stay with the base Moodle ! (for upgrade...) but I think I'll try !

Ciao

Eric

In reply to Petr Skoda

Re: Too many underscores _ _ _ _ _ _ _

de Éric Bugnet -
Imachen de Documentation writers Imachen de Plugin developers Imachen de Translators

Hi again...

It's done, and work :

I just change in function clean_filename() from lib/moodlelib.php

function clean_filename($string) {

/// Cleans a given filename by removing suspicious or troublesome characters

/// Only these are allowed:

/// alphanumeric _ - .

$string = eregi_replace("\.\.+", "", $string);

$string = eregi_replace("é", "e", $string);

$string = eregi_replace("è", "e", $string);

$string = eregi_replace("à", "a", $string);

$string = eregi_replace("ù", "u", $string);

$string = eregi_replace("â", "a", $string);

$string = eregi_replace("ô", "o", $string);

$string = eregi_replace("î", "i", $string);

$string = eregi_replace("ê", "e", $string);

$string = eregi_replace("û", "u", $string);

$string = eregi_replace("ä", "a", $string);

$string = eregi_replace("ö", "o", $string);

$string = eregi_replace("ï", "i", $string);

$string = eregi_replace("ë", "e", $string);

$string = eregi_replace("ü", "u", $string);

$string = eregi_replace("ç", "c", $string);

$string = preg_replace('/[^\.a-zA-Z\d\_-]/','_', $string ); // only allowed chars

$string = eregi_replace("_+", "_", $string);

return $string;

}

Just change this for other languages.

Eric

In reply to Petr Skoda

Re: Too many underscores _ _ _ _ _ _ _

de Nicolas Martignoni -
Imachen de Core developers Imachen de Documentation writers Imachen de Particularly helpful Moodlers Imachen de Plugin developers Imachen de Testers Imachen de Translators
The function "dirify" (adapted from MovableType) will do it rather completely. See here: http://kalsey.com/2004/07/dirify_in_php/

Nicolas
In reply to Nicolas Martignoni

Re: Too many underscores _ _ _ _ _ _ _

de Martin Dougiamas -
Imachen de Core developers Imachen de Documentation writers Imachen de Moodle HQ Imachen de Particularly helpful Moodlers Imachen de Plugin developers Imachen de Testers
Thanks!  Good pointer!  I've included that convert_high_ascii() function as the first step in our function.