class Llaxta
Constants
- SUPPORTED_LOCALES
- VERSION
Attributes
locale[R]
Public Class Methods
alpha2(country_name, locale)
click to toggle source
@param [String] country_name @param [String] locale @return [String]
# File lib/llaxta.rb, line 22 def alpha2(country_name, locale) dictionary(locale).key(country_name) end
new(locale)
click to toggle source
@param [String] locale @return [void]
# File lib/llaxta.rb, line 53 def initialize(locale) raise Exceptions::LocaleMissing unless locale @locale = SUPPORTED_LOCALES[locale] end
t(alpha2, locale)
click to toggle source
@param [String] alpha2 @param [String] locale @return [String]
# File lib/llaxta.rb, line 13 def t(alpha2, locale) raise Exceptions::AlphaMissing unless alpha2 dictionary(locale)[alpha2] end
Private Class Methods
dictionary(locale)
click to toggle source
@param [String] locale @return [Hash<String, String>]
# File lib/llaxta.rb, line 30 def dictionary(locale) @@locales ||= {} @@locales[locale] ||= new(locale).send(:load_dict) end
Private Instance Methods
load_dict()
click to toggle source
@return [void] @raise [Exceptions::LocaleNotFound] if unable to load a YAML file given an unexpected locale
# File lib/llaxta.rb, line 61 def load_dict YAML.load_file(locale_path) rescue Errno::ENOENT raise Exceptions::LocaleNotFound.new(locale) end
locale_path()
click to toggle source
@return [String]
# File lib/llaxta.rb, line 68 def locale_path File.expand_path("../llaxta/locales/#{locale}.yml", __FILE__) end