Class: Locale::Tag::Common
Overview
Common Language tag class for Ruby. Java and MS Windows use this format.
-
ja (language: RFC4646)
-
ja_JP (country: RFC4646(2 alpha or 3 digit))
-
ja-JP
-
ja_Hira_JP (script: 4 characters)
-
ja-Hira-JP
-
ja_Hira_JP_MOBILE (variants: more than 2 characters or 3 digit)
-
ja_Hira_JP_MOBILE_IPHONE (2 variants example)
Constant Summary collapse
- LANGUAGE =
RFC4646 (ISO639/reserved/registered)
"(#{ALPHA}{2,3}|#{ALPHA}{4}|#{ALPHA}{5,8})"
- SCRIPT =
"(#{ALPHA}{4})"
- VARIANT =
RFC3066 compatible
"(#{ALPHANUM}{3,}|#{DIGIT}#{ALPHANUM}{3})"
- TAG_RE =
/\A#{LANGUAGE}(?:[-_]#{SCRIPT})? (?:[-_]#{REGION})?((?:[-_]#{VARIANT})*)\Z/ix
Constants inherited from Simple
Simple::ALPHA, Simple::ALPHANUM, Simple::DIGIT, Simple::REGION
Instance Attribute Summary collapse
-
#script ⇒ Object
Returns the value of attribute script.
-
#variants ⇒ Object
Returns the value of attribute variants.
Attributes inherited from Simple
Class Method Summary collapse
-
.parse(tag) ⇒ Object
Parse the language tag and return the new Locale::Tag::Common.
Instance Method Summary collapse
-
#candidates ⇒ Object
Returns an Array of tag-candidates order by priority.
-
#initialize(language, script = nil, region = nil, variants = []) ⇒ Common
constructor
Create a Locale::Tag::Common.
Methods inherited from Simple
#<=>, #==, #country, #eql?, #hash, #inspect, #to_s, #to_str
Constructor Details
#initialize(language, script = nil, region = nil, variants = []) ⇒ Common
Create a Locale::Tag::Common.
56 57 58 59 60 |
# File 'lib/locale/tag/common.rb', line 56 def initialize(language, script = nil, region = nil, variants = []) @script, @variants = script, variants @script = @script.capitalize if @script super(language, region) end |
Instance Attribute Details
#script ⇒ Object
Returns the value of attribute script.
34 35 36 |
# File 'lib/locale/tag/common.rb', line 34 def script @script end |
#variants ⇒ Object
Returns the value of attribute variants.
34 35 36 |
# File 'lib/locale/tag/common.rb', line 34 def variants @variants end |
Class Method Details
.parse(tag) ⇒ Object
Parse the language tag and return the new Locale::Tag::Common.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/locale/tag/common.rb', line 38 def parse(tag) case tag when /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp. nil when TAG_RE lang, script, region, subtag = $1, $2, $3, $4 variants = subtag.scan(/(^|[-_])#{VARIANT}(?=([-_]|$))/i).collect{|v| v[1]} ret = self.new(lang, script, region, variants) ret.tag = tag ret else nil end end |
Instance Method Details
#candidates ⇒ Object
Returns an Array of tag-candidates order by priority. Use Locale.candidates instead of this method.
Locale::Tag::Rfc, Cldr don’t have their own candidates, because it’s meaningless to compare the extensions, privateuse, etc.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/locale/tag/common.rb', line 79 def candidates [self.class.new(language, script, region, variants), #ja-Kana-JP-FOO self.class.new(language, script, region), #ja-Kana-JP self.class.new(language, nil, region, variants), #ja-JP-FOO self.class.new(language, nil, region), #ja-JP self.class.new(language, script, nil, variants), #ja-Kana-FOO self.class.new(language, script), #ja-Kana self.class.new(language, nil, nil, variants), #ja-FOO self.class.new(language)] #ja end |