Included Modules

Locale::Tag::Common

Common Language tag class for Ruby. Java and MS Windows use this format.

Constants

LANGUAGE
SCRIPT
VARIANT
TAG_RE

Attributes

script[R]
variants[R]

Public Class Methods

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

Create a Locale::Tag::Common.

    # File lib/locale/tag/common.rb, line 56
56:       def initialize(language, script = nil, region = nil, variants = [])
57:         @script, @variants = script, variants
58:         @script = @script.capitalize  if @script
59:         super(language, region)
60:       end
parse(tag) click to toggle source

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

    # File lib/locale/tag/common.rb, line 38
38:         def parse(tag)
39:           if tag =~ /\APOSIX\Z/  # This is the special case of POSIX locale but match this regexp.
40:             nil
41:           elsif tag =~ TAG_RE
42:             lang, script, region, subtag = $1, $2, $3, $4
43:             variants = subtag.scan(/(^|[-_])#{VARIANT}(?=([-_]|$))/).collect{|v| v[1]}
44:             
45:             ret = self.new(lang, script, region, variants)
46:             ret.tag = tag
47:             ret
48:           else
49:             nil
50:           end
51:         end

Public Instance Methods

candidates() click to toggle source

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.

    # File lib/locale/tag/common.rb, line 81
81:       def candidates
82:         [self.class.new(language, script, region, variants),   #ja-Kana-JP-FOO
83:          self.class.new(language, script, region),             #ja-Kana-JP
84:          self.class.new(language, nil, region, variants),      #ja-JP-FOO
85:          self.class.new(language, nil, region),                #ja-JP
86:          self.class.new(language, script, nil, variants),      #ja-Kana-FOO
87:          self.class.new(language, script),                     #ja-Kana
88:          self.class.new(language, nil, nil, variants),         #ja-FOO
89:          self.class.new(language)]                             #ja
90:       end
script=(val) click to toggle source

Set the script (with capitalize)

    # File lib/locale/tag/common.rb, line 63
63:       def script=(val)
64:         clear
65:         @script = val
66:         @script = @script.capitalize if @script
67:         @script
68:       end
variants=(val) click to toggle source

Set the variants as an Array.

    # File lib/locale/tag/common.rb, line 71
71:       def variants=(val)
72:         clear
73:         @variants = val
74:       end

Private Instance Methods

to_string() click to toggle source

Returns the common language tag with “_”.

  <language>_<Script>_<REGION>_VARIANTS1_VARIANTS2
  (e.g.) "ja_Hira_JP_VARIANTS1_VARIANTS2"

This is used in internal only. Use to_s instead.

     # File lib/locale/tag/common.rb, line 116
116:       def to_string
117:         s = @language.dup
118:     
119:         s << "_" << @script if @script
120:         s << "_" << @region if @region
121: 
122:         @variants.each do |v|
123:           s << "_#{v}"
124:         end
125:         s
126:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.