Too many underscores _ _ _ _ _ _ _

Too many underscores _ _ _ _ _ _ _

by Éric Bugnet -
Number of replies: 7
ምስሊ ናይ Documentation writers ምስሊ ናይ Plugin developers ምስሊ ናይ 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

Average of ratings: -
In reply to Éric Bugnet

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

by Petr Skoda -
ምስሊ ናይ Core developers ምስሊ ናይ Documentation writers ምስሊ ናይ Particularly helpful Moodlers ምስሊ ናይ Peer reviewers ምስሊ ናይ Plugin developers
There are many different encodings and national characters - PHP has no proper support for them sad 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 wink


skodak
In reply to Petr Skoda

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

by Éric Bugnet -
ምስሊ ናይ Documentation writers ምስሊ ናይ Plugin developers ምስሊ ናይ 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 _ _ _ _ _ _ _

by Éric Bugnet -
ምስሊ ናይ Documentation writers ምስሊ ናይ Plugin developers ምስሊ ናይ 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 _ _ _ _ _ _ _

by Nicolas Martignoni -
ምስሊ ናይ Core developers ምስሊ ናይ Documentation writers ምስሊ ናይ Particularly helpful Moodlers ምስሊ ናይ Plugin developers ምስሊ ናይ Testers ምስሊ ናይ 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 _ _ _ _ _ _ _

by Martin Dougiamas -
ምስሊ ናይ Core developers ምስሊ ናይ Documentation writers ምስሊ ናይ Moodle HQ ምስሊ ናይ Particularly helpful Moodlers ምስሊ ናይ Plugin developers ምስሊ ናይ Testers
Thanks!  Good pointer!  I've included that convert_high_ascii() function as the first step in our function.
In reply to Martin Dougiamas

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

by Nicolas Martignoni -
ምስሊ ናይ Core developers ምስሊ ናይ Documentation writers ምስሊ ናይ Particularly helpful Moodlers ምስሊ ናይ Plugin developers ምስሊ ናይ Testers ምስሊ ናይ Translators
Martin,

Thank you for taking this problem in account wink

The perl script in attachment seems to have more unicode rules... but it's perl and I don't know how to convert it in PHP.

Cheers
Nicolas
In reply to Martin Dougiamas

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

by Éric Bugnet -
ምስሊ ናይ Documentation writers ምስሊ ናይ Plugin developers ምስሊ ናይ Translators

Thanks for working on that !

I hope you'll explain your results...

Eric