Sha256: d83c38322157167c7f6081cc4ab5981f65df57eb367e7e8a5ee2c73f018fe5db

Contents?: true

Size: 1.34 KB

Versions: 15

Compression:

Stored size: 1.34 KB

Contents

class Locale
  attr_reader :language, :country, :code

  #
  def self.language
    Globalite.language
  end

  # Return the country
  def self.country
    Globalite.country
  end

  # Return the user's locale or the system's if the user doesn't have one set
  def self.code
    "#{Globalite.language}-#{Globalite.country}".to_sym
  end
  
  #
  def self.set_code(locale)
    if locale.to_s.split('-') && locale.to_s.length.between?(4,5) && Globalite.locales.include?(locale.to_sym) 
       Globalite.language = locale.to_s.split('-')[0].downcase.to_sym if locale.to_s.split('-')[0]
       Globalite.country = locale.to_s.split('-')[1].upcase.to_sym if locale.to_s.split('-')[1]
    end
  end
  
  def self.code=(locale)
    self.set_code(locale)
  end
  
  # Return the available locales
  def self.codes
    Globalite.locales
  end
  
  # Return the locale name in its own language for instance fr-FR => Français
  def self.name(locale)
    Globalite.locale_name(locale)
  end
  
  # Return the list of the UI locales with their name
  def self.ui_locales
    Globalite.ui_locales
  end
  
  # Return the list of the Rails locales with their name 
  def self.rails_locales
    Globalite.rails_locales
  end

  # Reset the Locale to the default settings
  def self.reset!
    Locale.set_code("#{Globalite.default_language}-#{Globalite.default_country}")
  end
  
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
edgerunner-globalite-0.5.1 lib/globalite/locale.rb
matta-globalite-0.5.0 lib/globalite/locale.rb
mattetti-globalite-0.5.1 lib/globalite/locale.rb
morhekil-globalite-0.5.1 lib/globalite/locale.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/globalite/lib/globalite/locale.rb
picolena-0.1.0 rails_plugins/globalite/lib/globalite/locale.rb
picolena-0.1.1 rails_plugins/globalite/lib/globalite/locale.rb
picolena-0.1.2 rails_plugins/globalite/lib/globalite/locale.rb
picolena-0.1.3 rails_plugins/globalite/lib/globalite/locale.rb
picolena-0.1.4 rails_plugins/globalite/lib/globalite/locale.rb
picolena-0.1.5 rails_plugins/globalite/lib/globalite/locale.rb
spree-0.4.1 vendor/plugins/globalite/lib/globalite/locale.rb
spree-0.4.0 vendor/plugins/globalite/lib/globalite/locale.rb
spree-0.5.0 vendor/plugins/globalite/lib/globalite/locale.rb
spree-0.5.1 vendor/plugins/globalite/lib/globalite/locale.rb