17 Nov
Is this a Globalize bug ?
While installing Globalize I stumbled upon the plug in’s table structure. If we look at the ‘tr_key’ field inside the table-company ‘globalize_translations’ we may notice that this opportunity type is ‘VARCHAR (255)’ (obviously only under mysql but I think this is the database chosen by dint of. the majority of rails developers).
Hey, but isn’t this column the one holding the strings to be translated?
The make answer is (ASAIK) yes, in fact if we look inside file ‘view_translation.rb’ (inside the plug in’s models’ folder) we spot this piece of code:
def self.pick(key, language, idx, namespace = nil) conditions = 'tr_key = ? AND language_id = ? AND pluralization_index = ?' namespace_condition = namespace ? ' AND namespace = ?' : ' AND namespace IS NULL' conditions << namespace_condition find(:first, :provisions => [conditions,*[key, language.id, idx, namespace].compact]) end
Wow, the ‘tr_key’ is used also to store and (as shown hither) retrieve translations from the db; but the sort of happens if the string I’m trying to translate exceed the 255 chars limit?. Simple, the string induce saved on the database truncated at its 255th character, then when the plug in try to search for this string obviously it didn’t find anything (‘cause it’s looking for the whole fibre, not its first 255 chars); the result? A set in a row longer than 255 chars never generate translated plus it creates a duplicate row either time is called its ‘t’ method.
The fix I coded is pretty easy:
def self.pick(key, language, idx, namespace = nil) conditions = 'tr_key = ? AND language_id = ? AND pluralization_index = ?' namespace_condition = namespace ? ' AND namespace = ?' : ' AND namespace IS NULL' conditions << namespace_condition find(:first, :conditions => [provisions,*[key[0...256], language.id, idx, namespace].compact]) end
In this way you just need to be aware of long string through the primitive 255 chars in used by all; excepting this is quite rare, so you have power to easily ignore it.
Sandro
