Gettext and Rails?


#1

Hello,

I’m trying to use ruby-gettext 1.1.1 (installed with gem) with rails and
here is all I get :

undefined method `init_gettext’ for ApplicationController:Class

Here is my source :

require ‘gettext/rails’

class ApplicationController < ActionController::Base
init_gettext “test”
end

As a Nuby, I don’t really know what to do.
Please, Help !

Thx,
Jonathan


#2

Hi,

On Sun, 15 Jan 2006 16:21:20 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

class ApplicationController < ActionController::Base
init_gettext “test”
end

As a Nuby, I don’t really know what to do.
Please, Help !

I suspect you have other versions of Ruby-GetText-Package
and it’s installed to “site_ruby/1.8” directory.

Did you install another version of Ruby-GetText-Package?

For example, check /usr/lib/ruby/site_ruby/1.8/gettext.
Or Find gettext.rb from Explorer if you use MS Windows.


#3

Masao M. wrote:

Hi,

On Sun, 15 Jan 2006 16:21:20 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

class ApplicationController < ActionController::Base
init_gettext “test”
end

As a Nuby, I don’t really know what to do.
Please, Help !

I suspect you have other versions of Ruby-GetText-Package
and it’s installed to “site_ruby/1.8” directory.

Did you install another version of Ruby-GetText-Package?

For example, check /usr/lib/ruby/site_ruby/1.8/gettext.
Or Find gettext.rb from Explorer if you use MS Windows.

I checked and here are the results (I’m using GNU/Linux Debian - Stable)
:

test:~# locate gettext.rb
/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/lib/gettext.rb
/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/lib/gettext/rgettext.rb
/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/test/test_sgettext.rb
/usr/local/lib/site_ruby/1.8/gettext.rb
/usr/local/lib/site_ruby/1.8/gettext/rgettext.rb
test:~# diff /usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/lib/gettext.rb
/usr/local/lib/site_ruby/1.8/gettext.rb
test:~#

So it seems I have 2 directories with gettext but the versions are the
same ; the ‘/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/’ was installed
with ‘gem install gettext’, and for the other one I really don’t know
but diff seems to tell us that it is the same file.

I tried ‘gem uninstall gettext’ and ‘gem install gettext’ back but the
result is the same.


#4

Same again :

test:~# diff
/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/lib/gettext/rails.rb
/usr/local/lib/site_ruby/1.8/gettext/rails.rb

Any ideas ?


#5

Hi,

On Sun, 15 Jan 2006 17:16:06 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

/usr/local/lib/site_ruby/1.8/gettext.rb
test:~#

So it seems I have 2 directories with gettext but the versions are the
same.

How did you check it?

I tried ‘gem uninstall gettext’ and ‘gem install gettext’ back but the
result is the same.

Did you try to remove the files below ?
/usr/local/lib/site_ruby/1.8/gettext.rb
/usr/local/lib/site_ruby/1.8/gettext/*

If not, try it, please.


#6

So it seems I have 2 directories with gettext but the versions are the
same.

How did you check it?

‘locate gettext | grep ruby’ to get paths containing gettext and ruby.

I tried ‘gem uninstall gettext’ and ‘gem install gettext’ back but the
result is the same.

Did you try to remove the files below ?
/usr/local/lib/site_ruby/1.8/gettext.rb
/usr/local/lib/site_ruby/1.8/gettext/*

If not, try it, please.

Done, but still doesn’t work.
Is there any way to get the path of a loaded module ? So I could check
which version it is for sure.

Anyway thank’s for your help and concern so far.


#7

Jonathan DERROUGH wrote:

So it seems I have 2 directories with gettext but the versions are the
same.

How did you check it?

‘locate gettext | grep ruby’ to get paths containing gettext and ruby.

I tried ‘gem uninstall gettext’ and ‘gem install gettext’ back but the
result is the same.

Did you try to remove the files below ?
/usr/local/lib/site_ruby/1.8/gettext.rb
/usr/local/lib/site_ruby/1.8/gettext/*

If not, try it, please.

Done, but still doesn’t work.
Is there any way to get the path of a loaded module ? So I could check
which version it is for sure.

Anyway thank’s for your help and concern so far.

Here is something else, I commented the ‘init_gettext’ line and obtained
this :


uninitialized constant Rails

/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in
const_missing' /usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/lib/gettext/rails.rb:21 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire__’
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:inrequire’
#{RAILS_ROOT}/app/controllers/application.rb:4

Do you think it is relevant ?


#8

Jonathan DERROUGH wrote:

So it seems I have 2 directories with gettext but the versions are the
same.

How did you check it?

‘locate gettext | grep ruby’ to get paths containing gettext and ruby.

I tried ‘gem uninstall gettext’ and ‘gem install gettext’ back but the
result is the same.

Did you try to remove the files below ?
/usr/local/lib/site_ruby/1.8/gettext.rb
/usr/local/lib/site_ruby/1.8/gettext/*

If not, try it, please.

Done, but still doesn’t work.
Is there any way to get the path of a loaded module ? So I could check
which version it is for sure.

Anyway thank’s for your help and concern so far.

Here is something else, I commented the ‘init_gettext’ line and obtained
this :

uninitialized constant Rails

Do you think it is relevant ?


#9

Hi,

On Sun, 15 Jan 2006 18:18:34 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

uninitialized constant Rails

Do you think it is relevant ?

Hmm.

what version of rails do you use ?
Ruby-GetText-Package requires rails-1.0.0 or later.

Show the result of script/about.

$ ruby script/about

And how about to run sample script?

$ cd /usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails
$ ruby script/server


#10

Hi,

On Sun, 15 Jan 2006 18:09:55 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

So it seems I have 2 directories with gettext but the versions are the
same.

How did you check it?

‘locate gettext | grep ruby’ to get paths containing gettext and ruby.

Isn’t locate database old?
#Did you call updatedb manually?

Anyway,
could you check “/usr/lib/ruby/site_ruby/1.8/gettext.rb” manually ?

And your “/usr/local/lib/site_ruby/1.8/” path seems strange.
Isn’t it “/usr/local/lib/ruby/site_ruby/1.8” ?

If not, try it, please.

Done, but still doesn’t work.

Did you re-install ruby-gettext-1.1.1 with gem ?

Is there any way to get the path of a loaded module ? So I could check
which version it is for sure.

$ ruby -v -e ‘p $:’


#11

Masao M. wrote:

Hi,

On Sun, 15 Jan 2006 18:18:34 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

uninitialized constant Rails

Do you think it is relevant ?

Hmm.

what version of rails do you use ?
Ruby-GetText-Package requires rails-1.0.0 or later.

Show the result of script/about.

$ ruby script/about

test:/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails# ruby
script/about
About your application’s environment
Ruby version 1.8.2 (i386-linux)
RubyGems version 0.8.11
Rails version 1.0.0
Active Record version 1.13.2
Action Pack version 1.11.2
Action Web Service version 1.0.0
Action Mailer version 1.1.5
Active Support version 1.2.5
Application root
/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails
Environment development
Database adapter mysql
GetText version 1.1.1

And how about to run sample script?

$ cd /usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails
$ ruby script/server


test:/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails# ruby
script/server
=> Booting WEBrick…
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-01-15 18:40:21] INFO WEBrick 1.3.1
[2006-01-15 18:40:21] INFO ruby 1.8.2 (2005-04-11) [i386-linux]
[2006-01-15 18:40:21] INFO WEBrick::HTTPServer#start: pid=6429
port=3000
192.168.0.1 - - [15/Jan/2006:18:40:37 CET] “GET / HTTP/1.1” 200 7599

  • -> /
    192.168.0.1 - - [15/Jan/2006:18:40:37 CET] “GET
    /javascripts/prototype.js HTTP/1.1” 200 46235
    http://192.168.0.3:3000/ -> /javascripts/prototype.js
    192.168.0.1 - - [15/Jan/2006:18:40:38 CET] “GET /javascripts/effects.js
    HTTP/1.1” 200 34755
    http://192.168.0.3:3000/ -> /javascripts/effects.js
    192.168.0.1 - - [15/Jan/2006:18:40:38 CET] “GET /images/rails.png
    HTTP/1.1” 200 1787
    http://192.168.0.3:3000/ -> /images/rails.png
    192.168.0.1 - - [15/Jan/2006:18:40:38 CET] “GET /favicon.ico HTTP/1.1”
    200 0
  • -> /favicon.ico

Accessing the server through Firefox gives :


Welcome aboard
Youâ??re riding the Rails!
About your applicationâ??s environment
Getting started


#12

Isn’t locate database old?
#Did you call updatedb manually?

Just did and checked again : all the same.

Anyway,
could you check “/usr/lib/ruby/site_ruby/1.8/gettext.rb” manually ?

I removed it but here is
‘/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/lib/gettext.rb’ :


=begin
gettext.rb - GetText module

Copyright © 2001-2005 Masao M.
Copyright © 2001-2003 Masahiro S.

  Masao M.       <removed_email_address@domain.invalid>
  Masahiro S.    <removed_email_address@domain.invalid>

You may redistribute it and/or modify it under the same
license terms as Ruby.

$Id: gettext.rb,v 1.5 2005/11/30 17:59:14 mutoh Exp $
=end

require ‘rbconfig’
require ‘gettext/version’
require ‘gettext/mo’
require ‘gettext/locale’
require ‘gettext/textdomain’
require ‘gettext/string’

module GetText
class NoboundTextDomainError < RuntimeError
end

@@__textdomain = Hash.new
@@__textdomain_key = Hash.new

@@output_charset = nil
@@locale = nil

def bindtextdomain(domainname, path = nil, locale = nil, charset =
nil)
if @@locale
locale = @@locale
Locale.set(Locale::CTYPE, locale)
else
locale ||= Locale.get
end
if @@output_charset
charset = @@output_charset
else
charset ||= ENV[“OUTPUT_CHARSET”] ? ENV[“OUTPUT_CHARSET”] :
Locale.codeset
@@output_charset = charset
end
src = callersrc
$stderr.print “bind the domain ‘#{domainname}’ to ‘#{src}’. charset
is #{charset}\n” if $DEBUG
textdomain = @@__textdomain[src]
unless textdomain
textdomain = @@__textdomain_key[domainname]
@@__textdomain[src] = textdomain
end

if ! textdomain or ! textdomain.same_property?(domainname, path, 

locale, charset)
textdomain = TextDomain.new(domainname, path, locale, charset)
@@__textdomain_key[domainname] = textdomain
@@__textdomain[src] = textdomain
end
@@__textdomain[src]
end

def textdomain(domainname)
src = callersrc
textdomain = @@__textdomain_key[domainname]
raise NoboundTextDomainError, “#{domainname} is not bound.” unless
textdomain
@@__textdomain[src] = textdomain
$stderr.print “Use the domain ‘#{domainname}’ to ‘#{src}’. charset
is #{textdomain.charset}\n” if $DEBUG
@@__textdomain[src]
end

def gettext(msgid)
textdomain = @@__textdomain[callersrc]
textdomain ? textdomain.gettext(msgid) : msgid
end

def ngettext(msgid, msgid_plural, n)
textdomain = @@__textdomain[callersrc]
textdomain ? textdomain.ngettext(msgid, msgid_plural, n) : (n == 1 ?
msgid : msgid_plural)
end

def N_(msgid)
msgid
end

def sgettext(msgid, div = ‘|’)
textdomain = @@__textdomain[callersrc]
if textdomain
msg = textdomain.gettext(msgid)
else
msg = msgid
end
if msg == msgid
if index = msg.rindex(div)
msg = msg[(index + 1)…-1]
end
end
msg
end

def callersrc
caller(2)[0].sub(/:\d+(?::in `\S+’)?\Z/, ‘’)
end

def locale=(locale)
@@locale = locale
textdomain = @@__textdomain[callersrc]
textdomain.set_locale(locale) if textdomain
locale
end

def output_charset=(charset)
@@output_charset = charset
end

def output_charset
@@output_charset
end

def locale
@@locale
end

def charset=(cs)
textdomain = @@__textdomain[callersrc]
textdomain.set_charset(cs) if textdomain
end

alias :setlocale :locale=
alias :set_locale :locale=
alias :set_output_charset :output_charset=
alias :_ :gettext
alias :n_ :ngettext
alias :s_ :sgettext

module_function :bindtextdomain, :textdomain,
:N_, :gettext, :, :ngettext, :n,
:sgettext, :s_, :callersrc,
:setlocale, :set_locale, :locale=, :locale, :charset=,
:set_output_charset, :output_charset=, :output_charset
end

And your “/usr/local/lib/site_ruby/1.8/” path seems strange.
Isn’t it “/usr/local/lib/ruby/site_ruby/1.8” ?

No, I made a copy/paste ; the other gem modules are there too :

test:~# ls /usr/local/lib/site_ruby/1.8
gemconfigure.rb i386-linux rubygems rubygems.rb ubygems.rb

Did you re-install ruby-gettext-1.1.1 with gem ?

Yes : ‘gem uninstall gettext’, then ‘gem install gettext’

Is there any way to get the path of a loaded module ? So I could check
which version it is for sure.

$ ruby -v -e ‘p $:’

I meant : a way to get the complete of a module which has been loaded
with require.


#13

I managed to make the sample work so I guess there’s something wrong
with my application.

Thank’s for your time and help. :slight_smile:


#14

Show the result of script/about.

$ ruby script/about

test:/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails# ruby
script/about
About your application’s environment
Ruby version 1.8.2 (i386-linux)
RubyGems version 0.8.11
Rails version 1.0.0
Active Record version 1.13.2
Action Pack version 1.11.2
Action Web Service version 1.0.0
Action Mailer version 1.1.5
Active Support version 1.2.5
Application root
/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails
Environment development
Database adapter mysql
GetText version 1.1.1

And how about to run sample script?

$ cd /usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails
$ ruby script/server


test:/usr/lib/ruby/gems/1.8/gems/gettext-1.1.1/samples/rails# ruby
script/server
=> Booting WEBrick…
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-01-15 18:40:21] INFO WEBrick 1.3.1
[2006-01-15 18:40:21] INFO ruby 1.8.2 (2005-04-11) [i386-linux]
[2006-01-15 18:40:21] INFO WEBrick::HTTPServer#start: pid=6429
port=3000
192.168.0.1 - - [15/Jan/2006:18:40:37 CET] “GET / HTTP/1.1” 200 7599

  • -> /
    192.168.0.1 - - [15/Jan/2006:18:40:37 CET] “GET
    /javascripts/prototype.js HTTP/1.1” 200 46235
    http://192.168.0.3:3000/ -> /javascripts/prototype.js
    192.168.0.1 - - [15/Jan/2006:18:40:38 CET] “GET /javascripts/effects.js
    HTTP/1.1” 200 34755
    http://192.168.0.3:3000/ -> /javascripts/effects.js
    192.168.0.1 - - [15/Jan/2006:18:40:38 CET] “GET /images/rails.png
    HTTP/1.1” 200 1787
    http://192.168.0.3:3000/ -> /images/rails.png
    192.168.0.1 - - [15/Jan/2006:18:40:38 CET] “GET /favicon.ico HTTP/1.1”
    200 0
  • -> /favicon.ico

Accessing the server through Firefox gives :


Welcome aboard
Youâ??re riding the Rails!
About your applicationâ??s environment
Getting started

I removed ‘public/index.html’ but I get errors from WEBrick :

ActionController::RoutingError (Recognition failed for “/”):
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:469:in
recognition_failed' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:459:inrecognize!’
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:inhandle_dispatch’
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/lib/ruby/1.8/webrick/server.rb:172:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:161:in start' /usr/lib/ruby/1.8/webrick/server.rb:161:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/lib/ruby/1.8/webrick/server.rb:92:ineach’
/usr/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/lib/ruby/1.8/webrick/server.rb:82:instart’
/usr/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:indispatch’
/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in
require__' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require' /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire__’
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:inrequire’
script/server:3

192.168.0.1 - - [15/Jan/2006:18:46:10 CET] “GET / HTTP/1.1” 404 589

  • -> /

#15

I found something interresting : require ‘gettext/rails’ returns false.
However the module appears in $".

Any ideas on how to debug this ? more debug messages of some kind which
would tell exactly why require returns false ?


#16

Hi,

On Sun, 15 Jan 2006 21:46:47 +0100
Jonathan DERROUGH removed_email_address@domain.invalid wrote:

I found something interresting : require ‘gettext/rails’ returns false.

It seems you(or some other libraries which are required from your
application)
requires “gettext/rails” anywhere before application.rb.