-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Database-backed Gettext #280
Comments
👋 Please go ahead and explore this discussion. I believe all of the lookups happen through lgettext and lngettext functions, so you should be able to replace them in a custom backend to at least validate the approach:
Alternatively you can mix the projects and use handle_missing_translation to only go to the database when you don't have an alternative. So there should be no roadblocks for exploration and we can circle back once there is something you are pleased with. :) |
Hi @czwartyeon, do you have any updates here? :) |
I've been thinking about this problem because we've been looking into an option to automatically update translations without having to rebuild our applications and redeploy everything and I think I have an idea that could be generic enough. I particularly don't think it would be wise to hit the database for every translation request, so my idea would be to have, apart from the compile-time If we standardize this ETS table, we could then have different "syncers" that would fetch the translations, parse, and insert into the table and those would live on different libraries. An example library, would get all There could be a lot of different approaches that could get binary That being said, I think having a standard ETS format would be beneficial for these "runtime" loading and maybe could ship with a loader that just reads the If you think this approach would make sense, I can start working on a library to implement (my understanding is that I can quite easily do that without having to change Gettext, but I'll probably need to "re-implement" the |
Exploring this approach is certainly very welcome! |
@josevalim today I managed to give this a go and I think I made it work, but still a proof of concept. I created this repository: https://github.com/bamorim/runtime_gettext It contains three projects:
RuntimeGettextThe RuntimeGettext library is composed by:
|
this looks great! What we probably want to do is to allow multiple repos to be given. Then we go through each repo in order and if they don’t find something they return If we do find something then we call the Interpolator. Otherwise we say translation not found. Would you like to submit a request to this repository exploring how it would look like? Thank you! |
Hey, thanks for the response. I like the idea of multiple repos, I can definitely give it a try. However, at the same time, it might be putting a lot of complexity unnecessarily as one could easily create a repo that does exactly that: look into multiple sources. But I can explore this idea, for sure. One thing I didn't got is "Otherwise we say translation not found". This means we call super? |
Also, when you say "submit a request to this repo" are you referring to bamorim/runtime_gettext or elixir-gettext/gettext? |
The idea of multiple repos is to solve the problem with super. This way it is your choice to keep the default behavior as a fallback or not. If none of the repositories have a translation, then we return the error translation not found tuple. And I meant a pull request to this repo, yeah :) |
So one of the repos would be the one "calling super"? I don't see how that is possible since only the function can call super. Maybe if the repo just returns :super instead. |
Unless we change the compiler to create the default compile-time behavior as a repo (either in a nested module or in that same module) and the default repos being |
I see what you mean. So I agree with you, there is no need for a list, we just call a repository module if any was configured. |
Okay, I'll open a PR with a proposal on how that would look like "natively" here. |
Closing in favor of the PR. 💯 |
@whatyouhide Since the PR was closed, should this issue be re-opened? |
@peaceful-james in this case, the PR was closed because we don't believe this is the responsibility of Gettext overall, so it should remain closed. I think a generic translation layer should probably be built on top of Gettext, as outlined in the PR. |
Hi!
Hope you're well.
I and my team recently thought about integrating gettext with the database as a persistence point; unfortunately, we've stumbled upon this topic on the elixir forum: https://elixirforum.com/t/gettext-backed-by-db-ecto/19099 that suggested alternate solutions, with concerns that it might not be achievable.
However, we believe this is the best place to ask about such an issue; if possible, I would be more than happy to help make it happen.
One of the solutions we imagined might help could be:
I'm open to discussion.
👋
The text was updated successfully, but these errors were encountered: