« Return to Thread: base_language text does not show if translation is missing
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.
>
« Return to Thread: base_language text does not show if translation is missing
| Free embeddable forum powered by Nabble | Forum Help |