Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add `WeekData` component, [#229](https://github.com/ruby-i18n/ruby-cldr/pull/229)
- Drop support for Ruby 2, [#265](https://github.com/ruby-i18n/ruby-cldr/pull/265)
- Drop support for Ruby 3.0, [#268](https://github.com/ruby-i18n/ruby-cldr/pull/268)
- Add `LanguageInfo` component

---

Expand Down
1 change: 1 addition & 0 deletions lib/cldr/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Export
:Aliases,
:CountryCodes,
:CurrencyDigitsAndRounding,
:LanguageInfo,
:LikelySubtags,
:Metazones,
:NumberingSystems,
Expand Down
1 change: 1 addition & 0 deletions lib/cldr/export/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Data
autoload :Delimiters, "cldr/export/data/delimiters"
autoload :Fields, "cldr/export/data/fields"
autoload :Languages, "cldr/export/data/languages"
autoload :LanguageInfo, "cldr/export/data/language_info"
autoload :Layout, "cldr/export/data/layout"
autoload :LikelySubtags, "cldr/export/data/likely_subtags"
autoload :Lists, "cldr/export/data/lists"
Expand Down
55 changes: 55 additions & 0 deletions lib/cldr/export/data/language_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

module Cldr
module Export
module Data
class LanguageInfo < Base
def initialize
super(nil)
update(language_matching: language_matching)
deep_sort!
end

private

def language_matching
doc.xpath("//languageMatching/languageMatches").each_with_object({}) do |matches_node, ret|
matching_type = matches_node.attribute("type").to_s.underscore.to_sym
ret[matching_type] = {
paradigm_locales: paradigm_locales(matches_node),
match_variables: match_variables(matches_node),
language_matches: language_matches(matches_node),
}
end
end

def paradigm_locales(matches_node)
locales_node = matches_node.xpath("./paradigmLocales").first
return [] unless locales_node

locales_str = locales_node.attribute("locales").to_s
locales_str.split(" ").map { |locale| Cldr::Export.to_i18n(locale).to_s }
end

def match_variables(matches_node)
matches_node.xpath("./matchVariable").each_with_object({}) do |var_node, hash|
id = var_node.attribute("id").to_s
value = var_node.attribute("value").to_s
hash[id] = value
end
end

def language_matches(matches_node)
matches_node.xpath("./languageMatch").map do |match_node|
{
desired: Cldr::Export.to_i18n(match_node.attribute("desired")).to_s,
supported: Cldr::Export.to_i18n(match_node.attribute("supported")).to_s,
distance: match_node.attribute("distance").to_s.to_i,
oneway: match_node.attribute("oneway").to_s == "true",
}.reject { |_, v| v == false }
end
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/cldr/export/deep_validate_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def validate(hash, component, key_path = [])
CountryCodes: [["country_codes", "."]],
CurrencyDigitsAndRounding: [["."]],
Fields: [["*", "relative", "."]],
LanguageInfo: [
["language_matching", ".", "match_variables", "."],
["language_matching", ".", "paradigm_locales", "."],
],
Languages: [["languages", "."]],
LikelySubtags: [["subtags", "."]],
Metazones: [
Expand Down
Loading