Skip to content

Commit

Permalink
feat: export locale_display_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
aergonaut committed Dec 5, 2024
1 parent 5c5b2c7 commit 992db38
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cldr/export/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Data
autoload :Layout, "cldr/export/data/layout"
autoload :LikelySubtags, "cldr/export/data/likely_subtags"
autoload :Lists, "cldr/export/data/lists"
autoload :LocaleDisplayPattern, "cldr/export/data/locale_display_pattern"
autoload :Metazones, "cldr/export/data/metazones"
autoload :NumberingSystems, "cldr/export/data/numbering_systems"
autoload :Numbers, "cldr/export/data/numbers"
Expand Down
22 changes: 22 additions & 0 deletions lib/cldr/export/data/locale_display_pattern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Cldr
module Export
module Data
class LocaleDisplayPattern < Base
def initialize(locale)
super
update(locale_display_pattern: locale_display_pattern)
end

private

def locale_display_pattern
@locale_display_pattern ||= select("localeDisplayNames/localeDisplayPattern/*").each_with_object({}) do |node, result|
result[node.name.underscore] = node.content
end
end
end
end
end
end
18 changes: 18 additions & 0 deletions test/export/data/locale_display_pattern_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8
# frozen_string_literal: true

require File.expand_path(File.join(File.dirname(__FILE__) + "/../../test_helper"))

class TestLocaleDisplayPattern < Test::Unit::TestCase
test "locale_display_pattern :de" do
expected = {
"locale_key_type_pattern" => "{0}: {1}",
"locale_pattern" => "{0} ({1})",
"locale_separator" => "{0}, {1}",
}

actual = Cldr::Export::Data::LocaleDisplayPattern.new(:de)[:locale_display_pattern]

assert_equal expected, actual
end
end

0 comments on commit 992db38

Please sign in to comment.