Module | GetText::Rails |
In: |
lib/gettext/rails.rb
|
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>.
Rails | = | ::Rails #:nodoc: |
bindtextdomain | -> | _bindtextdomain |
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.
# File lib/gettext/rails.rb, line 67 67: def available_locales 68: unless (GetText.cached? and @@available_locales) 69: @@available_locales = (Dir.glob(File.join(RAILS_ROOT, "locale/[a-z]*")).map{|path| File.basename(path)} << "en").uniq.sort.reverse 70: end 71: @@available_locales 72: end
Bind a textdomain(#{path}/#{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.
# File lib/gettext/rails.rb, line 58 58: def bindtextdomain(domainname, options = {}) 59: options[:path] ||= File.join(RAILS_ROOT, "locale") 60: _bindtextdomain(domainname, options) 61: end
Returns a normalized locale which is in available_locales.
# File lib/gettext/rails.rb, line 76 76: def normalized_locale(locale = nil) 77: locale ||= GetText.locale 78: (available_locales & 79: [locale.to_general, locale.to_s, locale.language, Locale.default.language, "en"].uniq)[0] 80: end