#51 ✓invalid
Glenn Nilsson

Language isn't set.

Reported by Glenn Nilsson | July 4th, 2007 @ 12:25 PM

Hi, I'm having problem with setting the language. And I didn't know where else to ask the question, except for errtheblog.

In Rails 1.2.3, I have a module that's required before the Rails::Initializer.run in environment.rb, then a method in that module is run after the initializer, where you normally put the stuff. Reason: http://blog.innerewut.de/article....

That module does this:

      RAILS_DEFAULT_LOGGER.info(@@configuration[:language].to_sym) if RAILS_DEFAULT_LOGGER
      simple_localization :language => @@configuration[:language].to_sym,
                          :lang_file_dir => File.expand_path("#{RAILS_ROOT}/languages"),
                          :only => %w(
                                        localized_models_by_lang_file
                                        localized_error_messeges
                                        localized_active_record_helpers
                                        localized_date_and_time
                                        localized_array
                                        localized_date_helpers
                                        localized_number_helpers
                                        class_based_field_error_proc
                                      )
      RAILS_DEFAULT_LOGGER.info Gibberish.current_language

The result:

de
Simple Localization plugin configuration:
  You don't want the feature localized_models to be loaded.
  However to work with rails observers these features are loaded at the end of the plugins init.rb.
  To suppress a preloaded feature please look into the plugins readme file (chapter "Preloaded features").
Initialized Simple Localization plugin:
  language: de, lang_file_dir: c:/rails/my_app/trunk/languages
  features: localized_models
en

And as you can see the language isn't loaded. It's still english. And in the console:

$ ruby script/console
Loading development environment.
>> Gibberish.current_language
=> :en
>> Gibberish.current_language = :de
=> :de
>> Gibberish.current_language
=> :en

What is it that I'm doing wrong? Or is this i bug somehow?

/Glenn

Comments and changes to this ticket

  • Glenn Nilsson
  • Glenn Nilsson

    Glenn Nilsson July 4th, 2007 @ 12:25 PM

    Also.

    The log says:

    features: localized_models
    

    But I specified several others, and that didn't include localized_models.

    It's clearly something I'm doing wrong, right? =)

  • Chris Wanstrath

    Chris Wanstrath July 4th, 2007 @ 12:25 PM

    • State changed from “new” to “open”

    This is my fault and also Ruby's fault.

    First, an example:

    $ ./script/console 
    Loading development environment.
    >> Gibberish.current_language
    => :en
    >> Gibberish.current_language = :de
    => :de
    >> Gibberish.current_language
    => :en
    >> Gibberish.languages
    => [:es]
    >> Gibberish.current_language = :es
    => :es
    >> Gibberish.current_language
    => :es
    

    As you can see, it only 'sticks' when the current_language is recognized.

    Here is the explanation: http://pastie.caboo.se/74481

    Now, are you trying to set a language which does not have a LANG.yml file? If so, we can fix that. It just depends on what you're trying to do.

  • Chris Wanstrath

    Chris Wanstrath July 4th, 2007 @ 12:25 PM

    For posterity's sake, here is the implementation of @@@current_language=@@@ which shows the intended behavior:

        def current_language=(language)
          load_languages! if defined?(RAILS_ENV) && RAILS_ENV == 'development'
    
          language = language.to_sym if language.respond_to? :to_sym
          @@current_language = @@languages[language] ? language : nil
        end
    
  • Glenn Nilsson

    Glenn Nilsson July 4th, 2007 @ 12:25 PM

    Ok, I get an empty array back when trying:

    Gibberish.languages
    

    And in RAILS_ROOT/languages there's 2 language-files. de.yml and en.yml, and en.yml is copied from the langs-dir within the plugin.

    So the empty array surely explains why I can't set the language.

    :lang_file_dir => File.expand_path("#{RAILS_ROOT}/languages")
    

    and the fact that there are two files in there should be enough right?

  • Chris Wanstrath

    Chris Wanstrath July 4th, 2007 @ 12:25 PM

    • State changed from “open” to “invalid”

    I don't think there is any :lang_file_dir directive. Instead, Gibberish always looks in RAILS_ROOT/lang/*.yml for your language files. Feel free to submit a patch if you want this behavior changed, though.

    http://require.errtheblog.com/pl...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket

Tags

Pages