# Class: YARD::I18n::POParser

Inherits:
  Object
  - Object
  - YARD::I18n::POParser
  show all

Defined in:
  lib/yard/i18n/po_parser.rb

## Overview

`Locale` is a wrapper for gettext’s PO parsing feature. It hides gettext API difference from YARD.

Since:

- 0.8.8

## Class Method Summary collapse

- .available? ⇒ Boolean

  True if gettext is available, false otherwise.

## Instance Method Summary collapse

- #parse(file) ⇒ Hash<String, String>

  Parses PO file.

## Class Method Details

### .available? ⇒ `Boolean`

Returns true if gettext is available, false otherwise.

Returns:

- (`Boolean`) —

  true if gettext is available, false otherwise.

Since:

- 0.8.8

    37
    38
    39

    # File 'lib/yard/i18n/po_parser.rb', line 37

    def available?
      !@@gettext_version.nil?
    end

## Instance Method Details

### #parse(file) ⇒ `Hash<String, String>`

Parses PO file.

Parameters:

- file (`String`) —

  path of PO file to be parsed.

Returns:

- (`Hash<String, String>`) —

  parsed messages.

Since:

- 0.8.8

    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58

    # File 'lib/yard/i18n/po_parser.rb', line 46

    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