Obama '08
New-formula-starburst

Globalize plugin for Rails 2.1

11

Tonight at the Pivotal office I showed a few people the updates and modifications I’ve made to the globalize plugin for Rails.

My main motivation was fixing Globalize to work with Rails 2.1. They changed the way rails views are selected and rendered, and the date_helper api, both which broke the plugin. I forked globalize on github and my fork now works with Rails 2.1.

UPDATED June 14: Thanks to tips from jodosha and David Ramalho, I’ve made a few updates to the branch that fix a few things.

Get the plugin for Rails 2.1.0
script/plugin install git://github.com/heythisisnate/globalize.git
Globalize offers a variety of ways to translate and internationalize your Rails application. I’m using it primarily on my biodiesel stations locator application to translate arbitrary strings:
>> "Biodiesel Stations".t
=> "Biodiesel Stations"

>> Locale.set 'zh-tw'
>> "Biodiesel Stations".t
=> "生質柴油"

In addition to string translations, Globalize does a lot more, including date & time localization, currency, and number formatting differences. It handles pluralization supremely. The original team did a great job, and I’m happy to contribute my changes for Rails 2.1.

I’ve hacked on a few additional features that I previewed tonight … they’re not quite ready for prime time yet. I’ll definitely publish them here when they are.

Comments

  • Avatar David Ramalho said 2 days later:

    Hey, I’m using Rails 2.1 and have been having all sorts of problems with Globalize . I’ve switched to you branch and at least the date_select thing is solved (I had solved it myself earlier) but there’s still a problem that globalize had with the active_record_helper class. I’ve found the solution here (http://codesnippets.joyent.com/posts/show/896) and it solves it :) maybe you would want to include it… or not ;)

    either way, thanks and I just wanted to let you know

  • Avatar Simon said 8 days later:

    Hi there, thanks for your work on this and the fork on GH. 2.1 is a bit of a minefield (or maybe Globalize is starting to show its age?).

    I was wondering if you had had any luck with the “is not missing constant” exceptions thrown by the db_localizes_translates_test.rb?

  • Avatar Yuri said 28 days later:

    Hi, thanks for a great work!

    Globalize works for me with Rails 2.1 now. To make finders work with MySQL I changed the regexp at line 850 of db.translate.rb to

    where_clause.gsub!(/((((`?#{table_name}`?\.)|\W)`?#{facet}`?)|^`?#{facet}`?)\W/, " COALESCE(#{facet_table_alias}.text, #{table_name}.#{facet}) ")
    This was inspired by the solution at Nabble (sorry, textile breaks the full dashed URL to the entry). I just made it aware of backticks in table name.

  • Avatar Heinz said about 1 month later:

    Having trouble installing your plugin.

    F:\NetBeansProjects\myproject>ruby script/plugin install git://github.com/heythisisnate/globalize.git removing: F:/NetBeansProjects/myproject/vendor/plugins/globalize/.git

    Anyone knows why this is not working?

  • Avatar Heinz said about 1 month later:

    When I tried to install your globalize version I always get this: F:\NetBeansProjects\myproject>ruby script/plugin install git://github.com/heythisisnate/globalize.git removing: F:/NetBeansProjects/myproject/vendor/plugins/globalize/.git

  • Avatar Frank said about 1 month later:

    After installing your plugin the functional tests doesn’t work anymore…

    assert_template ‘edit’ ->

    expecting <”edit”> but rendering with <”edit.html.erb”>

    The integration tests doesn’t work too

    assert_template ‘people/show’

    expecting <”people/show”> but rendering with <”/Users/user/Documents/workspace/project/app/views/people/show.html.erb”>

    Any idea?

  • Avatar Jan said about 1 month later:

    @Heinz: make sure you have git installed on your system.

  • Avatar aimee.mychores.co.uk said about 1 month later:

    You should officially take over the Globalize project. They haven’t updated in about a milennium!

    Lovely to see you are using Git. I think i could try adding it as a git submodule, right?

  • Avatar aimee.mychores.co.uk said about 1 month later:

    I love you SO MUCH!!! You made my application work again!

    For anyone who wants to use this as a submodule, it works perfectly like this:

    git submodule add git://github.com/heythisisnate/globalize.git vendor/plugins/globalize

    The only problem is i now have a problem with TimeZone.unadjust … i seem to remember i had to tweak that for Globalize when i first got it.

    Probably about time i learned the new 2.1 way of doing TimeZones!

  • Avatar aimee.mychores.co.uk said about 1 month later:

    Ah … when i used Globalize before i wanted to keep track of who had contributed translations. So i added a

    belongs_to :person

    in the translation.rb model. What’s the best way for me to do this now that i’m using your shiny new version? I guess i need to extend it somehow … but i have no idea how or where i should do that.

  • Avatar Marko said 2 months later:

    We had some trouble with Globalize and rails 2.1 because Rails now stores full class name (including module namespace) in STI type column.

    Solution is to update type column ‘ViewTranslation’ to ‘Globalize::ViewTranslation’.

Trackbacks

Use the following link to trackback from your own site:
/articles/trackback/19491

(leave url/email »)

   Comment Markup Help Preview comment