To prove that fullstack Gettext support using the Rails I18n API is
possible and the way to go I've played with an experimental Gettext
helper layer and backend: github.com/svenfuchs/i18n/tree/gettext
As I don't have a real usecase for this right now I'd like to ask
Gettext folks to help improving this. :)
The goal basically is:
- have standard gettext'ish helpers like _(), n_() etc.
- have a backend that reads po/mo files and stores them in the
standard translation format
- somehow announce expected translations for computed keys in a
gettext'ish manner (so source code parsers can pick them up)
That would use the standard API both on the input and output side and
thus allow us to combine this with other tools like a caching layer or
whatever else.
So, any takers?
thanks for joining the discussion here :)
On 01.05.2009, at 05:49, mateo wrote:
> The attribute name concatenation issue is one that is frequently
> mentioned, but it seems to me that the solution is trivial; since
> error translations already support attribute interpolation, simply
> change the default error messages to include {{attribute}} at the
> beginning, and turn off concatenation.
Yeah, I agree with that. But I also agree with the sentiment that the
implementation of the full_messages helper is just wrong from the
perspective of proper I18n, we just should not concatenate anything
like that in Rails core.
> For backwards compatibility, a
> config option could be added to turn concatenation back on, or even a
> "smart" mode could be implement that only concatenates if
> {{attribute}} isn't found in the translation value. I can write a
> patch with tests for this, if you'd like.
The "smart mode" doesn't sound too bad to me, but the API currently
does not allow to check whether or not a value was interpolated to it.
So no matter how that's solved, it'd be a bit ugly.
Not sure, but why not not control this solely through the availability
of translations?
Can you explain why you want to write out the message? Because you
want to use a gettext source parser for identifying your messages? Or
is there another reason?
I've had a look at this issue yesterday.
For one thing with Clemens' Lambda support it should now already be
possible to do:
validates_format_of :account, :messages => lambda { _("foo") }
That should make both source parsers happy and work as expected.
Another option to solve this situation might be:
validates_format_of :account, :messages => gettext_noop("foo").to_sym
WDYT?
On Fri, 1 May 2009 13:52:41 +0200
Sven Fuchs <sven...@artweb-design.de> wrote:
>
> Hi Masao,
> # Different approaches
>
> Obviously we have a few different approaches to integrate Gettext with
> Rails I18n. I do not agree with that we must pick one of them. Instead
> we should try to support all of them as smoothly as possible because
> all of them target different needs. (I'm referring to Gettext as one
> example of third-party solutions.)
>
> 1. Rails I18n for Rails core, Gettext for everything else not using
> the I18n API
> 2. Rails I18n with a Gettext backend that falls back to the Simple
> backend
> 3. Rails I18n with a pure Gettext backend
>
> As far as I understand it (please correct me if I'm wrong) the
> following libraries take these approaches:
>
> 1. rails-gettext (your library) and fast_gettext (Michael Grosser)
> 2. i18n_gettext (Sam Lown)
> 3. (there's no solid implementation)
>
> Let me say clearly that I see all of these approaches as perfectly
> valid. They obviously solve problems for people so in my opinion
> there's no point in arguing that away.
1. is correct.
I don't know i18n_gettext well, but exactly, 2, 3 approach is needless.
We don't need that anymore.
> Now one of the reasons for geekQ to post their proposal that sparked
> the discussion on rails-core was that they want to manage *all* of
> their translations through Gettext (e.g. in order to enable
> translators to use poedit everywhere). It seems to me that there is no
> other way to fullfil that requirement to either implement approach 3)
> or just throw away Rails I18n, go back two years and try to implement
> pure Gettext right into Rails core (which isn't an option). And that's
> the reason for my previous experiments :)
He may think so.
But in my opinion, the real problem was monkey patches of gettext.
The reason why gettext have monkey patches is ruby-core's i18n
support has been poor yet. But it can improve with current i18n.
--
Masao Mutoh <muto...@gmail.com>
One of the reason of it is fit is gettext.
But don't think it's "only gettext problem". It's better to support both
style in this area.
Other reasons:
1. It's not beautiful to use to_sym or lamda.
Especially, symbol can't solve anything here for gettext.
2. It can't solve my "2. Calling same methods in different languages "
problem.
If ActiveRecord::Errors#generate_message is called
in #full_messages/#on/#each not #add, all problems are fixed.
It's not difficult and also gettext already has this kind of the monkey patch.
--
Masao Mutoh <muto...@gmail.com>
> Not sure, but why not not control this solely through the availability
> of translations?
Well, I think that ideally concatenation should be removed completely.
Even in english it forces you to write your error messages in a way
that isn't always natural. I think ideally it would be deprecated, but
supported for backwards compatibility, and with 3.0 coming up, now is
probably the best time to do it...
@Masao Mutoh:
> If ActiveRecord::Errors#generate_message is called
> in #full_messages/#on/#each not #add, all problems are fixed.
> It's not difficult and also gettext already has this kind of the monkey patch.
Right, I had trouble understanding what you meant by "lazy
localization support", but this makes it clear