http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
You can do pretty much everything you mentioned with the I18n#t method
and the "t" view helper (<%= t :key %>). Note that you'll just use
symbols instead of messages in your code, and leave the actual textual
messages (including in your base language, say English) for the
translators. So in your code, instead of writing "you are not logged
in", you'd do something like <%=t :not_logged_in %>. You'll need some
kind of translation front end, or you'll have to edit YAML files,
depending on the plugin.
The reason we didn't want to put strings right in the code is that if
you decide to change the message text in the base language, that
messes up the messages in the translated languages, and the message
will no longer be translated correctly.
-- Josh
On 20.07.2008, at 22:16, Trevor Turk wrote:
> On Jul 20, 1:34 pm, "Joshua Harvey" <jos...@gmail.com> wrote:
>> You can do pretty much everything you mentioned with the I18n#t
>> method
>> and the "t" view helper (<%= t :key %>)...
>> You'll need some
>> kind of translation front end, or you'll have to edit YAML files,
>> depending on the plugin.
>
> After rereading Sven's article, it sounds like I might even be able to
> avoid using a plugin for my simple case.
Yes, I think that might work.
> If I followed the same
> technique covered in Sven's article under the "Populating the
> translations storage" heading, I should be able to store the locale in
> memory, which would then be accessible to the "t" helper.
Yes.
> Taking a
> quick look through the Rails source, it seems that a way to choose
> from a list of available localizations to load (and to load the one
> chosen) is all that is missing to meet my needs.
Yes, that's a feature we didn't add to the Simple backend.
Maybe the way to go might be that you'd just re-open the Simple
backend and add that method yourself? I.e. your own mini-plugin for
this purpose. Should be super easy to do.
> Maybe I'm missing something, though...
I don't think so :) If your app is simple that might be everything you
need.
One thing to keep an eye on might me more nifty pluralization rules.
That of course depends on the languages you need to support. The
Simple backend (purposely) does not provide any means to customize the
pluralization algorithm for now. Again, this is easy to extend though:
module MyPluralizationBackend
include SimpleBackend
def pluralize(*args)
# your pluralization logic
end
end
I18n.backend = MyPluralizationBackend
HTH :)
If you succeed with this it would be mega awesome if you could write a
short howto-style blog post about what it took to use the Rails I18n
api for your app, cause that's something really missing right now.
Please feel free to suggest changes and ask questions.
Thanks for chiming in.
On 21.07.2008, at 05:30, Yaroslav Markin wrote:
> My question is regarding better "conditional translations" support,
> if I can say so. One of biggest advantages of having i18n support in
> the Rails core is to avoid monkeypatching, and I still need
> monkeypatching right now to support Russian datetime translations,
> for example [1].
I think you're right that this is one of the things not immediately
supported by the api.
Sticking to the terminology of the api I'd say that what you want to
do is *pluralize* the month names when localizing a date? Is that
correct?
If so, do you probably additionally need pluralization algorithms for
this purpose? Or are they the same as the pluralization rules for
month names in general?
> Is there any chance of adding some kind of lambda translations in
> the core?
I think that's unlikely at this point. I agree it's (although more
theoretically) an edge case. But one can always replace the Simple
backend by something more powerful.
I'd suggest you'd do exactly that: implement a backend that can cope
with this sort of case, look for languages that have the same kind of
requirement and publish it in some way. We could then, in our next
"round", again cherrypick solutions (e.g. you're extension) and
discuss whether they should go into core.
This approach forces us to first experiment with the api in our
plugins (or extensions, custom backends, whatever) instead of just
committing stuff to Rails - I believe this is an important point about
the progress. (E.g.: the solution to Russian datetimes might not work
for another language which might need only slightly different tweaks
to the same stuff. This would become visible when you publish your
solution. So you'd be able to fix that before it would go into core.)
> Also, Sven suggested we may have a wiki for discussing stuff like
> that -- i.e. what other languages need from i18n that is not
> supported / well done right now, may be github project wiki will do?
Yeah, maybe. Although I've rarely seen really useful GitHub wikis so
far. Maybe the code repository is just not the place where people work
actively with this sort of stuff.
I'm also planning to set up a site for this group at http://rails-i18n.org
maybe including a wiki but that's not ready, yet.
> My question is regarding better "conditional translations" support,I think you're right that this is one of the things not immediately
> if I can say so. One of biggest advantages of having i18n support in
> the Rails core is to avoid monkeypatching, and I still need
> monkeypatching right now to support Russian datetime translations,
> for example [1].
supported by the api.
Sticking to the terminology of the api I'd say that what you want to
do is *pluralize* the month names when localizing a date? Is that
correct?
> Also, Sven suggested we may have a wiki for discussing stuff like> that -- i.e. what other languages need from i18n that is notYeah, maybe. Although I've rarely seen really useful GitHub wikis so
> supported / well done right now, may be github project wiki will do?
far.
> I think you're right that this is one of the things not immediately
> supported by the api.
>
> Sticking to the terminology of the api I'd say that what you want to
> do is *pluralize* the month names when localizing a date? Is that
> correct?
On 05.08.2008, at 17:23, Yaroslav Markin wrote:
> We need month name inflection; we need to inflect month names if we
> are displaying month name with a date -- you can see the logic here, http://rutils.rubyforge.org/svn/trunk/lib/datetime/datetime.rb
> Notice how RU_INFLECTED_MONTHNAMES constant is used in strftime. We
> need that in select_month as well.
I going to use that example in my talk. Also, I think I really need to
better understand what's happening here.
Stupidly, Mail.app does not let me paste those Russian month names to
this email.
So: http://pastie.org/private/zztlgee76slerozan0oqq
I'd like to learn what kind of Inflection is happening here. Can you
point me to some wikipedia page about that or something?
> Uh hum Prototype wiki?
Prototype wiki?
sample from cldr/main/pl.xml:
<calendar type="gregorian">
<months>
<monthContext type="format">
<monthWidth type="wide">
<month type="1">stycznia</month>
<month type="2">lutego</month>
<month type="3">marca</month>
<month type="4">kwietnia</month>
<month type="5">maja</month>
<month type="6">czerwca</month>
<month type="7">lipca</month>
<month type="8">sierpnia</month>
<month type="9">września</month>
<month type="10">października</month>
<month type="11">listopada</month>
<month type="12">grudnia</month>
</monthWidth>
</monthContext>
<monthContext type="stand-alone">
<monthWidth type="wide">
<month type="1">styczeń</month>
<month type="2">luty</month>
<month type="3">marzec</month>
<month type="4">kwiecień</month>
<month type="5">maj</month>
<month type="6">czerwiec</month>
<month type="7">lipiec</month>
<month type="8">sierpień</month>
<month type="9">wrzesień</month>
<month type="10">październik</month>
<month type="11">listopad</month>
<month type="12">grudzień</month>
</monthWidth>
</monthContext>
</months>
Yes.
> Now I just need to learn how to pronounce them so I can read them in
> my RailsConf Eu talk :D
You can start with listening a sample here:
http://en.wiktionary.org/wiki/%D1%8F%D0%BD%D0%B2%D0%B0%D1%80%D1%8C :)
On 09.08.2008, at 16:19, Yaroslav Markin wrote:
> So, is there any way in near future to apply this http://gist.github.com/3436
> ?
personally I still think this is a good idea because it sort of
(further) unifies the API.
I'd like to hear some more opinions ideally :)
> Today we realized that writing a backend for russian language (for
> example) is not really a big deal, but you won't be able to do multi-
> language application using it. You won't be able to use
> pluralization, for example -- russian language needs an array of
> three as <tt>entry</tt> parameter.
The pluralization algorithm (which maps the :count to the translation
to pick) would need to be stored externally/dynamically per locale,
right?
That could either work with passing lambdas, defining dynamic methods
for it, even eval'ing code snippets stored in the db (or CLDR data) ...
> Defining labmdas in translation table as a strftime format or as a
> pluralization rule for a language would be a problem solver. Same
> probably goes for capitalization in danish language?
I guess you mean Dutch :) Yes, most probably.
> Sven, could you please comment what is wrong with http://gist.github.com/3436
> or with Clemens' plugin? What is the work to be done so this
> functionality can be merged into core, how can we help?
Well, so far this code is not actually working because we'd need to
figure out how/where to raise and catch exceptions in the right way so
that all the combinations work the way we'd expect them to. Much of
this should be covered by the test already, I think.
So if you'd want to help here (which would be awesome), maybe the best
starting point is just replacing the current code with that gist
snippet and see what tests break. Then figure out what tests are
missing. And then fix everything :)