Forum: Ruby on Rails Gettext and Rails ?

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.
Jonathan DERROUGH (Guest)
on 2006-01-15 17:21
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
Masao M. (Guest)
on 2006-01-15 17:34
(Received via mailing list)
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.
Jonathan D. (Guest)
on 2006-01-15 18:16
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.
Jonathan D. (Guest)
on 2006-01-15 18:32
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 ?
Masao M. (Guest)
on 2006-01-15 19:01
(Received via mailing list)
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.
Jonathan D. (Guest)
on 2006-01-15 19:09
>> 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.
Jonathan D. (Guest)
on 2006-01-15 19:17
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 ?
Jonathan D. (Guest)
on 2006-01-15 19:18
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:in
`require__'
/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:in
`require'
#{RAILS_ROOT}/app/controllers/application.rb:4
--------------------------------------

Do you think it is relevant ?
Masao M. (Guest)
on 2006-01-15 19:19
(Received via mailing list)
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 $:'
Masao M. (Guest)
on 2006-01-15 19:33
(Received via mailing list)
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
Jonathan D. (Guest)
on 2006-01-15 19:37
> 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 (C) 2001-2005  Masao M.
  Copyright (C) 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.
Jonathan D. (Guest)
on 2006-01-15 19:44
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
...
-------------------------------------
Jonathan D. (Guest)
on 2006-01-15 19:49
>> 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:in
`recognize!'
    /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:in
`handle_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:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:172:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:161:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:161:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /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:in
`dispatch'
    /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:in
`require'
    /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:in
`require__'
    /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:in
`require'
    script/server:3


192.168.0.1 - - [15/Jan/2006:18:46:10 CET] "GET / HTTP/1.1" 404 589
- -> /
Jonathan D. (Guest)
on 2006-01-15 20:09
I managed to make the sample work so I guess there's something wrong
with my application.

Thank's for your time and help. :)
Jonathan D. (Guest)
on 2006-01-15 22:46
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 ?
Masao M. (Guest)
on 2006-01-16 15:15
(Received via mailing list)
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.
This topic is locked and can not be replied to.