Sha256: fa86886f49168560704315630146a12d7ed3dde753c8f0a9c9b9ed410f0fb461

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
require 'pathname'

module FatFreeCRM
  module I18n
    #----------------------------------------------------------------------------
    def t(*args)
      if args.size == 1
        super(args.first, default: args.first.to_s)
      elsif args.second.is_a?(Hash)
        super(*args)
      elsif args.second.is_a?(Integer)
        super(args.first, count: args.second)
      else
        super(args.first, value: args.second)
      end
    end

    # Scan config/locales directory for Fat Free CRM localization files
    # (i.e. *_fat_free_crm.yml) and return locale part of the file name.
    # We can't use ::I18n.available_locales because rails provides it's own
    # translations too and we only want the locales that Fat Free CRM supports.
    #----------------------------------------------------------------------------
    def locales
      @@locales ||= ::I18n.load_path.grep(/_fat_free_crm\.yml$/).map { |path| Pathname.new(path).basename.to_s.match(/(.*)_fat_free_crm\.yml/)[1] }.uniq
    end

    # Return a hash where the key is locale name, and the value is language name
    # as defined in the locale_fat_free_crm.yml file.
    #----------------------------------------------------------------------------
    def languages
      @@languages ||= Hash[locales.map { |locale| [locale, t(:language, locale: locale)] }]
    end
  end
end

ActionView::Base.send(:include, FatFreeCRM::I18n)
ActionController::Base.send(:include, FatFreeCRM::I18n)

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fat_free_crm-0.15.2 lib/fat_free_crm/i18n.rb
fat_free_crm-0.16.4 lib/fat_free_crm/i18n.rb
fat_free_crm-0.15.1 lib/fat_free_crm/i18n.rb
fat_free_crm-0.16.3 lib/fat_free_crm/i18n.rb
fat_free_crm-0.16.2 lib/fat_free_crm/i18n.rb
fat_free_crm-0.16.1 lib/fat_free_crm/i18n.rb
fat_free_crm-0.16.0 lib/fat_free_crm/i18n.rb
fat_free_crm-0.15.0 lib/fat_free_crm/i18n.rb
fat_free_crm-0.15.0.beta.2 lib/fat_free_crm/i18n.rb