New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internationalization (I18n) #610
Comments
@jodosha have you ever thought about letting the browser (frontend side) to handle |
Glad to see internationalization making it into I'm a little concerned about using the It also monkey patches |
@joneslee85 interesting approach. It would involve JS on the frontend, right? What if you have just an API which serves i18n (error) messages to the client (not necessarily a browser)? @cllns Probably I meant using i18n is a bit rough in the sense of using it with Hanami (Lotus, back then) is difficult because it does not integrate that well. If I remember correctly:-) How about we start with the i18n gem but make sure our own interface is used? Also localization (i10n) should also be considered. Date/Time/NUmber formats, Currencies... |
@joneslee85
I haven't considered this scenario, but I'd discard it for now. This front-end scenario is an advanced use case which doesn't make sense to implement if we first don't have basic use case in place. In other words, server side first. Please remember that until now we don't have any JS support out of the box. Using JS for that, would mean to implement that JS support first, by delaying I18n. Betting on front-end for I18n makes the assumption that a JS engine is always available. This isn't true for several cases, think of browsers with disabled JS, or error messages sent over HTTP JSON API.
This sounds like a third party gem. For instance, I wrote something similar for Rails a few years ago: https://github.com/jodosha/rails-i18n-js |
It's a standard in Ruby world, there aren't better alternatives (as far as I know), and we already support it with |
Where, specifically? In views/templates we should use the new helpers mentioned in the description. For all the other contexts, I think that referencing directly
I intentionally didn't included l10n, because the This task will require a huge effort to organize that data. This is the biggest challenge for l10n for us. When we will have data in place it should be easy to write an API around it. I'm for shipping i18n first and then l10n. |
Did you consider gettext? |
@sakuro I don't know about the current state. The last time I used gettext it was horrible to get it working. |
To clarify: I used gettext maybe 7 years ago in a Rails project. Three different gems were required. I don't know anything about gettext of 2016. |
@hanami/core-team any feedback? Started implementing i18n. Some questions popped up: Hierarchy of YAML files in container architecture
Unless we implement some sort of hierarchy the load order will define what translation will be shown. Last one wins. Configuration Do you intend (or does it already exist) to provide a configuration of I18n via Hanami or should developers use standard I18n config? Sidenote |
For the Hierarchy question, I think the files should be isloated/scoped to the app their defined in. Is there some reason this isn't feasible? |
@cllns not sure if this kind of scoping is supported out of the box by i18n. Since we work with static/self methods, I don't think there is a way to switch out sources depending on app context. |
Can we fake it then? Like make "Welcome to App A" equal to |
probably this would work. Custom Backend perhaps. Let's see.... |
@pascalbetz Good catch! My suggestion is to do something similar to So: def routes
Web::Routes
end Can we think to have namespaced translation files: # apps/web/config/locales/en.yml
en:
web:
welcome: "Welcome" # apps/admin/config/locales/en.yml
en:
admin:
welcome: "Welcome to the admin panel" Then at the runtime we create Web::I18n.t('welcome') # => "Welcome"
# equivalent to
I18n.t('web.welcome') # => "Welcome"
# equivalent to
I18n.t('welcome', scope: 'web') # => "Welcome" Then, def t(*args)
Web::View.t(*args)
end Please have a look at: |
Hello @jodosha Thanks for the feedback. Having scoped YML files is probably the easiest way. But i'm not sure I like it.
In short, i'd really like if we could have the translations isolated. What do you think? |
Some more thoughts:
|
Hi @pascalbetz !
If they can still use
???
Right, and I think we should remove this practice after 1.0, but until then it's consistent with the other constants (eg. routes)
Sure. Is this bad or good for you?
That is great. What's your idea? 😄 |
@pascalbetz I have the impression that I poorly explained my idea. My proposal is to scope the translations only in the YAML file. The API should make the scope transparent. For instance in views/templates/helpers we should make this to work: Outside of that context (eg. actions, interactors), they should use Does this clarify the intent? |
Now I understand:-) It will still allow users to do:
right? Not saying that this is bad. Just pointing out to understand the expectations. For the implementation |
Yes.
Yup, that is an internal information, that |
Ok, i came up with something (yet basic though and WIP but should help for discussions).
I try scoped to the application first, then unscoped. I think this would be usefule as it provides some sort of fallback:
If nothing is found, then the error message will report the unscoped key as missing. @jodosha what do you think? |
@pascalbetz Yes, I like the idea of the fallback. IIRC |
Could we consider isolating I18n in its own service? On Aug 9, 2016 13:48, "Luca Guidi" notifications@github.com wrote:
|
@k-solutions can you explain a bit more? |
@jodosha I18n provides a cascading backend, but AFAIK it does not "try with and without scope". Anybody? |
Well, it could live outside of application and could have a common API and Regards, On 9 Aug 2016 6:37 p.m., "Pascal Betz" notifications@github.com wrote:
|
@k-solutions To clarify, are you suggesting a microservice for I18n, to live on its own process? |
From any application point I18n is outside there business domain, so it's On Aug 10, 2016 9:52 AM, "Luca Guidi" notifications@github.com wrote:
|
The intent is to use I18n gem. It provides different backends (YAML, Gettext PO Files, DB, ...) and will be hidden through Web::I18n.translate # or just .t, for short
Admin::I18n.translate
# and so on, one for each app in your hanami project What do you think? Can you detail how the Rack middleware would look like/work? Thanks for your input! |
@k-solutions A microservice is out of scope: it complicates deployment and introduces performances penalties because translations should be communicated down to the wire rather than accessed from memory. A Rack middleware is not viable too, because translations would only be available in web contexts, while we aim to make them accessible from all the parts of an application (eg. an entity). |
Well then we left with Rails approach to integrate I18n deep into framework Side note ...not sure it make sense for business use case to have I18n on On Aug 10, 2016 1:24 PM, "Luca Guidi" notifications@github.com wrote:
|
I'm closing this for now, but I'd like to resume the discussion with all of you after 1.0. |
I guess the time has come. ;) |
@jodosha Now that we're getting close to |
@jc00ke Which specific errors did you get in for validation error messages? Is it worth to open a ticket in Is there anything else you think we should consider? |
Sure, I can open an issue in |
Introduce I18n features:
i18n
gem as dependency tohanami.gemspec
:en
locale (this is useful forlib/
). It could be placed underconfig/locales/en.yml
.:en
locale. It could be placed underapps/web/config/locales/en.yml
.I18n
load paths (I18n.load_path.concat
)hanami-validations
) should use:i18n
messages engine instead of the default:yaml
. The files generated above should be used by developers to indicate validation failures.Hanami::Helpers::I18n
to ship with a public method#translate
, (aliased as#t
), to be available in views and templates. This should be a shortcut toI18n.t
.The text was updated successfully, but these errors were encountered: