Ticket #197 (new defect)

Opened 4 months ago

Last modified 4 months ago

Incorrect type for Date/Time localization in Translation data

Reported by: ulisses.montenegro Assigned to:
Priority: minor Milestone:
Component: data tables Version:
Keywords: ViewTranslation date time localization Cc:

Description

After setting up Globalize as described in Sven Fuchs' excellent tutorial, I tried running some of the date localization samples, which did not work:

>> Locale.set 'pt-BR'
=> #<Globalize::Locale:0xb6f4e53c @currency_decimal_sep=",", @code="pt-BR",
@currency_format="R$%n", @decimal_sep=",", @language=Portuguese, @date_format=nil, 
@thousands_sep=".", @country=#<Globalize::Country id: 29, code: "BR", english_name: "Brazil", 
date_format: nil, currency_format: "R$%n", currency_code: "BRR", thousands_sep: ".", 
decimal_sep: ",", currency_decimal_sep: ",", number_grouping_scheme: "western">, 
@number_grouping_scheme=:western, @currency_code="BRR">
>> Time.now.loc('%B')
=> "August"

After checking my logs, I discovered that the following query was being run against the globalize_translations table:

  Globalize::ViewTranslation Load (0.001088)   SELECT * FROM "globalize_translations" WHERE 
(tr_key = 'August [month]' AND language_id = 5250 AND pluralization_index = 1 AND namespace IS 
NULL) AND ( ("globalize_translations"."type" = 'Globalize::ViewTranslation' ) ) LIMIT 1

I ran this against my database and indeed it did not return a match:

sqlite> SELECT * FROM "globalize_translations" WHERE (tr_key = 'August [month]' AND language_id 
= 5250 AND pluralization_index = 1 AND namespace IS NULL) AND ( ("globalize_translations"."type" 
= 'Globalize::ViewTranslation' ) ) LIMIT 1;
sqlite> 

It turns out all ViewTranslation records created by rake globalize:setup do not specify the full classname, Globalize::ViewTranslation. A simple update solved the issue:

sqlite> UPDATE globalize_translations SET type = 'Globalize::ViewTranslation' WHERE type = 'ViewTranslation';

After that, all date/time localization started returning the correct values:

>> Time.now.loc("%d %B %Y")
=> "11 Agosto 2008"

Since I just recently discovered Globalize and I am not really sure that the only place that needs to be patched is vendor/plugins/globalize/data/translation_data.csv, I am submitting this bug report in hope that someone more knowledgeable about its innards can produce a proper patch.

Change History

08/12/08 15:09:23 changed by ulisses.montenegro

Some important details I forgot:

  • I am running Rails 2.1.0
  • I am using this fork of the main Globalize project, but I confirmed that the contents of vendor/plugins/globalize/data/translation_data.csv is the same on both versions