If one tries to transliterate paths from entity fields (for example taxonomy) characters like ä, ü, ö are converted to a,u,o but not to ae, ue, oe. The Drupal 8 transliteration does that correctly on url-paths but for file uploads File (Field) Paths creates just a, u, o. - It would be great to have that feature for SEO and useful paths on the server.

The Problem is that the pathauto module is used to transliterate the path before File (Field) Paths does it. The code at the end of the module (/modules/filefield_paths/filefield_paths.module) should be changed in that manner:

// Transliterate string
    if ($transliterate == TRUE) {
// Use the current default interface language.
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
// Instantiate the transliteration class.
$trans = \Drupal::transliteration();
// Use this to transliterate some text.
$path = $trans->transliterate($path, $langcode);     
    }

Moreover the Operation should be done before the path and the filename is cleared by the pathauto module:

before this

$path = \Drupal::service('pathauto.alias_cleaner')
            ->cleanstring($path);
          if (!empty($pathinfo['extension'])) {
            $path .= '.' . \Drupal::service('pathauto.alias_cleaner')
                ->cleanstring($pathinfo['extension']);
          }
          $path = str_replace('/', '', $path);
        }
        else {
           
          $path = str_replace($pathinfo['filename'], \Drupal::service('pathauto.alias_cleaner')
            ->cleanstring($pathinfo['filename']), $path);
        }
      }

and before that

$path = \Drupal::service('pathauto.alias_cleaner')->cleanstring($path);
      }
    }
    elseif ($remove_slashes) {
      $path = str_replace('/', '', $path);
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cmsarnold created an issue. See original summary.

cmsarnold’s picture

Issue summary: View changes
cmsarnold’s picture

Category: Feature request » Bug report
geek-merlin’s picture

Hmm, might make sense - can you (learn to) roll a patch?

der_manzke’s picture

I've hit the same problem today. I inserted the code like @cmsarnold mentioned and it works quite fine for me and translates umlauts like ä, ö and ü to ae, oe and ue.

Like you see in the screenshot it gets perfectly replaced :)

I also checked it for Japanese characters, but i don't know if it is translated well enough. (I'm not used to Japanese so i have no idea if it is correct)

This is my first patch and I'm not quite familiar with this so please check it and if it is working, feel free to use it :)

der_manzke’s picture

Status: Needs work » Needs review

I've hit the same problem today. I inserted the code like @cmsarnold mentioned and it works quite fine for me and translates umlauts like ä, ö and ü to ae, oe and ue.

Like you see in the screenshot it gets perfectly replaced :)

I also checked it for Japanese characters, but i don't know if it is translated well enough. (I'm not used to Japanese so i have no idea if it is correct)

This is my first patch and I'm not quite familiar with this so please check it and if it is working, feel free to use it :)

Castor-designs’s picture

This is gold and very important. Thanks. Why is it not implemented in the official release?

fox mulder’s picture

#5 works but composer can not apply patch for 8.x-1.0-beta6

C-Logemann’s picture

Status: Needs review » Needs work

Patch needs to be relative to module folder not the complete installation path/website project as currently in #5 patch: "/web/modules/contrib/filefield_paths/"