I need to clean up file names on upload. Both for image fields, other file fields and IMCE file manager. The transliteration module is not yet ported to Drupal 8 and the community does not seem to agree on how to implement the core transliteration in Drupal 8.

Do I have to make a custom module for this, or is there a simpler way?

Right now, Drupal 8 seems to allow both spaces and special characters in filenames. I know about the module File (Field) Paths, but it will have to be set up for every file field on every content type. I don't think it will work with IMCE.

  • 1
    \Drupal::service('transliteration')->transliterate() is in core. If you just need to clean file names you can do that manually with simple loop. If you need to do it from now on automatically, you'll need a module. Simple hook_file_presave will do. – user21641 Sep 27 '17 at 12:17
  • Thanks. I am not sure I would be able to build a custom module for this myself. File (Field) Paths is an option, but the beta1 version is not production ready I think. It can not easily be uninstalled either. – eye-wonder Sep 27 '17 at 14:33
  • so why did you ask then? – user21641 Sep 27 '17 at 17:05
  • Well am wondering if there is another module/unofficial module, an override snippet or some other workaround. I hope it exists out there or that this is implemented as a core option soon. I might try to put together some module based on ALEXANDER BELOVs work (when I have a day off)(trial and error approach). I don't think every Drupal 8 developer are able to make custom modules them selves, but I like to try and learn when I have time. I will share if I succeed. – eye-wonder Sep 28 '17 at 8:11

I applied a Drupal 8 core patch from this page. It seems to work fine. It adds a new option to /admin/config/media/file-system: File transliteration option Drupal 8

This option enables transliteration for all future uploads to all file fields. It also works for inline images when Enable image uploads is enabled (for the text-format). I don't know if the patch affects IMCE, since IMCE was not installed on my test installation.


There is a module for that https://www.drupal.org/project/transliterate_filenames

Transliteration for all uploading files (includes fields and ckeditor inline upload)

How to use: just enable module as usual. All new file names will be transliterate to Latin characters.

  • This project is not covered by Drupal’s security advisory policy. – eye-wonder Oct 17 '18 at 13:13
  • The module is stable now and it works: 1.It replaces spaces in file names 2.Adds a counter for duplicate files. – Achraf JEDAY Apr 6 '20 at 8:29

It seems that the module already mentioned is now covered by Drupals security advisory policy:

Transliterate filenames for uploads - https://www.drupal.org/project/transliterate_filenames

Stable releases for this project are covered by the security advisory policy.

8.x-1.3 Stable release covered by the Drupal Security Team released 1 July 2019


Just use this module. This module is based on the blog post by Alexander Belov, but simplified for a less specific use case. https://github.com/jameswilson/filename_transliteration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.