Too many underscores _ _ _ _ _ _ _

Too many underscores _ _ _ _ _ _ _

Éric Bugnet -
回帖数: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

回复Éric Bugnet

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

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 伤心 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 眨眼


skodak
回复Petr Skoda

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

É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

回复Petr Skoda

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

É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

回复Petr Skoda

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

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
回复Nicolas Martignoni

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

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.
回复Martin Dougiamas

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

Nicolas Martignoni -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像 Testers的头像 Translators的头像
Martin,

Thank you for taking this problem in account 眨眼

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