Support » Plugin: Filenames to latin » Not working with special characters

  • Samuel

    (@sambody)


    I uploaded a test file (57kb) named “test âl’élève.jpg”. Once uploaded, it was renamed to test-âlélève.jpg – so the space was replaced and the " ' " was removed correctly, but the special characters were not replaced.

    I’m using WordPress 4.7.1, PHP 5.4.45.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author webvitalii

    (@webvitaly)

    What language are those chars from?

    Samuel

    (@sambody)

    French. Examples of french characters: éèêâîçàôùû.

    Small correction: the resulting name did not have any spacing (unlike what I wrote above, or what the WordPress comment system did to what I wrote), so that was not an issue. Just the special characters.

    • This reply was modified 4 years ago by Samuel.
    Plugin Author webvitalii

    (@webvitaly)

    • Do you have French language installed on your computer?
    • What version of OS you you using?
    • What version of Browser are you using?
    Samuel

    (@sambody)

    – I’m on a Mac, OSX 10.11.6.
    – In english.
    – I use Firefox 50.1.

    I made a new test, using an image called test élève garçon.png, with Chrome (version 55.0) this time, and I got the same result: spacing were correctly replaced with “-“, but special characters remained in the file name: test-élève-garçon.png.

    Then I also switched my Mac computer to french, did that last test again in Firefox and Chrome, and it was the same result.

    I was facing the same issue. My guess is if the file is uploaded from Mac OS, the special characters are encoded in some proprietary Mac encoding – in my client’s case it was probably the Macintosh Central European encoding. In such case the current plugin’s replacement method will not work properly.

    I found the following solution.

    Change:

    $friendly_filename = preg_replace( array_keys( $chars_table ), array_values( $chars_table ), $filename );

    return strtolower( $friendly_filename );

    To:

    $friendly_filename = preg_replace( array_keys( $chars_table ), array_values( $chars_table ), $filename );

    $transliterate_filename = transliterator_transliterate(‘Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove’, $friendly_filename);

    return strtolower( $transliterate_filename );

    @webvitaly In case you’d like to list me as a contributor, I’d be grateful:)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Not working with special characters’ is closed to new replies.