Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RBNF fall back to root #257

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions lib/cldr/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def shared_component?(component)
end

def should_merge_root?(component)
return false if [:Rbnf, :Fields].include?(component)

true
![:Fields].include?(component)
end
end
end
Expand Down
30 changes: 19 additions & 11 deletions lib/cldr/export/data/rbnf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,39 @@ def rule_groups
return {} if grouping_nodes.empty?

grouping_nodes.map do |grouping_node|
{
type: grouping_node.attribute("type").value,
ruleset: (grouping_node / "ruleset").map do |ruleset_node|
rule_set(ruleset_node)
end,
}
end
type = grouping_node.attribute("type").value.underscore
next if type == "numbering_system_rules" && !is_a?(RbnfRoot)

[
type,
(grouping_node / "ruleset").map do |ruleset_node|
[
ruleset_node.attribute("type").value,
rule_set(ruleset_node),
]
end.to_h,
]
end.compact.to_h
end

def rule_set(ruleset_node)
attrs = {
type: ruleset_node.attribute("type").value,
rules: (ruleset_node / "rbnfrule").map do |rule_node|
radix = if (radix_attr = rule_node.attribute("radix"))
cast_value(radix_attr.value)
end

attrs = {
value: cast_value(rule_node.attribute("value").value),
rule: fix_rule(rule_node.text),
}

attrs[:radix] = radix if radix
attrs
end,

[
cast_value(rule_node.attribute("value").value).to_s,
attrs,
]
end.to_h,
}

access = ruleset_node.attribute("access")
Expand Down
14 changes: 14 additions & 0 deletions lib/cldr/export/deep_validate_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ def validate(hash, component, key_path = [])
],
RegionCurrencies: [["region_currencies", "."]],
ParentLocales: [["."]],
Rbnf: [
["rbnf", "grouping", "ordinal_rules", "."],
["rbnf", "grouping", "ordinal_rules", ".", "rules", "."],
["rbnf", "grouping", "spellout_rules", "."],
["rbnf", "grouping", "spellout_rules", ".", "rules", "."],
],
RbnfRoot: [
["rbnf", "grouping", "ordinal_rules", "."],
["rbnf", "grouping", "ordinal_rules", ".", "rules", "."],
["rbnf", "grouping", "numbering_system_rules", "."],
["rbnf", "grouping", "numbering_system_rules", ".", "rules", "."],
["rbnf", "grouping", "spellout_rules", "."],
["rbnf", "grouping", "spellout_rules", ".", "rules", "."],
],
Subdivisions: [["subdivisions", "."]],
Territories: [["territories", "."]],
TerritoriesContainment: [["territories", "."]],
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/export/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def export(locale, component, options = {})

private

UNSORTED_COMPONENTS = [:Calendars, :Delimiters, :Lists].freeze
UNSORTED_COMPONENTS = [:Calendars, :Delimiters, :Lists, :Rbnf, :RbnfRoot].freeze

def format(data, locale, component)
data.deep_prune!
Expand Down
Loading