Module: GetText::Rails
- Includes:
- GetText
- Included in:
- ActionController::Base, ActionMailer::Base, ActionMailer::Base
- Defined in:
- lib/gettext/rails.rb
Overview
GetText::Rails supports Ruby on Rails. You add only 2 lines in your controller, all of the controller/view/models are targeted the textdomain.
See <Ruby-GetText-Package HOWTO for Ruby on Rails (www.yotabanana.com/hiki/ruby-gettext-howto-rails.html>.
Constant Summary collapse
- Rails =
:nodoc:
::Rails
- @@available_locales =
nil
Constants included from GetText
CACHE_BOUND_TARGET_MAX_SIZE, VERSION
Class Method Summary collapse
-
.available_locales ⇒ Object
Returns locales which supported by the application.
-
.bindtextdomain(domainname, options = {}) ⇒ Object
call-seq: bindtextdomain(domainname, options = {}).
-
.included(mod) ⇒ Object
:nodoc:.
-
.normalized_locale(locale = nil) ⇒ Object
Returns a normalized locale which is in available_locales.
Instance Method Summary collapse
-
#_bindtextdomain ⇒ Object
:nodoc:.
Methods included from GetText
N_, #Nn_, _, #add_default_locale_path, #bindtextdomain_to, bound_target, bound_targets, cached=, cached?, cgi, cgi=, clear_cache, create_mofiles, current_textdomain_info, each_textdomain, find_targets, gettext, locale, locale=, msgmerge, msgmerge_all, n_, ngettext, #npgettext, ns_, nsgettext, output_charset, output_charset=, p_, pgettext, remove_all_textdomains, rgettext, rmsgfmt, rmsgmerge, s_, set_cgi, set_locale, set_locale_all, set_output_charset, setlocale, sgettext, textdomain, #textdomain_to, update_pofiles
Class Method Details
.available_locales ⇒ Object
Returns locales which supported by the application. This function returns an reversed array of the locale strings under RAILS_ROOT/locale/*. It is used for restriction such as caching files.
67 68 69 70 71 72 |
# File 'lib/gettext/rails.rb', line 67 def available_locales unless (GetText.cached? and @@available_locales) @@available_locales = (Dir.glob(File.join(RAILS_ROOT, "locale/[a-z]*")).map{|path| File.basename(path)} << "en").uniq.sort.reverse end @@available_locales end |
.bindtextdomain(domainname, options = {}) ⇒ Object
call-seq: bindtextdomain(domainname, options = {})
Bind a textdomain(#path/#GetText.locale/LC_MESSAGES/#domainname.mo) to your program. Notes the textdomain scope becomes all of the controllers/views/models in your app. This is different from normal GetText.bindtextomain.
Usually, you don’t call this directly in your rails application. Call init_gettext in ActionController::Base instead.
On the other hand, you need to call this in helpers/plugins.
-
domainname: the textdomain name.
-
options: options as a Hash.
-
:locale - the locale value such as “ja-JP”. When the value is nil, locale is searched the order by this value > “lang” value of QUERY_STRING > params > “lang” value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
-
:path - the path to the mo-files. Default is “RAIL_ROOT/locale”.
-
:charset - the charset. Generally UTF-8 is recommanded. And the charset is set order by “the argument of bindtextdomain” > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
-
58 59 60 61 |
# File 'lib/gettext/rails.rb', line 58 def bindtextdomain(domainname, = {}) [:path] ||= File.join(RAILS_ROOT, "locale") _bindtextdomain(domainname, ) end |
.included(mod) ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/gettext/rails.rb', line 29 def self.included(mod) #:nodoc: mod.extend self end |
.normalized_locale(locale = nil) ⇒ Object
Returns a normalized locale which is in available_locales.
-
locale: a Locale::Object or nil.
76 77 78 79 80 |
# File 'lib/gettext/rails.rb', line 76 def normalized_locale(locale = nil) locale ||= GetText.locale (available_locales & [locale.to_general, locale.to_s, locale.language, Locale.default.language, "en"].uniq)[0] end |
Instance Method Details
#_bindtextdomain ⇒ Object
:nodoc:
27 |
# File 'lib/gettext/rails.rb', line 27 alias :_bindtextdomain :bindtextdomain |