Forum: Ruby on Rails How to set the default language in GetText?

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.
2e5a77bf26f7cab677f33537c8495fbf?d=identicon&s=25 charlie (Guest)
on 2006-05-08 08:46
How to set the default language in GetText?
The default language of GetText is en,and I want to change it to another
language,and also keep the ability to change to any other languages by
just click the according href.
Currently I use:
class ApplicationController < ActionController::Base
before_filter :set_charset
  def set_charset
    @headers["Content-Type"] = "text/html; charset=utf-8"
    cookies["lang"] = 'zh_CN'
  end
end
But the language will not switch to my want until the next refresh.Could
I set the default language from en to others in some way?

Thanks
Charlie
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2006-05-08 15:26
(Received via mailing list)
Hi,

On Mon, 8 May 2006 08:46:05 +0200
charlie <blogyingfeng@gmail.com> wrote:

> How to set the default language in GetText?
> The default language of GetText is en,and I want to change it to another
> language,and also keep the ability to change to any other languages by
> just click the according href.

Here is a sample of application.rb:

require 'gettext/rails'
class ApplicationController < ActionController::Base
  prepend_before_filter :default_locale
  def default_locale
    if (cookies["lang"].nil? or cookies["lang"].empty?)
      GetText.locale = "zh_CN"
    else
      GetText.locale = cookies["lang"]
    end
  end
  init_gettext "yourapp"
end


> Currently I use:
> class ApplicationController < ActionController::Base
> before_filter :set_charset
>   def set_charset
>     @headers["Content-Type"] = "text/html; charset=utf-8"
>     cookies["lang"] = 'zh_CN'
>   end
> end
> But the language will not switch to my want until the next refresh.Could
> I set the default language from en to others in some way?

Because you call "set_charset" method after calling init_gettext.

BTW, you shouldn't set Content-Type by yourself with
Ruby-GetText-Package.
It may cause other problem.

HTH,
2e5a77bf26f7cab677f33537c8495fbf?d=identicon&s=25 charlie (Guest)
on 2006-05-09 03:38
Very grateful!

Masao Mutoh wrote:
> Hi,
> Here is a sample of application.rb:

> BTW, you shouldn't set Content-Type by yourself with
> Ruby-GetText-Package.
> It may cause other problem.
>
> HTH,
This topic is locked and can not be replied to.