Class: Locale::Tag::Rfc
Language tag class for RFC4646(BCP47).
Constants
Name | Value |
---|---|
SINGLETON | '[a-wyz0-9]' |
VARIANT | "(#{ALPHANUM}{5,8}|#{DIGIT}#{ALPHANUM}{3})" |
EXTENSION | "(#{SINGLETON}(?:-#{ALPHANUM}{2,8})+)" |
PRIVATEUSE | "(x(?:-#{ALPHANUM}{1,8})+)" |
GRANDFATHERED | "#{ALPHA}{1,3}(?:-#{ALPHANUM}{2,8}){1,2}" |
TAG_RE | /\A#{LANGUAGE}(?:-#{SCRIPT})? (?:-#{REGION})?((?:-#{VARIANT})* (?:-#{EXTENSION})*(?:-#{PRIVATEUSE})?)\Z/ix |
Attributes
Name | Read/write? |
---|---|
extensions | R |
privateuse | R |
Public Class Methods
new (language, script = nil, region = nil, variants = [], extensions = [], privateuse = nil)
# File lib/locale/tag/rfc.rb, line 29 29: def initialize(language, script = nil, region = nil, variants = [], 30: extensions = [], privateuse = nil) 31: @extensions, @privateuse = extensions, privateuse 32: super(language, script, region, variants) 33: end
parse (tag)
Parse the language tag and return the new Locale::Tag::Common.
# File lib/locale/tag/rfc.rb, line 36 36: def self.parse(tag) 37: if tag =~ /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp. 38: nil 39: elsif tag =~ TAG_RE 40: lang, script, region, subtag = $1, $2, $3, $4 41: extensions = [] 42: variants = [] 43: if subtag =~ /#{PRIVATEUSE}/ 44: subtag, privateuse = $`, $1 45: # Private use for CLDR. 46: if /x-ldml(.*)/ =~ privateuse 47: p_subtag = $1 48: extensions = p_subtag.scan(/(^|-)#{EXTENSION}/i).collect{|v| p_subtag.sub!(v[1], ""); v[1]} 49: variants = p_subtag.scan(/(^|-)#{VARIANT}(?=(-|$))/i).collect{|v| v[1]} 50: end 51: end 52: extensions += subtag.scan(/(^|-)#{EXTENSION}/i).collect{|v| subtag.sub!(v[1], ""); v[1]} 53: variants += subtag.scan(/(^|-)#{VARIANT}(?=(-|$))/i).collect{|v| v[1]} 54: 55: ret = self.new(lang, script, region, variants, extensions, privateuse) 56: ret.tag = tag 57: ret 58: else 59: nil 60: end 61: end
Public Instance Methods
extensions= (val)
Sets the extensions.
# File lib/locale/tag/rfc.rb, line 76 76: def extensions=(val) 77: clear 78: @extensions = val 79: end
privateuse= (val)
Sets the extensions.
# File lib/locale/tag/rfc.rb, line 82 82: def privateuse=(val) 83: clear 84: @privateuse = val 85: end
to_s ()
Returns the language tag
<language>-<Script>-<REGION>-<variants>-<extensions>-<PRIVATEUSE> (e.g.) "ja-Hira-JP-variant"
# File lib/locale/tag/rfc.rb, line 66 66: def to_s 67: s = super.to_s.gsub(/_/, "-") 68: @extensions.each do |v| 69: s << "-#{v}" 70: end 71: s << "-#{@privateuse}" if @privateuse 72: s 73: end