Class: Locale::Tag::Simple
Abstract language tag class. This class has <language>, <region> which all of language tag specifications have.
- ja (language: ISO 639 (2 or 3 alpha))
- ja_JP (country: RFC4646 (ISO3166/UN M.49) (2 alpha or 3 digit)
- ja-JP
- ja-392
Constants
Name | Value |
---|---|
ALPHA | '[a-z]' |
DIGIT | '[0-9]' |
ALPHANUM | "[a-zA-Z0-9]" |
LANGUAGE | "(#{ALPHA}{2,3})" |
REGION | "(#{ALPHA}{2}|#{DIGIT}{3})" |
TAG_RE | /\A#{LANGUAGE}(?:[_-]#{REGION})?\Z/i |
Attributes
Name | Read/write? |
---|---|
language | R |
region | R |
tag | RW |
Public Class Methods
new (language, region = nil)
Create a Locale::Tag::Simple
# File lib/locale/tag/simple.rb, line 72 72: def initialize(language, region = nil) 73: raise "language can't be nil." unless language 74: @language, @region = language, region 75: @language.downcase! if @language 76: @region.upcase! if @region 77: end
parse (tag)
Parse the language tag and return the new Locale::Tag::Simple.
# File lib/locale/tag/simple.rb, line 44 44: def self.parse(tag) 45: if tag =~ TAG_RE 46: ret = self.new($1, $2) 47: ret.tag = tag 48: ret 49: else 50: nil 51: end 52: end
Public Instance Methods
candidates ()
Returns an Array of tag-candidates order by priority. Use Locale.candidates instead of this method.
# File lib/locale/tag/simple.rb, line 129 129: def candidates 130: [self.class.new(language, region), self.class.new(language)] 131: end
country ()
For backward compatibility.
# File lib/locale/tag/simple.rb, line 109 109: def country; region end
language= (val)
Set the language (with downcase)
# File lib/locale/tag/simple.rb, line 112 112: def language=(val) 113: clear 114: @language = val 115: @language.downcase! if @language 116: @language 117: end
region= (val)
Set the region (with upcase)
# File lib/locale/tag/simple.rb, line 120 120: def region=(val) 121: clear 122: @region = val 123: @region.upcase! if @region 124: @region 125: end
to_s ()
Returns the language tag as the String.
<language>_<REGION> (e.g.) "ja_JP"
# File lib/locale/tag/simple.rb, line 82 82: def to_s 83: s = @language.dup 84: s << "_" << @region if @region 85: s 86: end