Compressing Icelandic name declension patterns into a 3.27 kB trie August 2, 2025
Displaying personal names in Icelandic user interfaces is surprisingly hard. This is because of declension — a language feature where the forms of nouns change to communicate a syntactic function.
In Icelandic, personal names have four forms, one for each of the grammatical cases of Icelandic nouns. Take the name “Guðmundur”:
Grammatical case Form Nominative Guðmundur Accusative Guðmund Dative Guðmundi Genitive Guðmundar
When including a name in a sentence, the sentence’s structure determines the grammatical case, and correspondingly, a certain form of the name should be used. Using the wrong form results in a “broken” feel that native speakers associate with non-native speakers not yet fluent in the language.
The problem is that Icelandic personal names are always stored in the nominative case. If you’ve loaded a user from a database, their name will be in the nominative case. This creates a problem when you have a sentence structure that requires, for example, the accusative form of the name.
As a developer, you can work around that by rewriting the sentence to use the nominative case, which can be very awkward, or by using a pronoun (e.g. they). Both are unsatisfactory.
A few years ago, I built a JavaScript library to solve this issue. It applies any of the four grammatical cases to an Icelandic name, provided in the nominative case:
applyCase ( "Guðmundur" , "accusative" )
When building this library, I did not code any declension rules by hand. Instead, the rules of Icelandic name declension are derived from public Icelandic data for personal names and their forms. The rules are encoded in a trie-like data structure that uses clever compression techniques to get the library’s bundle size under 4.5 kB gzipped. This lets the library be included in web apps without increasing bundle size significantly.
... continue reading