I18n generators gem

49 views
Skip to first unread message

Akira Matsuda

unread,
Nov 17, 2008, 1:22:04 AM11/17/08
to rails-i18n
Hello, my name is Akira.
I'm a Railer from Japan, and I think this is the first time to give a
post here by myself.

Now, let me announce that I wrote a gem/plugin to support I18n Rails
application development.

http://github.com/amatsuda/i18n_generators

This gem/plugin generates
* i18n locale files for ActiveRecord/ActiveSupport/ActionPack
* model names & attribute names translation file
for any locale you specified.

It internally invokes Ruby-Gettext-Package, scrapes the website of the
Unicord CLDR project, and calls Google Translation API to localize/
translate each value.
I know you can't release this kind of product officially as Rails I18n
team, because there's a little bit dirty hack inside, but I believe
this might be very useful to develop a non-US Rails application.

So, if you're interested in this gem, please give it a try by
% sudo gem install amatsuda-i18n_generators -s http://gems.github.com
and type in
% ./script/generate i18n YOUR_LOCALE
at your $RAILS_ROOT.

Any feedbacks and suggestions are welcomed!

Regards,

Akira

Yaroslav Markin

unread,
Nov 17, 2008, 2:00:15 AM11/17/08
to rails...@googlegroups.com
This is awesome, great work!

We've got a CLDR parser now :)

On Mon, Nov 17, 2008 at 9:22 AM, Akira Matsuda <pushi...@gmail.com> wrote:

Hello, my name is Akira.
http://github.com/amatsuda/i18n_generators

This gem/plugin generates
 * i18n locale files for ActiveRecord/ActiveSupport/ActionPack
 * model names & attribute names translation file
for any locale you specified.

It internally invokes Ruby-Gettext-Package, scrapes the website of the
Unicord CLDR project, and calls Google Translation API to localize/
translate each value.


--
Yaroslav Markin

Akira Matsuda

unread,
Nov 17, 2008, 2:44:34 AM11/17/08
to rails-i18n
Thank you, Yaroslav!

> We've got a CLDR parser now :)

Well... I noticed that project after I almost finished my
implementation...

Anyways, of course I knew that it might be better to use something
like XPath to parse the CLDR data in a good manner, and tried REXML
and Hpricot and Nokogiri, but, for me, they were unbearably slow and
eats a lot memory when parsing the huge amount of CLDR data.
That's why I finally decided to parse the HTML document by regexp
reluctantly.
Does your parser work fast enough?

Akira


On 11月17日, 午後4:00, "Yaroslav Markin" <yaroslav.mar...@gmail.com>
wrote:
> This is awesome, great work!
>
> We've got a CLDR parser now :)
>

Sven Fuchs

unread,
Nov 17, 2008, 7:59:17 AM11/17/08
to rails...@googlegroups.com
Hi Akira,

welcome to the list.

Wow, this makes an awesome addition to our toolbox! It's also great
that you've started gathering experience with collecting stuff from
CLDR.

I'd like to add this to the wiki. What would be a good description in
just a few words?

Maybe "generates scaffold locale files for Rails, model and attribute
names"?

Thanks!

Akira Matsuda

unread,
Nov 17, 2008, 12:02:55 PM11/17/08
to rails-i18n
Hi Sven,

First of all, let me apologize that I'd been away from here for a very
very long time (I guess you're enraged and full of anger), just
because I had been extraordinarily busy these few months...

> I'd like to add this to the wiki. What would be a good description in
> just a few words?
>
> Maybe "generates scaffold locale files for Rails, model and attribute
> names"?

Of course! That sounds great! I'm flying high on rapture!
I like that description, and, can you please put "I18n generators" as
the title?

Akira

P.S. I found another great thing in the wiki. The "Official" Hymn!
You know, my locale "ja-JP" is for Judas Priest, and I saw that Metal
Gods at Budokan just few weeks ago!
> > % sudo gem install amatsuda-i18n_generators -shttp://gems.github.com

Sven Fuchs

unread,
Nov 17, 2008, 12:33:20 PM11/17/08
to rails...@googlegroups.com
Hey Akira,

On 17.11.2008, at 18:02, Akira Matsuda wrote:
> First of all, let me apologize that I'd been away from here for a very
> very long time (I guess you're enraged and full of anger),

I'm absolutely not!

> just
> because I had been extraordinarily busy these few months...

Happens to all of us. There's no reason to apologize imo :)

>> I'd like to add this to the wiki. What would be a good description in
>> just a few words?
>>
>> Maybe "generates scaffold locale files for Rails, model and attribute
>> names"?
>
> Of course! That sounds great! I'm flying high on rapture!
> I like that description, and, can you please put "I18n generators" as
> the title?

Whoops. What a stupid mistake. I've corrected that.

> P.S. I found another great thing in the wiki. The "Official" Hymn!
> You know, my locale "ja-JP" is for Judas Priest, and I saw that Metal
> Gods at Budokan just few weeks ago!

Haha :)

Funny coincidence. Apparently they even played Painkiller? http://www.guitars101.com/forums/f90/judas-priest-nippon-budokan-tokyo-japan-29-09-2008-a-77384.html
How was it?

PanosJee

unread,
Nov 18, 2008, 9:40:43 AM11/18/08
to rails-i18n
Congrats for the release. I plan to migrate soon to Rails 2.2
Does your gem find the other string symbols from the yaml or views
files and appends them to the new locales ?

In that that case does it also translate form them Google or we have
to add them on our own ?

Many thanks

Akira Matsuda

unread,
Nov 28, 2008, 2:51:43 AM11/28/08
to rails-i18n
Hello.

I updated the i18n_generators gem.
Now it conforms to the Rails 2.2.2 official way of i18n config (use
environment.rb and config/locales/*.yml), and fetches the .yml file
from Sven's rails-i18n repository (thanks for adopting my jp.yml,
Sven).

> PanosJee

Sorry for my late reply.

> Does your gem find the other string symbols from the yaml or views
> files and appends them to the new locales ?
>
> In that that case does it also translate form them Google or we have
> to add them on our own ?

No, I'm sorry, that function is not yet implemented.
I just added your request to my TODO list (in my mind), so maybe it's
gonna be implemented someday...

iain hecker

unread,
Nov 28, 2008, 5:40:18 AM11/28/08
to rails-i18n
Hi,

Fantastic work Akira, I really love it!

I have one question though, why do you exclude created_at and
updated_at from the generated model translations? Why shouldn't they
be translated?

Furthermore I have one little alteration: on line 14 of
i18n_models_command.rb[1], can you change

next unless m.ancestors.include? ActiveRecord::Base

into:

next unless m.respond_to?(:content_columns)

This makes it a lot easier to add translations which are not based on
ActiveRecord. I can adjust my ActsAsTranslatableModel plugin[2] to
work in concert with your generator.

I also found one bug: when you specify translations for virtual
attributes, they get removed by the generator from the file, which
shouldn't be happening.

Anyway, Keep up the good work!

Iain Hecker
http://iain.nl/

[1] http://github.com/amatsuda/i18n_generators/tree/master/generators/i18n_models/i18n_models_command.rb#L14
[2] http://iain.nl/2008/09/acts_as_translatable_model-plugin/

Akira Matsuda

unread,
Nov 28, 2008, 6:02:24 PM11/28/08
to rails-i18n
Thank you very very much, iain.

> I have one question though, why do you exclude created_at and
> updated_at from the generated model translations? Why shouldn't they
> be translated?

I believe these columns are "system columns" just for framework-
internal use, and should not be revealed to the end users,
thus not needed to be translated as well.
If you need a timestamped column in your application code, you might
add another datetime column with values updated explicitly (not
automatically by the framework).

> next unless m.ancestors.include? ActiveRecord::Base
>
> into:
>
> next unless m.respond_to?(:content_columns)

Thank you! Committed your enhancement!

> I also found one bug: when you specify translations for virtual
> attributes, they get removed by the generator from the file, which
> shouldn't be happening.

Ah, yes. I agree it's a very big problem.
I'm gonna maka a fix somehow.

And, let me ask you one more thing.
Do you mind if I use your Translated scaffold templates to provide
i18n_scaffold generator?
Actually, it's already been implemented
http://github.com/amatsuda/i18n_generators/tree/master/generators/i18n_scaffold
but not yet included in the gem.

Akira

On 11月28日, 午後7:40, iain hecker <i...@iain.nl> wrote:
> Hi,
>
> Fantastic work Akira, I really love it!
>
> I have one question though, why do you exclude created_at and
> updated_at from the generated model translations? Why shouldn't they
> be translated?
>
> Furthermore I have one little alteration: on line 14 of
> i18n_models_command.rb[1], can you change
>
> next unless m.ancestors.include? ActiveRecord::Base
>
> into:
>
> next unless m.respond_to?(:content_columns)
>
> This makes it a lot easier to add translations which are not based on
> ActiveRecord. I can adjust my ActsAsTranslatableModel plugin[2] to
> work in concert with your generator.
>
> I also found one bug: when you specify translations for virtual
> attributes, they get removed by the generator from the file, which
> shouldn't be happening.
>
> Anyway, Keep up the good work!
>
> Iain Heckerhttp://iain.nl/
>
> [1]http://github.com/amatsuda/i18n_generators/tree/master/generators/i18...

Iain Hecker

unread,
Nov 28, 2008, 6:19:58 PM11/28/08
to rails...@googlegroups.com
Hi,

> I believe these columns are "system columns" just for framework-
> internal use, and should not be revealed to the end users,
> thus not needed to be translated as well.
> If you need a timestamped column in your application code, you might
> add another datetime column with values updated explicitly (not
> automatically by the framework).

Why should I need to make another attribute to store when the object
was created to show to my users? That totally doesn't make any sense!
I mean, I would store information double, which is against
normalization, and I would be writing code to implement it, which
could possibly contain bugs, takes time and is not necessary, since it
is already there! I make a lot of closed administrative applications,
which always have lists and such

> Do you mind if I use your Translated scaffold templates to provide
> i18n_scaffold generator?

Not at all!

2008/11/29 Akira Matsuda <pushi...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages