-
Notifications
You must be signed in to change notification settings - Fork 87
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
Add a way of marking a string for translation #131
Comments
Can you please provide a bit more context? I cannot see how this would be used in the context of Phoenix. Also Phoenix and Ecto were designed precisely so you don't translate in the schema. The translation happens at another layer which is concerned about translations. Although I am fine with supporting other mechanisms, I just want to point out our preference. |
If you write |
sure. my use case is simply adding a custom error message. maybe i just missed how to do it correctly. So in my example i want to add the custom error message "Some error" to the field "field". I could do I could also do |
Right. The idea is that you would do that and then add it to the .pot file (only once). From .pot it will be moved to .po. Another idea (which I don't like but I thought I would put it out there anyway) is to still call
Assuming though you want to write |
(also want to mention: lookup of translations is ridiculously inexpensive in Gettext - and also side-effect free -, so there may be a good chance that this is not where your app is spending time :) ) |
@whatyouhide I'm not concerned about performance at all. it just seems wrong to translate twice. especially as the second time, the already translated string would be translated. so i would actually be calling @josevalim maybe we misunderstood each other even. i don;t want to call if i understood the gettext code correctly, it would look something like: defmacro remember_for_gettext(msgid) do
if Gettext.Extractor.extracting? do
Gettext.Extractor.extract(__CALLER__, __MODULE__, "default", msgid)
end
msgid
end |
to also show how it would be used in the example above: add_error(changeset, :field, remember_for_gettext("Some error")) |
So, I think this feature is actually doable and could make sense. We could have extract("Some error")
dextract("errors", "Some error")
nextract("Some error", "Some errors")
dnextract("errors", "Some error", "Some errors") These macros would just extract the string and return it. We could the implement the current I'm not sure about this name as we usually tend to What do you think? |
I am still not convinced why we should not use: @missing_foo gettext("missing foo")
def missing_foo(changeset, field) do
add_error(changeset, field, @missing_foo)
end |
@josevalim that was my first thought and I was about to write a message about that, but then I thought about why we have gettext in the first place, and one of the reasons was to have |
in our app we've called the helpers @josevalim's last proposed way would mean that the translation of the translation ends up in the template. i agree that that probably never is a problem, as whatever the proper way would be to manually add "missing foo" to the |
@manukall with
it's still deeply wrong as a concept 😄 |
Ah, yes. So I think gettext_extract, ngettext_extract and similar would be better. |
For the record, Python supports this as well: https://docs.python.org/3/library/gettext.html#deferred-translations. Shall we proceed and do it @josevalim? I am terrified of feature bloating but this is a hard call cause it looks like this has its use cases 😱 |
Sounds good! |
Maybe we should also use |
Started implementing this and ran into something that puzzles me: what do we do with plural translations? Do we use English's rule so that: gettext_extract("foo") #=> "foo"
n = 3
ngettext_extract("foo", "foos", n) #=> "foos" ? |
@whatyouhide we should return the id on all of them IMO. After all the goal is not to translate but to keep the reference for translations later on. |
As it turns out, the name gettext gives to this is |
👍 for noop.
…On Wed, Nov 30, 2016 at 00:20 Andrea Leopardi ***@***.***> wrote:
As it turns out, the name gettext gives to this is gettext_noop so my
suggestion is to just go with (d|n|dn)gettext_noop for this :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#131 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAlboKIT3f7gYtXW7nA7CSLIo7cEq_Eks5rDLNBgaJpZM4Kuj3T>
.
|
I would like to propose a feature that is also found in the ruby gettext gem:
= N_("Apple") which does not translate, but tells the parser: "Apple" needs translation.
This would be useful for the
mix gettext.extract
task and add "Apple" as msgid to the po files.I would especially like to use such a feature in my Ecto validations. Currently there isn't really a nice way to add translatable error messages without manually adding them to the .po files.
Using gettext from within the model (
add_error(changeset, :field, gettext("Some error"))
) in a standard Phoenix project would result in double translation, as the generated ErrorHelpers will translate the already translated error message again.The text was updated successfully, but these errors were encountered: