belaustegui
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 ![]()
Trending in Announcing
Other Trending 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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
belaustegui
Trans is now on version 1.0.0
!!!
You can see the release notes on GitHub. The main changes of this version are the improved support for Elixir 1.3.x and the new requirement of Ecto 2.0.
You can update the version of Trans in your project by adding
{:trans, "~> 1.0"}to yourmix.exsand then runningmix hex.update trans.As usual, any comments, suggestions, issues or pull-requests are more than welcome!
Love
belaustegui
Hi again! We got a new version of Trans!!
The version 1.0.1 is a minor release that focuses mainly on making Trans more comprehensible by improving the documentation and adding a changelog that conforms to the Keep a Changelog format.
You can see the release notes on GitHub. There are also some nice improvements planned
As usual, any comments, suggestions, issues or pull-requests are more than welcome!
Love
belaustegui
After a long time we have a new version of Trans.
The main changes in version 1.0.2 are:
earmarkhas been removed, since it is already required byex_doc.CONTRIBUTING.mdfile has been added, detailing the contribution guidelines.You can see the release notes and the planned improvements on GitHub.
The next Trans version will focus on making Ecto an optional dependency that is only required when using the QueryBuilder component.
As usual, any comments, suggestions, issues or pull-requests are more than welcome!
Love
OvermindDL1
So this is not so much for translations of the application, but rather for easily allowing users to create their own translated content for a given set of data? Looks useful.
agustif
This is awesome for user-generated sites aspiring to manage multi-lang effortlessly in PostgreSQL with leverage of JSONB types.
Thank you very much for posting about it, I had already in my github stars but forgot about the project now that it might come useful for a side project
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:
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
I’ve released a new version of Trans
Trans 1.1.0 makes Ecto an optional dependency.
This update addresses one of the main concerns of trans since its inception: to leverage, but be usable without, a database. The
Trans.QueryBuildercomponent requires Ecto to work, but theTrans.Translatorcomponent can be used with any struct or map and does not require a database.As usual, any comments, suggestions, issues or pull-requests are more than welcome!
Love
belaustegui
Trans 2.0 is out!
This release of Trans is focused on improving the library interface and making it more safe and usable.
The
Trans.QueryBuildermodule has been completely rewritten. It now exposes thetranslated/3macro that generates an SQL fragment that can be used when building Ecto queries.The new
translated/3macro is compatible with all the functions and macros inEcto.QueryandEcto.Query.Apiand provides safe checks against translations on non existing or non translatable fields.Compare how you would create a query with Trans 2.0 and before:
More detailed release notes can be found at GitHub. I also plan to publish soon an article explaining the changes and the reasoning behind them.
EDIT: the promised article about the changes in Trans 2.0 is now published in Medium
As usual, any comments, suggestions, issues or pull-requests are more than welcome!
Love
Eiji
@belaustegui: Can you explain why you decided to have all translated columns in big
jsonb?After read your description here I through that you do something like:
so any
trans_fieldis a separatemapcolumn.How about performance when you have big
jsonbmap (with lots of fields) and lots of records?Do you validating language codes?
For your #12 and #14 issues: in some cases developer prefer to store locales in database for example table named
localescould have fields:id,locale,fallback_locale_id,nameanddescription.btw. You have still opened
2.0.0milestone and already released2.0.0versionbelaustegui
Hi @Eiji , I really appreciate your comment.
, it is closed now, thanks!
I completely forgot about the milestone
Your idea of
trans_fieldlooks really good indeed. Could you open an issue in the project so we can discuss it further?I went with this approach for Trans because I wanted to port the hstore_translate gem to Elixir.
I share your concerns with the big
jsonbfield containing all the translations, in particular when fetching lots of data in queries. I’ve not been able to test Trans in any project with high data volume. I’ve used thehstore_translategem in a Ruby project and this approach was faster than having the translations in their own separated tables (theglobalizeapproach). I think that this performance gain will still apply in Elixir.I may perform a test comparing Trans performance versus having the translations separated in different tables. It would be a very interesting comparison
Thank you very much!
Cheers.