[Nitro] "babel": new translation system - suggestions&help wanted
Stephan Walter
news at stephan.walter.name
Sat Apr 1 06:09:38 EST 2006
Hi
I started writing a new system for translating both models and views,
similar to "Globalize" from RoR. Currently only model translations are
supported, and it's not optimised at all. Also you have to enter the
languages manually :-/
svn co http://84.16.238.99/svn/babel/
In your model you write:
require 'babel/babel.rb'
class Whisper
property :text, String
translate :text
end
in the controller you set the base language:
Babel::Locale.set_base_language("en")
and in your template:
<?r Babel::Locale.set("de") ?>
#{@whisper.text}
which will automatically get the german translation (if there is no
translation, you'll get it in the base language). The same goes for
assigning values:
Babel::Locale.set("fr")
@whisper.text = "Bonjour"
I plan to write a translator for views (perhaps this could be in the
transformer pipeline?) Any suggestions or corrections are welcome!
Also, I ran into a few problems:
1. I have two classes for storing the translations, which inherit from the
same class:
class Translation
class ModelTranslation < Translation
class ViewTranslation < Translation
How do I prevent Og from making a db table for Translation?
2. as I am automagically translating the fields into the selected
language, this interferes with the admin interface (i.e. the admin
interface doesn't show the actual contents of the database, but the
translations in the base language). Is there a simple way to distinguish
if the admin interface or the normal web app is accessing the data?
-Stephan
More information about the Nitro-general
mailing list