belaustegui
Trans - Embedded translations for Elixir
Hi all.
A few days ago I published my first package in Hex.pm. It is called Trans and aims to provide a easy way to leverage database support of JSON datatypes to store translations. Trans is heavily inspired by the incredible gem hstore_translate.
The traditional approach of having adjacent tables for storing the translation information quickly increases the number of JOINs required for retrieving data, especially when a single query contains multiple models. The approach provided by Trans stores translations in a single column of each model, so when a model is retrieved so are it’s translations. Modern RDBMSs provide support for this kind of unschemed data and to use conditions in it.
If you find it interesting, take a more detailed look at:
- Trans page on Hex.pm: trans | Hex
- Trans documentation: API Reference — Trans v3.0.1
- Trans code: GitHub - crbelaus/trans: Embedded translations for Ecto · GitHub
Any suggestions, issues, ideas and contributions are more than welcome.
Love ![]()
Most Liked
belaustegui
Hi again! I’ve just published a new release of Trans.
Thanks to @sfusato, @RxAssim and Philipp Waldmann for their awesome contributions:
- Translations can now be stored using embedded schemas. This is now the preferred way of using Trans since it provides stronger, explicit and easy to use translations. The old plain maps are still supported, of course.
- Entire structs can now be translated using the new
translate/2function - We can automatically raise an error if a translation does not exist by using the new
translate!/3function. - Documentation has been greatly improved to showcase the new structured translations approach and to include specs in the public functions.
This release also updates the Trans dependencies to ensure clean compilations without warnings and requires Elixir 1.7 or higher.
You can see the release notes on GitHub or fetch the new version from hex.pm.
As usual, any comments, suggestions or pull-requests are more than welcome.
Love ![]()
belaustegui
Thank you very much for your words @OvermindDL1 and @schp ![]()
The mission of Trans is to provide an easy way to retrieve translations from structs or maps, and (optionally) provide an interface for generating Ecto queries by adding conditions on translated fields.
Trans has two main components:
- The Translator mission is to retrieve a translation into the desired language, or fall back to the default one if no translation exists. (I also plan to allow more flexibility into the fallback process).
- The QueryBuilder mission is to allow creating or modifying queries based on translated values. This component does require Ecto and leverages the power of the JSONB data type of PostgreSQL databases to look into the translations for the queries.
At the moment Trans has a hard dependency on Ecto, but I intend to make this dependency optional in the next version. Then, you will be able to use the Translator component without Ecto in any application.
The QueryBuilder will still require Ecto to work though, but it won’t be even compiled if Ecto does not exist in the application.
Edit: I actually plan to support MySQL also, since newer versions also have a JSON type. But there is an open issue in the Mariaex adapter to add support for this type that must be addressed first. I could look into it myself, but I would need some guidance into where to look first ![]()
belaustegui
Hi again! We got a new version of Trans!! ![]()
The only change in the new 2.1.0 version is the support of Ecto 3.0 as a dependency. Client code using Trans should keep working as usual without any modification.
You can see the release notes on GitHub or fetch the new version fron hex.pm.
As usual, any comments, suggestions, issues or pull-requests are more than welcome!
Love ![]()
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








