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
Gettext public API #11
Comments
I have no preference here. The first solution (warning to check strings in the As for the locale customization, gettext seems to still require some kind of manual setting of the locale, e.g., calling a |
|
All the cons in the first approach does not exist in the third approach. The first approach has the benefit of not introducing a new API. But that is its downside too, people will use However, if we give up on the first approach and make Thoughts? |
This makes a pretty good point. If we're not going with the first approach, then the third approach would probably produce the cleaner code. We could heavily refactor the |
This is a welcome refactoring anyway. :) |
This will be annoying because you would get the warning on every compilation even though it's perfectly valid code. I like the third approach best. Will users define their own
I had the same problem when creating Decimal. I was following a specification and had to convert the API to Elixir conventions. In Decimal I went around some of the global APIs (like setlocale/1) by using the process dict. |
Yep.
We're most likely going to do that in gettext as well, as José mentioned in the first proposal. That said, I don't like @josevalim I'm going to refactor that part tomorrow if I can, I had that in mind for a while now :). So, any thoughts on how to set the locale? I think once we decide that I can start implementing, right? |
Go ahead!
I can think of two options (read and write):
Both are used in Elixir and I prefer the second (we use it for example in |
The third option is what I would lean towards.
This is also what I was thinking. Are we also going to provide a |
I'm actually in favor of We can provide a variant of |
As for making the locale per-backend, I have no preferences here but making it per-backend may turn out to be more versatile. Wdyt? |
One downside of making it per backend is that you would need to do in a Phoenix app something like: MyApp1.Gettext.put_locale "pt"
MyApp2.Gettext.put_locale "pt"
MyApp3.Gettext.put_locale "pt" And I can't think of cases you would explicitly want different locales per gettext module. |
So we're going with only one locale per process, providing |
Let's go with |
Based on our IRC talk, let's add:
The four last functions should return a string or raise if we got an error. |
Hey @josevalim, if we're going to provide
right? Should we move that to the configuration of the |
Yes. Good catch. The first time we read the locale, if one is not set in the pdict, we read from the application and store it. |
Closing this for now as the public API is kind of ready. :) |
For now all the work has been done on Gettext internals and it is time to discuss the public API. What I would like to call is this:
And this does a couple things:
.po
files. In order to be collected, the first argument needs to be a string at compilation time.:en
but the default can be customized with the:default_locale
option onuse
. What is the official gettext API for setting locale?However, this discussion brings one main question: what should be the API for doing dynamic lookups?
One option is to do the dynamic lookup still using the gettext macro:
And then, when generating the default
.po
file, we would warn on such usages so users remember of checking those strings into their.po
files.Another option though is to ask the users to go through the currently "private"
lgettext
function for doing the dynamic lookup. In doing such, they would need to explicitly pass the locale, domain and what not.The third and final option is to introduce another set of functions that would be used for the dynamic lookup. Or even provide an API in the main Gettext module itself:
The rationale behind this last one is that for dynamic lookups the gettext module will likely be dynamic too, so provide an API that receives both is ok.
Thoughts?
The text was updated successfully, but these errors were encountered: