class TwitterCldr::Resources::ListFormatsImporter
Private Instance Methods
execute()
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 23 def execute locales = Set.new finish = -> (locale, *) do locales.add(locale) STDOUT.write "\rImported #{locale}, #{locales.size} of #{params[:locales].size} total" end Parallel.each(params[:locales], in_processes: Etc.nprocessors, finish: finish) do |locale| import_locale(locale) locales << locale end puts end
import_locale(locale)
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 39 def import_locale(locale) # The merging that happens here works at the listPatternPart level of granularity. # In other words, a missing part will be filled in by any part with the same key # in the locale's ancestor chain. The raw CLDR data contains the inheritance marker # (i.e. "↑↑↑") for listPatterns that are missing parts, but the expanded data we # get in the downloadable CLDR zip file doesn't include them or the inherited data, # making it impossible for TwitterCLDR to know how it should handle missing keys. # I believe whatever massage tool the CLDR maintainers use to generate the final # data set doesn't take aliases into account, which explains the holes in the data. # By allowing individual listPatternParts to be populated by data from ancestor # locales, we fill in any missing parts at the minor risk of being slightly wrong # when formatting lists. In my opinion, it's far better to produce a slightly wrong # string than to error or produce an entirely empty string. data = requirements[:cldr].merge_each_ancestor(locale) do |ancestor_locale| ListFormats.new(ancestor_locale, requirements[:cldr]).to_h end output_file = File.join(output_path, locale.to_s, 'lists.yml') File.open(output_file, 'w:utf-8') do |output| output.write( TwitterCldr::Utils::YAML.dump( TwitterCldr::Utils.deep_symbolize_keys(locale => data), use_natural_symbols: true ) ) end end
output_path()
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 68 def output_path params.fetch(:output_path) end