class Locale::Tag::Cldr

Unicode locale identifier class for CLDR-1.6.1. (Unicode Common Locale Data Repository).

Constants

EXTENSION
TAG_RE
VARIANT

Attributes

extensions[R]

Public Class Methods

new(language, script = nil, region = nil, variants = [], extensions = {}) click to toggle source

Create Locale::Tag::Cldr.

variants should be upcase.

# File lib/locale/tag/cldr.rb, line 58
def initialize(language, script = nil, region = nil, 
               variants = [], extensions = {})
  @extensions = extensions
  super(language, script, region, variants.map{|v| v.upcase})
end
parse(tag) click to toggle source

Parse the language tag and return the new Locale::Tag::CLDR.

# File lib/locale/tag/cldr.rb, line 31
def parse(tag)
  if tag =~ %r\APOSIX\Z/  # This is the special case of POSIX locale but match this regexp.
    nil
  elsif tag =~ TAG_RE
    lang, script, region, subtag = $1, $2, $3, $4
    
    extensions = {}
    subtag.scan(%r#{EXTENSION}/).each{|v| 
      subtag.sub!(v, "")
      key, type = v.split("=")
      extensions[key] = type
    }
    variants = subtag.scan(%r#{VARIANT}/).collect{|v| v[0].upcase}
    
    ret = self.new(lang, script, region, variants, extensions)
    ret.tag = tag
    ret
  else
    nil
  end
end

Public Instance Methods

extensions=(val) click to toggle source

Sets the extensions as an Hash.

# File lib/locale/tag/cldr.rb, line 65
def extensions=(val)
  clear
  @extensions = val
end