MailingList


Re: base_language text does not show if translation is missing

by Julien Ramel :: Rate this Message:

Reply to Author | View in Thread

Hi Tako,

if follow the instructions here, the "new feature" is actually a hack,  
that requires some modifications or installing a plugin.
http://saimonmoore.net/2006/12/1/alternative-implementation-of-globalize-model-translations

if it's exactly what you want, then have a look at my blog, http://www.yabo-concept.com/
it's veeeeeery empty for the moment, just 2 articles, and guess what,  
the latest one is just about that implementation,
I had a hard time, but really needed it. (at first I thought you just  
wanted to get started with globalize)

I have to update my blog with my latest work, because there are still  
some issues with it, I also modified the plugin because it conflicts
with will_paginate, just added

ActiveRecord::Base.send(:extend, LocalizeAlternative::LocalizeModels)

to the init.rb... I'm not expert enough to explain exactly why, but it  
works
(original plugin is here http://www.saimonmoore.net/assets/2006/12/11/localize_models.tar.gz)


a bit in a rush now... hope that helps, I had such a hard time to get  
globalize to work the way I want, I really wanna share this, because  
I'm finally able to use  standard globalize translation, model  
translation, fragment caching and ferret search together...

cheers
julien
Le 14 mars 08 à 14:14, tako a écrit :

>
> Hi Julien, thanks for your answer...
> But I really thought that this functionality was built in Globalize  
> 1.2 as
> announced on the globalize website
> -------------
> from  http://www.globalize-rails.org/globalize/
> http://www.globalize-rails.org/globalize/
>
> Besides being compatible with the latest shiny & jaw-dropping Ruby  
> on Rails
> 1.2 release this Globalize release adds two new major features:
>
> alternative way of storing ModelTranslations in the model table
> namespaced ViewTranslations
> ------------
>
> Are you sure it requires the plugin?
>
> Moreover, when I have a translation (name_fr) for my category, it  
> shows it
> perfectly on locale change. It is only when I have no translation  
> that I get
> the problem...
>
> I'll reverse to the 'classic' way of storing translations only if I  
> can't
> find a solution to this...
>
>
> Julien Ramel wrote:
>>
>> Hi Tako,
>>
>>
>> I think you got mixed up with tutorials about alternative ways to
>> store translations
>> http://saimonmoore.net/2006/12/1/alternative-implementation-of-globalize-model-translations
>>
>> it works great, but requires to install the plugin, and make  
>> globalize
>> work a bit differently, putting all the translations
>> in the same table, as you did in your example.
>>
>> it's mostly useful to save DB queries (see saimon's blog) but it's
>> still easier to use the standard globalize way, so just
>> remove the "name_fr", "descrption_fr"  from your model, keep your
>> views & controller in the standard rails way,
>> and you'll be able to translate & view the results simply by changing
>> the locale.
>> (do all this in the console first to check that it's all working)
>>
>> and don't forget to follow tips on Sven's blog
>> http://www.artweb-design.de/2006/11/10/get-on-rails-with-globalize-comprehensive-writeup
>> he saved my project when I needed to fix my routes and my caching.
>>
>> cheers
>>
>> julien
>>
>>
>>
>>
>>
>>
>>
>> Le 14 mars 08 à 10:16, tako a écrit :
>>
>>>
>>> Hi everyone!
>>> Sorry to bother you with a rails newbee question but I can't get
>>> this right
>>> after a few hours...
>>> If a translation is missing, my application does not show the
>>> base_language
>>> text:
>>>
>>> With http://svn.globalize-rails.org/svn/globalize/trunk (installed
>>> on March
>>> 13 2008)
>>>
>>> In ./config/environment.rb I have
>>>
>>> include Globalize
>>> Globalize::DbTranslate.keep_translations_in_model = true
>>> Globalize::Locale.set_base_language('en-US')
>>> LOCALES = {'en' => 'en-US','fr' => 'fr-FR'}.freeze
>>>
>>> In ./app/controllers/application.rb I have
>>>
>>> class ApplicationController < ActionController::Base
>>> before_filter :set_locale
>>> private
>>> def set_locale
>>>   default_locale = 'en-US'
>>>   request_language = request.env['HTTP_ACCEPT_LANGUAGE']
>>>   request_language = request_language.nil? ? nil :
>>> request_language[/[^,;]+/]
>>>   params_locale = params[:locale] if params[:locale] == 'en-US' or
>>> params[:locale] == 'fr-FR'
>>>
>>>   @locale = params[:locale] || session[:locale] || request_language
>>> ||
>>> default_locale
>>>   session[:locale] = @locale
>>>   begin
>>>     Locale.set @locale
>>>   rescue
>>>     Locale.set default_locale
>>>   end
>>> end
>>> end
>>>
>>> In ./app/models/category.rb I have
>>>
>>> class Category < ActiveRecord::Base
>>> translates :name, :description
>>> end
>>>
>>> I created my categories table with
>>>
>>> class CreateCategories < ActiveRecord::Migration
>>> def self.up
>>>   create_table :categories do |t|
>>>     t.string :name
>>>     t.string :name_fr
>>>     t.text :description
>>>     t.text :description_fr
>>>
>>>     t.timestamps
>>>   end
>>> end
>>>
>>> def self.down
>>>   drop_table :categories
>>> end
>>> end
>>>
>>> For example, if a name_fr is missing, Globalize does not show the
>>> default
>>> name. At best I have a blank and in the worth case I have an error,
>>> if I try
>>> to concatenate the category.name to another string...
>>> Someone can help?
>>> In advance, thank you very much.
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/base_language-text-does-not-show-if-translation-is-missing-tp16047003s17045p16047003.html
>>> Sent from the Globalize-rails.org mailing list archive at  
>>> Nabble.com.
>>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/base_language-text-does-not-show-if-translation-is-missing-tp16047003s17045p16048010.html
> Sent from the Globalize-rails.org mailing list archive at Nabble.com.
>

 « Return to Thread: base_language text does not show if translation is missing