# Trouble with Rails/Ri18n

**URL:** <https://www.ruby-forum.com/t/trouble-with-rails-ri18n/82327>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/trouble-with-rails-ri18n/82327 "2007-01-19T16:13:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![markus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@markus](https://www.ruby-forum.com/u/markus)\
**Post date:** [January 19, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/trouble-with-rails-ri18n/82327/1 "2007-01-19T16:13:21Z")

</div>

Hi,

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

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](mailto: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](mailto:EMAIL@ADDRESS)\n”  
“Language-Team: LANGUAGE [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![markus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@markus](https://www.ruby-forum.com/u/markus)\
**Post date:** [March 10, 2007, 3:18am UTC](https://www.ruby-forum.com/t/trouble-with-rails-ri18n/82327/2 "2007-03-10T03:18:45Z")

</div>

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
