Sha256: dee6a77152438f34ef34579652dc5893e6b96616d71b974b74aa6002e2362552

Contents?: true

Size: 1.15 KB

Versions: 20

Compression:

Stored size: 1.15 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'nokogiri'

module TwitterCldr
  module Resources

    class ParentLocalesImporter < Importer

      requirement :cldr, Versions.cldr_version
      output_path 'shared'
      ruby_engine :mri

      private

      def execute
        output_file = File.join(output_path, 'parent_locales.yml')
        File.write(output_file, YAML.dump(parent_locales))
      end

      def parent_locales
        @parent_locales ||= supplemental_data.xpath('//parentLocales/parentLocale').each_with_object({}) do |node, ret|
          parent = node.attr('parent')
          locales = node.attr('locales').split(' ')

          locales.each do |locale|
            ret[locale] = parent
          end
        end
      end

      def output_path
        params.fetch(:output_path)
      end

      def supplemental_data
        @supplemental_data ||= Nokogiri.XML(
          File.read(
            File.join(
              requirements[:cldr].common_path,
              'supplemental',
              'supplementalData.xml'
            )
          )
        )
      end

    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
twitter_cldr-6.12.1 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.12.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.11.5 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.11.4 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.11.3 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.11.2 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.11.1 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.11.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.10.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.9.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.8.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.7.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.6.2 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.6.1 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.6.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.5.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.4.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.3.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.2.0 lib/twitter_cldr/resources/parent_locales_importer.rb
twitter_cldr-6.1.0 lib/twitter_cldr/resources/parent_locales_importer.rb