Sha256: 9396d4747a5c239545a403db7470562f9189d0da16a94da4327b2fa115f41dbd

Contents?: true

Size: 1.63 KB

Versions: 63

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
module YARD
  module I18n
    # +Locale+ is a wrapper for gettext's PO parsing feature. It hides
    # gettext API difference from YARD.
    #
    # @since 0.8.8
    class POParser
      if RUBY_VERSION < "1.9"
        begin
          require "gettext/tools/poparser"
          require "gettext/runtime/mofile"
          @@gettext_version = 2
        rescue LoadError
          log.warn "Need gettext gem 2.x for i18n feature:\n" \
                   "\tgem install gettext -v 2.3.9"
        end
      else
        begin
          require "gettext/po_parser"
          require "gettext/mo"
          @@gettext_version = 3
        rescue LoadError
          begin
            require "gettext/tools/poparser"
            require "gettext/runtime/mofile"
            @@gettext_version = 2
          rescue LoadError
            log.warn "Need gettext gem for i18n feature:\n" \
                     "\tgem install gettext"
          end
        end
      end

      class << self
        # @return [Boolean] true if gettext is available, false otherwise.
        def available?
          !@@gettext_version.nil?
        end
      end

      # Parses PO file.
      #
      # @param [String] file path of PO file to be parsed.
      # @return [Hash<String, String>] parsed messages.
      def parse(file)
        case @@gettext_version
        when 2
          parser = GetText::PoParser.new
          data = GetText::MoFile.new
        when 3
          parser = GetText::POParser.new
          data = GetText::MO.new
        end
        parser.report_warning = false
        parser.parse_file(file, data)
        data
      end
    end
  end
end

Version data entries

63 entries across 62 versions & 9 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/lib/yard/i18n/po_parser.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
yard-0.9.37 lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.25 gems/yard-0.9.25/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.24 gems/yard-0.9.25/lib/yard/i18n/po_parser.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
yard-0.9.36 lib/yard/i18n/po_parser.rb
yard-0.9.35 lib/yard/i18n/po_parser.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.23 gems/yard-0.9.25/lib/yard/i18n/po_parser.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.22 gems/yard-0.9.25/lib/yard/i18n/po_parser.rb
kinetic_sdk-5.0.21 gems/yard-0.9.25/lib/yard/i18n/po_parser.rb
yard-0.9.34 lib/yard/i18n/po_parser.rb