-
Notifications
You must be signed in to change notification settings - Fork 84
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
Consider adding gettext functions that accept locale as argument #112
Comments
I think we already have those they are just not exposed (but you probably knew that). |
This is also kind of a "natural" function to have as internally other functions would still be built on it, e.g.: defmodule Gettext do
def gettext(backend, msgid, bindings \\ %{}) do
backend.lgettext(get_locale(backend), msgid, bindings)
end
end would become just defmodule Gettext do
def gettext(backend, msgid, bindings) do
gettext(backend, get_locale(locale), msgid, bindings)
end
end (roughly ofc) The only nasty thing I foresee (but which is an implementation detail) is that arities will start clashing, e.g., |
@josevalim yes we have them as |
@whatyouhide right. I would consider exposing them instead so we avoid the argument issue. |
@josevalim expose the |
@whatyouhide because it is meant to be dynamic, no need to have them in the backend only on Gettext? |
The locale is meant to be dynamic but the msgids not necessarily, right? I mean in our use case we would call: MyApp.Gettext.lgettext(user_locale, "This guy scored a goal!") and still use |
@whatyouhide good call, yes. |
@josevalim so the thing will be that it will be nasty to generate private and internal |
@whatyouhide another option is to allow it only through Gettext and in the dynamic format... or just accept Gettext.with_locale is the way to go because of the API complexity. |
@josevalim the thing is that as I said above I think it would be pretty legit to use |
Don't we use the process dictionary? |
Correct, sorry, I meant the pdict :) |
Yeah, I think neither |
Have you measured? Because storing to pdict and a anonymous function sounds On Monday, July 25, 2016, Aleksei Magusev notifications@github.com wrote:
José Valimwww.plataformatec.com.br |
Yes, indeed it's tiny difference for a single call, but not having anonymous function creation it makes payload generating about 2 times faster, for 1 million recipients – translation calls take 0,09s instead of 0,15s. |
I'm torn a bit on this. On one hand, these macros seem really natural to have and they also bring improvements in terms of speed (slight) and garbage (with the anon function, this could get nastier than speed). However, on the other hand, we had no other users requesting this, which makes me think it's not a features many want; note that this may just be because users are ok with What do you suggest we do here? :) |
In your case, can't you just set the locale without with_locale? What is On Monday, July 25, 2016, Andrea Leopardi notifications@github.com wrote:
José Valimwww.plataformatec.com.br |
We probably can and likely will do (don't really remember why we didn't do it from the beginning), anyway, I think these new locale functions can wait. 💛 |
Awesome, let's wait if other users request this, especially now that they may see this issue. Thanks everybody for the help 💟 |
Right now it requires extra work and affects performance (e.g. the usage of
Gettext.with_locale/3
).An use case for it is the construction of push notification messages.
The text was updated successfully, but these errors were encountered: