# Globalize2 enhancements (dynamic writers, blcks, validtions)

**URL:** <https://www.ruby-forum.com/t/globalize2-enhancements-dynamic-writers-blcks-validtions/188368>\
**Category:** Rails I18n\
**Created:** [May 10, 2010, 11:47pm UTC](https://www.ruby-forum.com/t/globalize2-enhancements-dynamic-writers-blcks-validtions/188368 "2010-05-10T23:47:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 10, 2010, 11:47pm UTC](https://www.ruby-forum.com/t/globalize2-enhancements-dynamic-writers-blcks-validtions/188368/1 "2010-05-10T23:47:39Z")

</div>

Hey everyone,

I am replacing some old Rails model localization with Globalize2. I am  
really impressed with the design of the Globalize2 plugin, but we have a  
pretty involved i18n setup on my site, so I’m finding a lot of areas to  
improve. So far I have a number of significant changes in my github  
fork:

[http://github.com/dasil003/globalize2](http://github.com/dasil003/globalize2)

- translates accepts a block to customize the dynamicly generated  
Translation class (thanks juni0r)
- some options to allow multiple models to use the same translation  
table (:foreign\_key and :not\_dependent)
- add a unique key to enforce translation uniqueness and speed up  
queries collecting all translations for a given language
- dynamic locale-specific accessors. this allows bypassing fallbacks,  
is easier to code forms against then #set\_translations, and is more  
robust then accepts\_nested\_attributes solutions which are subject to  
race conditions and dups due to the fact that there is no lookup by  
unique key other than an actual translation primary\_key.

Now I’m onto some more involved questions such as how to handle  
validations on the translation model and pass it back to the base model  
without the current exceptions we see when translation saves fail, and  
also the issue of deleting translations (eg. auto-clearing translations  
when there is no data in them).

As I mentioned my app is quite complex in its localization architecture.  
I am writing my enhancements to be general purpose and well-tested, but  
could use some input from others using globalize2 to increase the chance  
that the stuff I’m working on can make it back into the mainline and be  
useful to others.

One example of a big issue I’d like to collaborate on is how to test  
I18n.fallbacks in Globalize2 (which currently have tests that don’t run,  
and are broken when I explicitly enable fallbacks). Another thing is a  
test harness for I18n.available\_locales, or supporting per-Globalize  
available\_locales setting (rather than implicitly defining from the DB).

Anyone down to work on this?

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [June 1, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/globalize2-enhancements-dynamic-writers-blcks-validtions/188368/2 "2010-06-01T18:35:00Z")

</div>

Hey Gabe, thanks for sharing!! I was just adding the foreign\_key when i  
found your post.

In my case it was needed, because my tables are in spanish and the  
inflections are a mess.

Gabe Da silveira wrote:

> Hey everyone,
> 
> I am replacing some old Rails model localization with Globalize2. I am  
> really impressed with the design of the Globalize2 plugin, but we have a  
> pretty involved i18n setup on my site, so I’m finding a lot of areas to  
> improve. So far I have a number of significant changes in my github  
> fork:

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [June 1, 2010, 6:51pm UTC](https://www.ruby-forum.com/t/globalize2-enhancements-dynamic-writers-blcks-validtions/188368/3 "2010-06-01T18:51:59Z")

</div>

Thanks for the reply Federico. Development has been quiet on my fork  
for the moment, but I have a lot more stuff going on in my app. So far  
I haven’t had any outside interest, but my use case is quite  
sophisticated and exposes a lot of vectors for improvement in  
globalize2. I’m hoping to get more feedback so that my changes can make  
it back to the core distribution.
