Module: Multilang::LanguageNames

Defined in:
lib/multilang/language_names.rb

Class Method Summary collapse

Class Method Details

.[](spec) ⇒ String

Convert from the language specifier to the language name.

Parameters:

  • spec (String)

    the language name

  • spec (Symbol)

    the language code (ISO639-2 or ISO639-1)

Returns:

  • (String)

    normalized language name



30
31
32
33
34
35
36
37
38
# File 'lib/multilang/language_names.rb', line 30

def self.[](spec)
  map, key = case spec
             when String then [NAME_MAP, spec]
             when Symbol then [CODE_MAP, spec.to_s]
             else             raise TypeError, "can't convert #{spec.class} into #{String} or #{Symbol}"
             end

  map[key.downcase] or raise ArgumentError, "#{spec.inspect} language specifier does not defined"
end