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
qiita_org-0.1.25 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/i18n/po_parser.rb
yard-0.9.25 lib/yard/i18n/po_parser.rb
yard-0.9.24 lib/yard/i18n/po_parser.rb
yard-0.9.23 lib/yard/i18n/po_parser.rb
yard-0.9.22 lib/yard/i18n/po_parser.rb
yard-0.9.21 lib/yard/i18n/po_parser.rb
yard-0.9.20 lib/yard/i18n/po_parser.rb
yard-0.9.19 lib/yard/i18n/po_parser.rb
yard-0.9.16 lib/yard/i18n/po_parser.rb
yard-0.9.15 lib/yard/i18n/po_parser.rb
yard-0.9.14 lib/yard/i18n/po_parser.rb
yard-0.9.13 lib/yard/i18n/po_parser.rb
yard-0.9.12 lib/yard/i18n/po_parser.rb
yard-0.9.11 lib/yard/i18n/po_parser.rb
yard-0.9.10 lib/yard/i18n/po_parser.rb
yard-0.9.9 lib/yard/i18n/po_parser.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/lib/yard/i18n/po_parser.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/lib/yard/i18n/po_parser.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/lib/yard/i18n/po_parser.rb
yard-0.9.8 lib/yard/i18n/po_parser.rb