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.

Calls superclass method
# File lib/locale/tag/cldr.rb, line 56
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 30
def parse(tag)
  if tag =~ /\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(/#{EXTENSION}/i).each{|v| 
      subtag.sub!(v, "")
      key, type = v.split("=")
      extensions[key] = type
    }
    variants = subtag.scan(/#{VARIANT}/i).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 63
def extensions=(val)
  @extensions = val
end

Private Instance Methods

to_string() click to toggle source

Returns the language tag. (e.g.) “ja_Hira_JP_VARIANT1_VARIANT2@foo1=var1;foo2=var2”

This is used in internal only. Use to_s instead.

Calls superclass method
# File lib/locale/tag/cldr.rb, line 87
def to_string
  s = super
  if @extensions.size > 0
    s << "@" << @extensions.to_a.sort.map{|k, v| "#{k}=#{v}"}.join(";")
  end
  s 
end