Forum: Ruby on Rails Trouble with Rails/Ri18n

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
markus (Guest)
on 2007-01-19 17:13
(Received via mailing list)
Hi,

I am new to Ruby/Rails but totally fall in love with :D

Nonetheless, today I am totally stuck with Ri18n. I basically followed
the 10 Steps to Make Your Rails Apps Multilingual. No errors are
thrown,
the english version works as before with the freshly added <%= _('') %>

Still, no translations are performed. Setting I18nService.instance.lang
= 'de' manually, I expected a translation to germany for all pages.


Rakefile works perfectly with "rake gettext":
.....
# Ri18n
task :gettext do
  require 'i18nservice'
  require 'gettext'
  I18nService.instance.po_dir = 'locale'
  Rake::GettextTask.new do |t|
    t.new_langs = ['de']
    t.source_files =
      ['{lib,app,components}/**/*.r{b,html,xml}']
    t.verbose = true
  end
end


environment.rb states:
# Include your application configuration below

# Require Rails libraries (Ri18n)
require 'rubygems'
require 'gettext'
require 'i18nservice'

$KCODE = 'u'                              # unicode
require 'jcode'                           # correct string methods for
utf8
I18nService.instance.po_dir = "locale"    # original:
"#{RAILS_ROOT}/locale"
I18nService.instance.lang = 'de'

ADDITIONAL_LOAD_PATHS.concat %w(
     # ... other entries
     vendor
     vendor/ri18n/lib
     # ... other entries
   ).map { |dir| "#{RAILS_ROOT}/#{dir}" }.select { |dir|
File.directory?(dir) }


/locale/de.po states:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# This file is distributed under the same license as the PACKAGE
package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"POT-Creation-Date: 2002-12-10 22:11+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <removed_email_address@domain.invalid>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ASCII\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n == 0;\n"

msgid "Add ContactList"
msgstr "Kontaktliste
hinzuf├╝gen"
msgid "Listing all users"
msgstr "Alle Benutzer anzeigen"


It seems, that it just does not find the translations and therefore
displays the english version - but why?
Could someone kindly point me in the right direction?

Kind regards
-Markus


PS:
I also tried to set language depending on browser, but this did not
work
with a browser requesting 'de', worked righted with a browser
requesting
 en  :)
Error: can't convert nil into String

in application.rb

class ApplicationController < ActionController::Base
  before_filter :localize
  before_filter :authenticate, :except => [:login, :sign_on]


  private
    def localize
      lang = if @request.env['HTTP_ACCEPT_LANGUAGE'].nil?
        'en'
      else
        lang = @request.env['HTTP_ACCEPT_LANGUAGE'].split('-')[0]
      end
      I18nService.instance.lang = lang
    end
Oscar O. (Guest)
on 2007-03-10 04:18
(Received via mailing list)
Hi,

I don't know if you solved your problem but I had recently the same
error.

The application I was working on previously use the Globalize plugin
so there were still some remnants of 'globalized' methods like
XXXX.translate.

Clean my code from all reference to Globalize did solved the problem.

Hope this helps.

Oscar
This topic is locked and can not be replied to.