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.