DanielRS
I’m implementing a blogging system in my website, and I’m trying to generate post slugs from the title, like this:
def slugify(string) do
string
|> String.normalize(:nfd)
|> String.replace(~r/[^A-z\s]/u, "")
|> String.replace(~r/\s/, "-")
end
If I try something like slugify("árboles más grandes") I get arboles-ms-grandes
Trying slugify("los árboles más grandes") returns los-rboles-ms-grandes
My slugify function seems to only work with accented letters at the start of the string.
Best regards,
Daniel Rivas.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
KronicDeth
Is it a requirement that you ascii-ify the slugs? There is support in modern browsers for non-ascii URLs being percent encoded in the HTML source, but displayed as the unicode characters as described on stackoverflow. Certain languages have words that can be confused with other words if you strip accents. I’m aware of it in Polish, I don’t know if it affects any of your target languages. If you’re sure you want to strip the accents, then you can disregard this and we’ll move on to a technical solution to the loss of accented characters.
DanielRS
It is definitely not required, as I can do just fine striping out the punctuation and replacing white-spaces with dashes (my target languages are English and Spanish); however, I would still like to learn how to get this done, for future reference.
Best regards,
Daniel Rivas.
KronicDeth
I’m not sure what is going on. When I tested it, it works:
I got the test string by copying the string from your posting, so I don’t know if that changed the encoding.
hubertlepicki
@KronicDeth this does not seem to work on all systems, at least not on mine:
There is unix library
libiconvthat does that. Erlang has a few wrappers, one can be installed from hex and is callediconv.I think using iconv transliteration also replaces some of the national characters to recognized ascii replacements, I think in German ß is replaced with “ss” etc.
After you transliterated the string to most matching ascii equivalents, you can downcase it and replace whitespace with dashes.
KronicDeth
Let’s (both @hubertlepicki and @DanielRS) back up and compare each part of the pipeline. I’m curious where the difference is. Here’s my output for each stage
NOTE: I had to manually type in the acute accents separate from the a for the first stage because although iex prints them separate, when I copied and pasted into Chrome they were recombined, so the above is visually what I saw
Also, let’s not use the abbreviated form of the range in the regex just in case that makes a difference:
In my mind,
A-zcoversA-Z,[,\``,],^,_, backtick (since it can't quote it in markdown), anda-z` and I would think we don’t want the symbols in the range really.hubertlepicki
@KronicDeth it’s
String.normalize. I do not think it does what you think it does, I quite frankly do not understand what it should do. But it does not seem to convert UTF-8 national characters to matching ASCII ones at all on my system:(And above is exactly what I see on my IEX terminal). I’m on Linux, en_US.UTF-8 LANG.
DanielRS
@hubertlepicki
String.normalizeseparates each special character in multiple characters in such a way that their combination represents the original character. Simple example:However, for some reason it doesn’t work when the accentuated character is not the first one in the string:
@KronicDeth Here’s my output:
My machine is running Archlinux, this is the output of running
localein the terminal:I wonder what the problem could be…
hubertlepicki
Ok, so I would definitely use iconv instead, it will allow you to work with
broader number of characters and it works as expected
Possibly you found a bug, may be worth submitting GH issue on elixir-lang/elixir.
gringocl
I ran into this issue today, after upgrading from
1.2.3. This was a bug and I submitted a pr to fix this onelixir-lang/elixir. Hopefully it will get merged soon!yurko
If anyone stumbles upon this issue like I did, it might not be clear right away but at the moment it is doable to slugify a string using only string functions mostly discussed here:
String.normalize(:nfd)would split the string into separate characters so that accents can be removed and ASCII parts remain leaving us with a reasonable slug (not a grammatically correct transcriptions but the ASCII parts of the special chars).Here is a changeset function I came up with:
Few tests from above:
Hubert Łępicki>hubert-epickiárboles más grandes>arboles-mas-grandesÜbel wütet der Gürtelwürger>ubel-wutet-der-gurtelwurger