Module: Lang::Tag::Lookup
- Included in:
- Grandfathered, Langtag, Privateuse
- Defined in:
- lib/lang/tag/lookup.rb
Overview
Lookup. RFC 4647, Section 3.4.
Instance Method Summary collapse
- #in?(range) ⇒ Boolean
-
#lookup_candidates(min_subtags_count = 1) ⇒ Object
– RFC 4647, Section 3.4.
Instance Method Details
#in?(range) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/lang/tag/lookup.rb', line 46 def in?(range) range = Composition === range ? range.composition : range.to_str.downcase return true if composition == range range.index(composition) == 0 end |
#lookup_candidates(min_subtags_count = 1) ⇒ Object
– RFC 4647, Section 3.4
In the lookup scheme, the language range is progressively truncated from the end until a matching language tag is located. Single letter or digit subtags (including both the letter ‘x’, which introduces private-use sequences, and the subtags that introduce extensions) are removed at the same time as their closest trailing subtag. For example, starting with the range “zh-Hant-CN-x-private1-private2” (Chinese, Traditional script, China, two private-use tags) the lookup progressively searches for content as shown below:
Example of a Lookup Fallback Pattern
Range to match: zh-Hant-CN-x-private1-private2
-
zh-Hant-CN-x-private1-private2
-
zh-Hant-CN-x-private1
-
zh-Hant-CN
-
zh-Hant
-
zh
-
(default)
++
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lang/tag/lookup.rb', line 34 def lookup_candidates( = 1) = to_a return nil if < 1 || .size < candidates = [] for i in ( - 1)..(.size - 1) do next if [i].size == 1 candidates.unshift [0..i].join(HYPHEN) end candidates end |