Module: Lang::Tag
- Defined in:
- lib/lang/tag.rb,
lib/lang/tag/lookup.rb,
lib/lang/tag/langtag.rb,
lib/lang/tag/pattern.rb,
lib/lang/tag/filtering.rb,
lib/lang/tag/privateuse.rb,
lib/lang/tag/composition.rb,
lib/lang/tag/grandfathered.rb,
lib/lang/tag/canonicalization.rb
Defined Under Namespace
Modules: Canonicalization, Filtering, Lookup, PATTERN Classes: Composition, Error, Grandfathered, InvalidComponentError, Langtag, Privateuse
Constant Summary collapse
- IRREGULAR =
– Grandfathered tags that do not match the ‘langtag’ production in the ABNF and would otherwise be invalid are considered ‘irregular’ grandfathered tags. With the exception of “en-GB-oed”, which is a variant of “en-GB”, each of them, in its entirety, represents a language. ++
{ 'en-gb-oed' => nil , 'i-ami' => 'ami' , 'i-bnn' => 'bnn' , 'i-default' => nil , 'i-enochian' => nil , 'i-hak' => 'hak' , 'i-klingon' => 'tlh' , 'i-lux' => 'lb' , 'i-mingo' => nil , 'i-navajo' => 'nv' , 'i-pwn' => 'pwn' , 'i-tao' => 'tao' , 'i-tay' => 'tay' , 'i-tsu' => 'tsu' , 'sgn-be-fr' => 'sfb' , 'sgn-be-nl' => 'vgt' , 'sgn-ch-de' => 'sgg' , }.freeze
- GRANDFATHERED =
– Grandfathered tags that (appear to) match the ‘langtag’ production in Figure 1 are considered ‘regular’ grandfathered tags. These tags contain one or more subtags that either do not individually appear in the registry or appear but with a different semantic meaning: each tag, in its entirety, represents a language or collection of languages. ++
IRREGULAR.merge( 'art-lojban' => 'jbo' , 'cel-gaulish' => nil , 'no-bok' => 'nb' , 'no-nyn' => 'nn' , 'zh-guoyu' => 'cmn' , 'zh-hakka' => 'hak' , 'zh-min' => nil , 'zh-min-nan' => 'nan' , 'zh-xiang' => 'hsn' ).freeze
- HYPHEN =
'-'.freeze
- HYPHEN_SPLITTER =
RUBY_VERSION < '1.9.1' ? /-/.freeze : HYPHEN
- PRIVATEUSE =
'x'.freeze
- LANGUAGE_REGEX =
/^(?:#{PATTERN::LANGUAGE})$/io.freeze
- SCRIPT_REGEX =
/^(?:#{PATTERN::SCRIPT})$/io.freeze
- REGION_REGEX =
/^(?:#{PATTERN::REGION})$/io.freeze
- VARIANTS_SEQUENCE_REGEX =
/^(?:#{PATTERN::VARIANT_SEQUENCE}+)$/io.freeze
- EXTENSIONS_SEQUENCE_REGEX =
/^#{PATTERN::EXTENSION_SEQUENCE}+$/io.freeze
- EXTENSIONS_SEQUENCE_SPLITTER =
/(?:^|-)(?=#{PATTERN::SINGLETON}-)/io.freeze
- PRIVATEUSE_REGEX =
/^#{PATTERN::PRIVATEUSE}$/io.freeze
- LANGTAG_REGEX =
/^ (#{PATTERN::LANGUAGE}) (?# shortest ISO 639 code plus extlang or reserved for future use or registered language subtag) (?:-(#{PATTERN::SCRIPT}))? (?# ISO 15924 code) (?:-(#{PATTERN::REGION}))? (?# ISO 3166-1 code or UN M.49 code) (#{PATTERN::VARIANT_SEQUENCE}*)? (?# registered variants) (#{PATTERN::EXTENSION_SEQUENCE}*)? (?# extensions) (?=(?:-#{PATTERN::PRIVATEUSE})?$) (?# privateuse) /iox.freeze
- LANGTAG_WELLFORMEDNESS_REGEX =
/^ (?:#{PATTERN::LOOSE_LANGUAGE}) (?# shortest ISO 639 code plus at most 3 extlangs or reserved for future use or registered language subtag) (?:-(?:#{PATTERN::SCRIPT}))? (?# ISO 15924 code) (?:-(?:#{PATTERN::REGION}))? (?# ISO 3166-1 code or UN M.49 code) (?=#{PATTERN::VARIANT_SEQUENCE}* (?# registered variants) #{PATTERN::EXTENSION_SEQUENCE}* (?# extensions) (?:-#{PATTERN::PRIVATEUSE})?$) (?# privateuse) /iox.freeze
Class Method Summary collapse
- .Grandfathered(thing) ⇒ Object
-
.grandfathered?(snippet) ⇒ Boolean
Checks if the
String
passed represents a ‘grandfathered’ language tag. - .Langtag(thing = nil) ⇒ Object
- .Privateuse(thing) ⇒ Object
-
.privateuse?(snippet) ⇒ Boolean
Checks if the
String
passed represents a ‘privateuse’ language tag. -
.wellformed?(snippet) ⇒ Boolean
Checks if the
String
passed represents a well-formed language tag.
Class Method Details
.Grandfathered(thing) ⇒ Object
6 7 8 9 |
# File 'lib/lang/tag/grandfathered.rb', line 6 def self.Grandfathered(thing) return thing if Grandfathered === thing Grandfathered.new(thing) end |
.grandfathered?(snippet) ⇒ Boolean
Checks if the String
passed represents a ‘grandfathered’ language tag. Works case-insensitively.
116 117 118 |
# File 'lib/lang/tag.rb', line 116 def grandfathered?(snippet) GRANDFATHERED.key?(snippet) || GRANDFATHERED.key?(snippet.downcase) end |
.Langtag(thing = nil) ⇒ Object
6 7 8 9 |
# File 'lib/lang/tag/langtag.rb', line 6 def self.Langtag(thing = nil) return thing if Langtag === thing Langtag.new(thing) end |
.Privateuse(thing) ⇒ Object
6 7 8 9 |
# File 'lib/lang/tag/privateuse.rb', line 6 def self.Privateuse(thing) return thing if Privateuse === thing Privateuse.new(thing) end |
.privateuse?(snippet) ⇒ Boolean
Checks if the String
passed represents a ‘privateuse’ language tag. Works case-insensitively.
109 110 111 |
# File 'lib/lang/tag.rb', line 109 def privateuse?(snippet) PRIVATEUSE_REGEX === snippet end |
.wellformed?(snippet) ⇒ Boolean
Checks if the String
passed represents a well-formed language tag. Works case-insensitively.
132 133 134 |
# File 'lib/lang/tag.rb', line 132 def wellformed?(snippet) privateuse?(snippet) || grandfathered?(snippet) || LANGTAG_WELLFORMEDNESS_REGEX === snippet end |