Accents replacement with natural letter


Is there a way to remove accents from a string, i’ve search the doc I found some modifier (like anchorize, urlize etc) but none to replace accents (for exemple é => e).

{{- $txs := ( $.Scratch.Get "taxonomy" ) -}}
{{- $tx := ( $txs | singularize ) -}}

{{- $taxonomies := ( index $.Site.Taxonomies $txs ) -}}

<div class='{{ $txs }}'>
  {{- partial "svg/icons" $tx -}}
  <span class='screen-reader-text'>{{ ( ( i18n $tx 2 ) | default $txs ) }}: </span>
  {{- range $i, $term := ( index $.Params $txs ) -}}
    {{- if gt $i 0 }}, {{ end -}}
    {{- with ( index $taxonomies ( $term | anchorize ) ) -}}
    <a class='{{ $tx }}' href='{{ .Page.RelPermalink }}'>
      {{- .Page.Title -}}
    {{- end -}}
  {{- end -}}

hugo dis it on his source code for the key of taxonomy map

problem is there

{{- with ( index $taxonomies ( $term | anchorize ) ) -}}

i need something like

{{- with ( index $taxonomies ( $term | anchorize | toASCII ) ) -}}

is there a modifier like this ?


1 Like


you could use something like this:

{{ $tag := replace . "é" "e" }}
{{ $tag := replace $tag "è" "e" }}

(Just tested: The urlize function does not remove accents.)

By the way: There is a config setting removePathAccents.

Even with removePathAccents set to true, urlize does not remove accents.

For me the replace solution is not efficient, there’s a lot of letters with accents in French (and others languages)

Isn’t URLIZE doing that? It should remove accents because those aren’t too well liked in URLs?

This might be a bug or at least worth an issue.

Just in addition:

Hugo does not seem to handle German umlauts correctly:

An ä remains an “ä”.

With removePathAccents an “ä” in converted into an “a”. That is wrong in German. An “ä” should be converted into “ae”.

This applies analogously to all other umlauts.

The German “ß” should be transliterated into “ss”.

There is/was an issue on GitHub.

This might not make you happy, but in my german weblog I have no such issues. Mostly because I define slugs and urls to such umlaut-pages. It’s probably best to “handle” these special characters by yourself or use a very specialized version of the solution @grob proposed.

@davidsneighbour, @grob

I do not agree

Hugo discover taxonomy terms in front matter, where they are written in a language, apply some tranformation rules on this term name to get a key for the index collection index.

But there’s no transformer that apply the same rules to get a key from the language term name available in the template. It’s a missing feature.

Having this transformer and you are sure it works.

{{- with ( index $taxonomies ( $term | toKey ) ) -}}

a toKey (or no matter how you call it) should be provided by Hugo

You are right urlize remove accents when removePathAccents is set to true :wink:


Glad it’s working.

So like… is this solved? Can we clarify which parts work for you and which parts you think is missing?

I found nothing in the doc about removePathAccents

It’s n option to put in config.toml?

1 Like

Yes, it is an option for config.toml
removePathAccents = true

1 Like