Sha256: 5631a71f2124096871a0bb9f3238d2121169392af4228a2a4e5ae84b13c6fcbb

Contents?: true

Size: 1.5 KB

Versions: 17

Compression:

Stored size: 1.5 KB

Contents

require "gettext/tools/poparser"
require "gettext/runtime/mofile"

module YARD
  module I18n
    # +Locale+ is a unit of translation. It has {#name} and a set of
    # messages.
    #
    # @since 0.8.2
    class Locale
      # @return [String] the name of the locale. It used IETF language
      #   tag format +[language[_territory][.codeset][@modifier]]+.
      # @see http://tools.ietf.org/rfc/bcp/bcp47.txt
      #   BCP 47 - Tags for Identifying Languages
      attr_reader :name

      # Creates a locale for +name+ locale.
      #
      # @param [String] name the locale name.
      def initialize(name)
        @name = name
        @messages = {}
      end

      # Loads translation messages from +locale_directory+/{#name}.po.
      #
      # @param [String] locale_directory the directory path that has
      #   {#name}.po.
      # @return [Boolean] +true+ if PO file exists, +false+ otherwise.
      def load(locale_directory)
        po_file = File.join(locale_directory, "#{@name}.po")
        return false unless File.exist?(po_file)

        parser = GetText::PoParser.new
        parser.report_warning = false
        data = GetText::MoFile.new
        parser.parse_file(po_file, data)
        @messages.merge!(data)
        true
      end

      # @param [String] message the translation target message.
      # @return [String] translated message. If tarnslation isn't
      #   registered, the +message+ is returned.
      def translate(message)
        @messages[message] || message
      end
    end
  end
end

Version data entries

17 entries across 13 versions & 3 rubygems

Version Path
challah-rolls-0.2.0 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.8.3 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.8.1 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-rolls-0.1.0 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.8.0.pre vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.7.1 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.7.0 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.7.0.pre2 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.7.0.pre vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
challah-0.6.2 vendor/bundle/gems/yard-0.8.2/lib/yard/i18n/locale.rb
challah-0.6.2 vendor/bundle/gems/yard-0.8.2.1/lib/yard/i18n/locale.rb
yard-0.8.2.1 lib/yard/i18n/locale.rb
challah-0.6.1 vendor/bundle/gems/yard-0.8.2/lib/yard/i18n/locale.rb
yard-0.8.2 lib/yard/i18n/locale.rb