Module: I18n::Locale::Tag::Rfc4646::Parser

Defined in:
lib/i18n/locale/tag/rfc4646.rb

Constant Summary collapse

PATTERN =
%r{\A(?:
([a-z]{2,3}(?:(?:-[a-z]{3}){0,3})?|[a-z]{4}|[a-z]{5,8}) # language
(?:-([a-z]{4}))?                                        # script
(?:-([a-z]{2}|\d{3}))?                                  # region
(?:-([0-9a-z]{5,8}|\d[0-9a-z]{3}))*                     # variant
(?:-([0-9a-wyz](?:-[0-9a-z]{2,8})+))*                   # extension
(?:-(x(?:-[0-9a-z]{1,8})+))?|                           # privateuse subtag
(x(?:-[0-9a-z]{1,8})+)|                                 # privateuse tag
/* ([a-z]{1,3}(?:-[0-9a-z]{2,8}){1,2}) */               # grandfathered
)\z}xi

Class Method Summary collapse

Class Method Details

.match(tag) ⇒ Object



65
66
67
68
69
70
# File 'lib/i18n/locale/tag/rfc4646.rb', line 65

def match(tag)
  c = PATTERN.match(tag.to_s).captures
  c[0..4] << (c[5].nil? ? c[6] : c[5])  << c[7] # TODO c[7] is grandfathered, throw a NotImplemented exception here?
rescue
  false
end