Sha256: dbb0f4cce2c7b937928d67bbe77d4e01a8d2a0d59a3ad0a5585ecd16adf5fbae

Contents?: true

Size: 1.8 KB

Versions: 20

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true
module YARD
  module I18n
    # +Locale+ is a unit of translation. It has {#name} and a set of
    # messages.
    #
    # @since 0.8.2
    class Locale
      class << self
        # @return [String, nil] the default locale name.
        # @since 0.8.4
        attr_accessor :default

        undef default
        def default
          @@default ||= nil
        end

        undef default=
        def default=(locale)
          @@default = locale
        end
      end

      # @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)
        return false if @name.nil?

        po_file = File.join(locale_directory, "#{@name}.po")
        return false unless File.exist?(po_file)

        require "yard/i18n/po_parser"
        return false unless POParser.available?

        po_parser = POParser.new
        @messages.merge!(po_parser.parse(po_file))

        true
      end

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

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/lib/yard/i18n/locale.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/lib/yard/i18n/locale.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
yard-0.9.37 lib/yard/i18n/locale.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/lib/yard/i18n/locale.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/lib/yard/i18n/locale.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
yard-0.9.36 lib/yard/i18n/locale.rb
yard-0.9.35 lib/yard/i18n/locale.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/locale.rb
yard-0.9.34 lib/yard/i18n/locale.rb
yard-0.9.33 lib/yard/i18n/locale.rb
yard-0.9.32 lib/yard/i18n/locale.rb
yard-0.9.31 lib/yard/i18n/locale.rb
yard-0.9.30 lib/yard/i18n/locale.rb
yard-0.9.29 lib/yard/i18n/locale.rb