From 5319eae03d58490c1c4d558c3dc4d5e20a192428 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Tue, 19 Apr 2022 15:05:23 -0400 Subject: [PATCH 1/5] Add `DraftStatus` --- lib/cldr.rb | 9 ++++---- lib/cldr/draft_status.rb | 42 ++++++++++++++++++++++++++++++++++++++ test/draft_status_test.rb | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 lib/cldr/draft_status.rb create mode 100644 test/draft_status_test.rb diff --git a/lib/cldr.rb b/lib/cldr.rb index ada3f05e..921cb16f 100644 --- a/lib/cldr.rb +++ b/lib/cldr.rb @@ -3,10 +3,11 @@ require "core_ext/hash/symbolize_keys" module Cldr - autoload :Data, "cldr/data" - autoload :Export, "cldr/export" - autoload :Locale, "cldr/locale" - autoload :Format, "cldr/format" + autoload :Data, "cldr/data" + autoload :DraftStatus, "cldr/draft_status" + autoload :Export, "cldr/export" + autoload :Locale, "cldr/locale" + autoload :Format, "cldr/format" class << self def fallbacks diff --git a/lib/cldr/draft_status.rb b/lib/cldr/draft_status.rb new file mode 100644 index 00000000..d1c29413 --- /dev/null +++ b/lib/cldr/draft_status.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Cldr + module DraftStatus + class Status + include Comparable + + def initialize(name, value) + @name = name + @value = value + end + + def <=>(other) + @value <=> other.value + end + + def to_s + @name.to_s + end + + protected + + attr_reader :value + end + + ALL = [ + :unconfirmed, + :provisional, + :contributed, + :approved, + ].map.with_index do |name, index| + const_set(name.upcase, Status.new(name, index)) + end.freeze + + ALL_BY_NAME = ALL.to_h { |status| [status.to_s, status] }.freeze + private_constant :ALL_BY_NAME + + def self.fetch(name) + ALL_BY_NAME.fetch(name.to_s) + end + end +end diff --git a/test/draft_status_test.rb b/test/draft_status_test.rb new file mode 100644 index 00000000..60611e96 --- /dev/null +++ b/test/draft_status_test.rb @@ -0,0 +1,43 @@ +# encoding: utf-8 +# frozen_string_literal: true + +require File.expand_path(File.join(File.dirname(__FILE__), "test_helper")) + +class TestExport < Test::Unit::TestCase + def test_statuses_can_be_compared + assert(Cldr::DraftStatus::UNCONFIRMED < Cldr::DraftStatus::PROVISIONAL) + assert(Cldr::DraftStatus::PROVISIONAL < Cldr::DraftStatus::CONTRIBUTED) + assert(Cldr::DraftStatus::CONTRIBUTED < Cldr::DraftStatus::APPROVED) + end + + def test_statuses_can_be_looked_up_by_name + assert_equal(Cldr::DraftStatus::UNCONFIRMED, Cldr::DraftStatus.fetch("unconfirmed")) + assert_equal(Cldr::DraftStatus::PROVISIONAL, Cldr::DraftStatus.fetch("provisional")) + assert_equal(Cldr::DraftStatus::CONTRIBUTED, Cldr::DraftStatus.fetch("contributed")) + assert_equal(Cldr::DraftStatus::APPROVED, Cldr::DraftStatus.fetch("approved")) + end + + def test_statuses_can_be_looked_up_by_symbolic_name + assert_equal(Cldr::DraftStatus::UNCONFIRMED, Cldr::DraftStatus.fetch(:unconfirmed)) + assert_equal(Cldr::DraftStatus::PROVISIONAL, Cldr::DraftStatus.fetch(:provisional)) + assert_equal(Cldr::DraftStatus::CONTRIBUTED, Cldr::DraftStatus.fetch(:contributed)) + assert_equal(Cldr::DraftStatus::APPROVED, Cldr::DraftStatus.fetch(:approved)) + end + + def test_statuses_can_be_looked_up_by_themselves + assert_equal(Cldr::DraftStatus::UNCONFIRMED, Cldr::DraftStatus.fetch(Cldr::DraftStatus::UNCONFIRMED)) + assert_equal(Cldr::DraftStatus::PROVISIONAL, Cldr::DraftStatus.fetch(Cldr::DraftStatus::PROVISIONAL)) + assert_equal(Cldr::DraftStatus::CONTRIBUTED, Cldr::DraftStatus.fetch(Cldr::DraftStatus::CONTRIBUTED)) + assert_equal(Cldr::DraftStatus::APPROVED, Cldr::DraftStatus.fetch(Cldr::DraftStatus::APPROVED)) + end + + def test_invalid_statuses_are_not_found + assert_raises(KeyError) { Cldr::DraftStatus.fetch(:invalid) } + end + + def test_statuses_are_their_own_class + Cldr::DraftStatus::ALL.each do |status| + assert_instance_of(Cldr::DraftStatus::Status, status) + end + end +end From 64dc5d8bf5803adeddb2f8fdd4ca0f40672e9652 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Tue, 19 Apr 2022 15:06:00 -0400 Subject: [PATCH 2/5] Add `--draft-status` CLI option --- lib/cldr/thor.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cldr/thor.rb b/lib/cldr/thor.rb index 4607d191..1dd346a8 100644 --- a/lib/cldr/thor.rb +++ b/lib/cldr/thor.rb @@ -25,11 +25,18 @@ def download Cldr::Download.download(options["source"], options["target"], options["version"]) end + DEFAULT_MINIMUM_DRAFT_STATUS = Cldr::DraftStatus::CONTRIBUTED + desc "export [--locales=de fr-FR en-ZA] [--components=Numbers Plurals] [--target=#{Cldr::Export::DEFAULT_TARGET}] [--merge/--no-merge]", "Export CLDR data by locales and components to target dir" option :locales, aliases: [:l], type: :array, banner: "de fr-FR en-ZA", enum: Cldr::Export::Data.locales option :components, aliases: [:c], type: :array, banner: "Numbers Plurals", enum: Cldr::Export::Data.components option :target, aliases: [:t], type: :string, default: Cldr::Export::DEFAULT_TARGET, banner: Cldr::Export::DEFAULT_TARGET + option :draft_status, aliases: [:d], type: :string, + enum: Cldr::DraftStatus::ALL.map(&:to_s), + default: DEFAULT_MINIMUM_DRAFT_STATUS.to_s, + banner: DEFAULT_MINIMUM_DRAFT_STATUS.to_s, + desc: "The minimum draft status to include in the export" option :merge, aliases: [:m], type: :boolean, default: false def export $stdout.sync @@ -49,6 +56,11 @@ def export raise ArgumentError, "Unknown components: #{unknown_components.join(", ")}" unless unknown_components.empty? end + if formatted_options.key?(:draft_status) + formatted_options[:minimum_draft_status] = Cldr::DraftStatus.fetch(formatted_options[:draft_status]) + formatted_options.delete(:draft_status) + end + Cldr::Export.export(formatted_options) { putc(".") } puts end From 172ac987fcc1416b729332f559c096bc35817278 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Tue, 19 Apr 2022 10:05:26 -0400 Subject: [PATCH 3/5] Add `DataFile`s Provides a view into the data that is filtered by draft level --- lib/cldr/export.rb | 19 +- lib/cldr/export/data/base.rb | 27 +-- .../data/currency_digits_and_rounding.rb | 2 +- lib/cldr/export/data/metazones.rb | 2 +- lib/cldr/export/data/parent_locales.rb | 2 +- lib/cldr/export/data/plural_rules.rb | 4 +- lib/cldr/export/data/plurals.rb | 6 +- lib/cldr/export/data/plurals/rules.rb | 2 +- lib/cldr/export/data/windows_zones.rb | 2 +- lib/cldr/export/data_file.rb | 83 +++++++ test/export/data_file_test.rb | 223 ++++++++++++++++++ test/export_test.rb | 1 + test/format/date_test.rb | 1 + test/format/datetime_test.rb | 1 + test/format/time_test.rb | 1 + test/test_helper.rb | 4 + 16 files changed, 343 insertions(+), 37 deletions(-) create mode 100644 lib/cldr/export/data_file.rb create mode 100644 test/export/data_file_test.rb diff --git a/lib/cldr/export.rb b/lib/cldr/export.rb index 5cd2294a..2e137e86 100644 --- a/lib/cldr/export.rb +++ b/lib/cldr/export.rb @@ -12,10 +12,11 @@ module Cldr module Export - autoload :Code, "cldr/export/code" - autoload :Data, "cldr/export/data" - autoload :Ruby, "cldr/export/ruby" - autoload :Yaml, "cldr/export/yaml" + autoload :Code, "cldr/export/code" + autoload :Data, "cldr/export/data" + autoload :DataFile, "cldr/export/data_file" + autoload :Ruby, "cldr/export/ruby" + autoload :Yaml, "cldr/export/yaml" SHARED_COMPONENTS = [ :Aliases, :CountryCodes, :CurrencyDigitsAndRounding, :LikelySubtags, @@ -35,9 +36,19 @@ def base_path=(base_path) @@base_path = File.expand_path(base_path) end + def minimum_draft_status + raise StandardError, "minimum_draft_status is not yet set." unless defined?(@@minimum_draft_status) + @@minimum_draft_status + end + + def minimum_draft_status=(draft_status) + @@minimum_draft_status = draft_status + end + def export(options = {}, &block) locales = options[:locales] || Data.locales components = options[:components] || Data.components + self.minimum_draft_status = options[:minimum_draft_status] if options[:minimum_draft_status] self.base_path = options[:target] if options[:target] shared_components, locale_components = components.partition do |component| diff --git a/lib/cldr/export/data/base.rb b/lib/cldr/export/data/base.rb index fada0f57..7075baab 100644 --- a/lib/cldr/export/data/base.rb +++ b/lib/cldr/export/data/base.rb @@ -68,26 +68,13 @@ def paths private def merge_paths(paths_to_merge) - # Some parts (`ldml`, `ldmlBCP47` amd `supplementalData`) of CLDR data require that you merge all the - # files with the same root element before doing lookups. - # Ref: https://www.unicode.org/reports/tr35/tr35.html#XML_Format - # - # The return of this method is a merged XML Nokogiri document. - # Note that it technically is no longer compliant with the CLDR `ldml.dtd`, since: - # * it has repeated elements - # * the elements no longer refer to the filename - # - # However, this is not an issue, since #select will find all of the matches from each of the repeated elements, - # and the elements are not important to us / make no sense when combined together. - return Nokogiri::XML("") if paths_to_merge.empty? - - rest = paths_to_merge[1..paths_to_merge.size - 1] - rest.each_with_object(Nokogiri::XML(File.read(paths_to_merge.first))) do |path, result| - next_doc = Nokogiri::XML(File.read(path)) - - next_doc.root.children.each do |child| - result.root.add_child(child) - end + return Cldr::Export::DataFile.new(Nokogiri::XML("")) if paths_to_merge.empty? + + first = Cldr::Export::DataFile.parse(File.read(paths_to_merge.first)) + rest = paths_to_merge[1..] + rest.reduce(first) do |result, path| + parsed = Cldr::Export::DataFile.parse(File.read(path)) + result.merge(parsed) end end end diff --git a/lib/cldr/export/data/currency_digits_and_rounding.rb b/lib/cldr/export/data/currency_digits_and_rounding.rb index 7bc60d59..d37362fb 100644 --- a/lib/cldr/export/data/currency_digits_and_rounding.rb +++ b/lib/cldr/export/data/currency_digits_and_rounding.rb @@ -10,7 +10,7 @@ def initialize super path = "#{Cldr::Export::Data.dir}/supplemental/supplementalData.xml" - doc = File.open(path) { |file| Nokogiri::XML(file) } + doc = Cldr::Export::DataFile.parse(File.read(path)) doc.xpath("//currencyData/fractions/info").each do |node| code = node.attr("iso4217") diff --git a/lib/cldr/export/data/metazones.rb b/lib/cldr/export/data/metazones.rb index 761e2775..1d78de3c 100644 --- a/lib/cldr/export/data/metazones.rb +++ b/lib/cldr/export/data/metazones.rb @@ -11,7 +11,7 @@ def initialize super path = "#{Cldr::Export::Data.dir}/supplemental/metaZones.xml" - doc = File.open(path) { |file| Nokogiri::XML(file) } + doc = Cldr::Export::DataFile.parse(File.read(path)) self[:timezones] = doc.xpath("//metaZones/metazoneInfo/timezone").each_with_object({}) do |node, result| timezone = node.attr("type").to_sym result[timezone] = metazone(node.xpath("usesMetazone")) diff --git a/lib/cldr/export/data/parent_locales.rb b/lib/cldr/export/data/parent_locales.rb index f9acbc52..55bef3dc 100644 --- a/lib/cldr/export/data/parent_locales.rb +++ b/lib/cldr/export/data/parent_locales.rb @@ -10,7 +10,7 @@ def initialize super path = File.join(Cldr::Export::Data.dir, "supplemental", "supplementalData.xml") - doc = File.open(path) { |file| Nokogiri::XML(file) } + doc = Cldr::Export::DataFile.parse(File.read(path)) doc.xpath("//parentLocales/parentLocale").each do |node| parent = Cldr::Export.to_i18n(node.attr("parent")) diff --git a/lib/cldr/export/data/plural_rules.rb b/lib/cldr/export/data/plural_rules.rb index 72e623f0..2278aea1 100644 --- a/lib/cldr/export/data/plural_rules.rb +++ b/lib/cldr/export/data/plural_rules.rb @@ -22,9 +22,7 @@ def initialize(locale) def sources @sources ||= ["plurals", "ordinals"].each_with_object({}) do |source_name, ret| - ret[source_name] = ::Nokogiri::XML( - File.read("#{Cldr::Export::Data.dir}/supplemental/#{source_name}.xml") - ) + ret[source_name] = Cldr::Export::DataFile.parse(File.read("#{Cldr::Export::Data.dir}/supplemental/#{source_name}.xml")) end end diff --git a/lib/cldr/export/data/plurals.rb b/lib/cldr/export/data/plurals.rb index 5faac62f..b831fe95 100644 --- a/lib/cldr/export/data/plurals.rb +++ b/lib/cldr/export/data/plurals.rb @@ -15,11 +15,7 @@ class Plurals < Hash class << self def rules - @@rules ||= Rules.parse(source) - end - - def source - File.read("#{Cldr::Export::Data.dir}/supplemental/plurals.xml") + @@rules ||= Rules.parse(File.read("#{Cldr::Export::Data.dir}/supplemental/plurals.xml")) end end diff --git a/lib/cldr/export/data/plurals/rules.rb b/lib/cldr/export/data/plurals/rules.rb index 615e126d..ffe5de52 100644 --- a/lib/cldr/export/data/plurals/rules.rb +++ b/lib/cldr/export/data/plurals/rules.rb @@ -10,7 +10,7 @@ class Plurals class Rules < Array class << self def parse(xml) - doc = Nokogiri.XML(xml) + doc = Cldr::Export::DataFile.parse(xml) rules = new doc.xpath("//pluralRules").each do |node| diff --git a/lib/cldr/export/data/windows_zones.rb b/lib/cldr/export/data/windows_zones.rb index ae7be47a..abbc22ee 100644 --- a/lib/cldr/export/data/windows_zones.rb +++ b/lib/cldr/export/data/windows_zones.rb @@ -11,7 +11,7 @@ def initialize super path = "#{Cldr::Export::Data.dir}/supplemental/windowsZones.xml" - doc = File.open(path) { |file| Nokogiri::XML(file) } + doc = Cldr::Export::DataFile.parse(File.read(path)) doc.xpath("//windowsZones/mapTimezones/mapZone").each_with_object(self) do |node, result| zone = node.attr("other").to_s territory = node.attr("territory") diff --git a/lib/cldr/export/data_file.rb b/lib/cldr/export/data_file.rb new file mode 100644 index 00000000..76128e0f --- /dev/null +++ b/lib/cldr/export/data_file.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require "nokogiri" + +module Cldr + module Export + class DataFile + class << self + def parse(string, minimum_draft_status: nil) + doc = Nokogiri::XML(string) do |config| + config.strict.noblanks + end + DataFile.new(doc, minimum_draft_status: minimum_draft_status) + end + + def filter_by_draft(doc, minimum_draft_status) + doc.traverse do |child| + next unless child.text? + + draft_status = child.parent.attribute("draft").nil? ? Cldr::DraftStatus::APPROVED : Cldr::DraftStatus.fetch(child.parent.attribute("draft")) + if draft_status < minimum_draft_status + ancestors = child.ancestors + child.remove + # Remove the ancestors that are now empty + ancestors.each do |ancestor| + ancestor.remove if ancestor.children.empty? + end + end + end + doc + end + end + + attr_reader :doc, :minimum_draft_status + + def initialize(doc, minimum_draft_status: nil) + @minimum_draft_status = minimum_draft_status || Cldr::Export.minimum_draft_status + @doc = Cldr::Export::DataFile.filter_by_draft(doc, @minimum_draft_status) + end + + def traverse(&block) + @doc.traverse(&block) + end + + def xpath(path) + @doc.xpath(path) + end + + def /(*args) + @doc./(*args) + end + + def locale + language = @doc.xpath("//ldml/identity/language").first&.attribute("type")&.value + territory = @doc.xpath("//ldml/identity/territory").first&.attribute("type")&.value + elements = [language, territory].compact + elements.empty? ? nil : elements.join("-").to_sym + end + + def merge(other) + # Some parts (`ldml`, `ldmlBCP47` amd `supplementalData`) of CLDR data require that you merge all the + # files with the same root element before doing lookups. + # Ref: https://www.unicode.org/reports/tr35/tr35.html#XML_Format + # + # Note that it technically is no longer compliant with the CLDR `ldml.dtd`, since: + # * it has repeated elements + # * the elements no longer refer to the filename + # + # However, this is not an issue, since #xpath will find all of the matches from each of the repeated elements, + # and the elements are not important to us / make no sense when combined together. + raise StandardError, "Cannot merge data file with more permissive draft status" if other.minimum_draft_status < minimum_draft_status + raise StandardError, "Cannot merge data file from different locales" if other.locale != locale + + result = @doc.dup + other.doc.root.children.each do |child| + result.root.add_child(child.dup) + end + + Cldr::Export::DataFile.new(result, minimum_draft_status: minimum_draft_status) + end + end + end +end diff --git a/test/export/data_file_test.rb b/test/export/data_file_test.rb new file mode 100644 index 00000000..b228dfbf --- /dev/null +++ b/test/export/data_file_test.rb @@ -0,0 +1,223 @@ +# frozen_string_literal: true + +require File.join(File.expand_path(File.dirname(__FILE__)), "../test_helper") + +class TestDataFile < Test::Unit::TestCase + def cldr_data + File.read("#{Cldr::Export::Data.dir}/main/de.xml") + end + + def test_merging + first_contents = <<~XML_CONTENTS + + + + + + + + + Q + + in {0} Q + in {0} Q + + + vor {0} Q + vor {0} Q + + + + + XML_CONTENTS + + first_parsed = Cldr::Export::DataFile.parse(first_contents) + + second_contents = <<~XML_CONTENTS + + + + + + + + + + + + Port. + Alt. + Di. + Ges. + + + + + XML_CONTENTS + + second_parsed = Cldr::Export::DataFile.parse(second_contents) + + merged = first_parsed.merge(second_parsed) + + # Inputs are unchanged + assert_equal(first_contents, first_parsed.doc.to_xml) + assert_equal(second_contents, second_parsed.doc.to_xml) + + expected = <<~XML_CONTENTS + + + + + + + + + Q + + in {0} Q + in {0} Q + + + vor {0} Q + vor {0} Q + + + + + + + + + + + + Port. + Alt. + Di. + Ges. + + + + + XML_CONTENTS + + assert_instance_of(Cldr::Export::DataFile, merged) + assert_equal(expected, merged.doc.to_xml) + end + + def test_locale_parsing + xml_contents = <<~XML_CONTENTS + + + + + + + + XML_CONTENTS + + parsed = Cldr::Export::DataFile.parse(xml_contents) + + assert_equal(:de, parsed.locale) + + xml_contents = <<~XML_CONTENTS + + + + + + + + + XML_CONTENTS + + parsed = Cldr::Export::DataFile.parse(xml_contents) + + assert_equal(:"de-CH", parsed.locale) + end + + def test_locale_parsing_returns_nil_when_missing + xml_contents = <<~XML_CONTENTS + + + + + + + XML_CONTENTS + + parsed = Cldr::Export::DataFile.parse(xml_contents) + + assert_nil(parsed.locale) + end +end + +class TestDataFileDraftStatusFilter < Test::Unit::TestCase + def setup; end # We don't want the default behaviour for these. + + def cldr_data + File.read("#{Cldr::Export::Data.dir}/main/de.xml") + end + + def test_filters_file_by_draft_status + unconfirmed_count = pairs(Cldr::Export::DataFile.parse(cldr_data, minimum_draft_status: Cldr::DraftStatus::UNCONFIRMED)).count + provisional_count = pairs(Cldr::Export::DataFile.parse(cldr_data, minimum_draft_status: Cldr::DraftStatus::PROVISIONAL)).count + contributed_count = pairs(Cldr::Export::DataFile.parse(cldr_data, minimum_draft_status: Cldr::DraftStatus::CONTRIBUTED)).count + approved_count = pairs(Cldr::Export::DataFile.parse(cldr_data, minimum_draft_status: Cldr::DraftStatus::APPROVED)).count + + assert(unconfirmed_count >= provisional_count, "Found #{unconfirmed_count} unconfirmed pairs, and #{provisional_count} provisional pairs") + assert(provisional_count >= contributed_count, "Found #{provisional_count} provisional pairs, and #{contributed_count} contributed pairs") + assert(contributed_count >= approved_count, "Found #{contributed_count} contributed pairs, and #{approved_count} approved pairs") + end + + def test_removes_draft_pairs_and_empty_ancestors + xml_contents = <<~XML_CONTENTS + + + + + + + + + letztes Quartal + dieses Quartal + nächstes Quartal + + in {0} Q + in {0} Q + + + vor {0} Q + vor {0} Q + + + + + XML_CONTENTS + + parsed = Cldr::Export::DataFile.parse(xml_contents, minimum_draft_status: Cldr::DraftStatus::APPROVED) + + expected = <<~XML_CONTENTS + + + + + + + + XML_CONTENTS + assert_equal(expected, parsed.doc.to_xml) + end + + private + + def pairs(doc) + return to_enum(:pairs, doc) unless block_given? + + doc.traverse do |node| + next unless node.text? + yield node.path, node.text + end + end +end diff --git a/test/export_test.rb b/test/export_test.rb index e26bca69..7e6a3cc9 100644 --- a/test/export_test.rb +++ b/test/export_test.rb @@ -9,6 +9,7 @@ class TestExport < Test::Unit::TestCase def setup Cldr::Export.base_path = tmp_dir + Cldr::Export.minimum_draft_status = Cldr::DraftStatus::CONTRIBUTED begin FileUtils.mkdir_p(tmp_dir) rescue diff --git a/test/format/date_test.rb b/test/format/date_test.rb index a1e701a6..cbd21797 100644 --- a/test/format/date_test.rb +++ b/test/format/date_test.rb @@ -6,6 +6,7 @@ class TestCldrDateFormat < Test::Unit::TestCase def setup + super @locale = :de @calendar = Cldr::Export::Data::Calendars.new(@locale)[:calendars][:gregorian] end diff --git a/test/format/datetime_test.rb b/test/format/datetime_test.rb index 2ae59b87..4174553c 100644 --- a/test/format/datetime_test.rb +++ b/test/format/datetime_test.rb @@ -6,6 +6,7 @@ class TestCldrDatetimeFormat < Test::Unit::TestCase def setup + super @locale = :de @calendar = Cldr::Export::Data::Calendars.new(@locale)[:calendars][:gregorian] end diff --git a/test/format/time_test.rb b/test/format/time_test.rb index 7ee2e5fb..7c70b05c 100644 --- a/test/format/time_test.rb +++ b/test/format/time_test.rb @@ -6,6 +6,7 @@ class TestCldrTimeFormat < Test::Unit::TestCase def setup + super @locale = :de @calendar = Cldr::Export::Data::Calendars.new(@locale)[:calendars][:gregorian] end diff --git a/test/test_helper.rb b/test/test_helper.rb index b2e880b7..9926c45c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -26,6 +26,10 @@ def self.test(name, &block) end end end + + def setup + Cldr::Export.minimum_draft_status = Cldr::DraftStatus::CONTRIBUTED + end end end end From cd2ba1bf3c09b1e7805056012cf63790dd83147f Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Tue, 19 Apr 2022 10:08:16 -0400 Subject: [PATCH 4/5] Remove `draft?` It is already handled by `DataFile` --- lib/cldr/export/data/base.rb | 7 +------ lib/cldr/export/data/currencies.rb | 12 +++++------- lib/cldr/export/data/languages.rb | 2 +- lib/cldr/export/data/numbers.rb | 4 +--- lib/cldr/export/data/subdivisions.rb | 2 +- lib/cldr/export/data/territories.rb | 2 +- lib/cldr/export/data/units.rb | 2 +- 7 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/cldr/export/data/base.rb b/lib/cldr/export/data/base.rb index 7075baab..58a5de54 100644 --- a/lib/cldr/export/data/base.rb +++ b/lib/cldr/export/data/base.rb @@ -27,12 +27,7 @@ def []=(key, value) protected - def draft?(node) - draft = node.attribute("draft") - draft && draft.value == "unconfirmed" - end - - def alt?(node) + def alt?(node) # TODO: Move this into DataFile !node.attribute("alt").nil? end diff --git a/lib/cldr/export/data/currencies.rb b/lib/cldr/export/data/currencies.rb index cb74a210..ad0ee431 100644 --- a/lib/cldr/export/data/currencies.rb +++ b/lib/cldr/export/data/currencies.rb @@ -20,13 +20,11 @@ def currencies def currency(node) data = select(node, "displayName").each_with_object({}) do |node, result| - unless draft?(node) - if node.attribute("count") - count = node.attribute("count").value.to_sym - result[count] = node.content - else - result[:name] = node.content - end + if node.attribute("count") + count = node.attribute("count").value.to_sym + result[count] = node.content + else + result[:name] = node.content end end diff --git a/lib/cldr/export/data/languages.rb b/lib/cldr/export/data/languages.rb index cec1484a..9c866503 100644 --- a/lib/cldr/export/data/languages.rb +++ b/lib/cldr/export/data/languages.rb @@ -13,7 +13,7 @@ def initialize(locale) def languages @languages ||= select("localeDisplayNames/languages/language").each_with_object({}) do |node, result| - result[Cldr::Export.to_i18n(node.attribute("type").value)] = node.content unless draft?(node) || alt?(node) + result[Cldr::Export.to_i18n(node.attribute("type").value)] = node.content unless alt?(node) end end end diff --git a/lib/cldr/export/data/numbers.rb b/lib/cldr/export/data/numbers.rb index de0ac2c4..a576e025 100644 --- a/lib/cldr/export/data/numbers.rb +++ b/lib/cldr/export/data/numbers.rb @@ -42,7 +42,7 @@ def currency def symbols select("numbers/symbols/*").each_with_object({}) do |node, result| - result[name(node).to_sym] = node.content unless draft?(node) + result[name(node).to_sym] = node.content end end @@ -60,8 +60,6 @@ def format(type) pattern_count_node = pattern_node.attribute("count") - next if draft?(pattern_node) - pattern_key = pattern_key_node ? pattern_key_node.value : :default if pattern_count_node diff --git a/lib/cldr/export/data/subdivisions.rb b/lib/cldr/export/data/subdivisions.rb index 5f8088bf..0fbd693e 100644 --- a/lib/cldr/export/data/subdivisions.rb +++ b/lib/cldr/export/data/subdivisions.rb @@ -13,7 +13,7 @@ def initialize(locale) def subdivisions @subdivisions ||= select("localeDisplayNames/subdivisions/subdivision").each_with_object({}) do |node, result| - result[node.attribute("type").value.to_sym] = node.content unless draft?(node) || alt?(node) + result[node.attribute("type").value.to_sym] = node.content unless alt?(node) end end end diff --git a/lib/cldr/export/data/territories.rb b/lib/cldr/export/data/territories.rb index 8cac48a4..75e3f70c 100644 --- a/lib/cldr/export/data/territories.rb +++ b/lib/cldr/export/data/territories.rb @@ -13,7 +13,7 @@ def initialize(locale) def territories @territories ||= select("localeDisplayNames/territories/territory").each_with_object({}) do |node, result| - result[node.attribute("type").value.to_sym] = node.content unless draft?(node) || alt?(node) + result[node.attribute("type").value.to_sym] = node.content unless alt?(node) end end end diff --git a/lib/cldr/export/data/units.rb b/lib/cldr/export/data/units.rb index 7e4a028d..7d977ecd 100644 --- a/lib/cldr/export/data/units.rb +++ b/lib/cldr/export/data/units.rb @@ -31,7 +31,7 @@ def units(node) def unit(node) node.xpath("unitPattern").each_with_object({}) do |node, result| count = node.attribute("count") ? node.attribute("count").value.to_sym : :one - result[count] = node.content unless draft?(node) + result[count] = node.content end end From 92defe0d29e072ad48fd4d5341008bcaba878864 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Thu, 21 Apr 2022 09:47:37 -0400 Subject: [PATCH 5/5] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e357ce09..572f0977 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Standardize component names for the `thor cldr:export` command (and internally in the codebase), [#121](https://github.com/ruby-i18n/ruby-cldr/pull/121) - Standardize locale names for the `thor cldr:export` command (and internally in the codebase), [#121](https://github.com/ruby-i18n/ruby-cldr/pull/121) - Output `plurals.rb` with the `ruby-cldr` style locale codes (only affects `pt-PT` in CLDR v34), [#121](https://github.com/ruby-i18n/ruby-cldr/pull/121) +- Export data at with a consistent minimum draft status, [#124](https://github.com/ruby-i18n/ruby-cldr/pull/124) +- Add `--draft-status` flag for specifying the minimum draft status for data to be exported, [#124](https://github.com/ruby-i18n/ruby-cldr/pull/124) ---