Hello!
I guess this is when I release Idiom to the open. Idiom is a new localisation library for Elixir that I’ve been working on for a few weeks now, and there’s a few things about it that I think are really cool.
Here’s a few examples of its API, straight from the README:
Idiom.put_locale("en-US")
t("landing.welcome")
# With natural language key
t("Hello Idiom!")
# With interpolation
t("Good morning, {{name}}. We hope you are having a great day.", %{name: "Tim"})
# With plural and interpolation
# `count` is a magic option that automatically is available as binding.
t("You need to buy {{count}} carrots", count: 1)
# With namespace
t("Create your account", namespace: "signup")
Idiom.put_namespace("signup")
t("Create your account")
# With explicit locale
t("Create your account", to: "fr")
# With fallback locale
t("Create your account", to: "fr", fallback: "en")
That’s basically it already. You mainly interact with the library through t/3
, with a few extra wrapper functions around the process dictionary to not have to repeat to
and namespace
every time.
Some other things Idiom supports out of the box:
- Fallback locales — Some keys not available in the target language yet? No problem, you can always fall back to a different locale (or a list of them) while you are still busy translating!
- Automatic resolution of the entire locale hierarchy — There are many situations where most of the keys are not different between geographies, but some are different between regions. This is covered by automatically resolving both
en-US
anden
when you passen-US
as the target locale. - Over-the-air messages - At this point in time, other than supporting localisation files from the local file system on startup, Idiom supports fetching translations over-the-air from both Phrase and Lokalise! Configure one of these providers and simply update your localisations without having to completely redeploy your application. Idiom is backed by an ETS table, so you can also add any other source you want and just update the cache yourself.
Full documentation is available on Hexdocs - please let me know what you think and file an issue on GitHub if something looks funky!
Cheers!