Sha256: 46bbfd5c2be1909ac081bd4f1322d281c8f67b3f3f00574725fbe81578a45775

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module FastGettext
  module TranslationRepository
    # Responsibility:
    #  - base for all repositories
    #  - fallback as empty repository, that cannot translate anything but does not crash
    class Base
      attr_reader :name, :options

      def initialize(name, options = {})
        @name = name
        @options = options
      end

      def pluralisation_rule
        nil
      end

      def available_locales
        []
      end

      def [](key)
        current_translations[key]
      end

      def plural(*keys)
        current_translations.plural(*keys)
      end

      def reload
        true
      end

      protected

      def current_translations
        MoFile.empty
      end

      def find_files_in_locale_folders(relative_file_path, path)
        path ||= "locale"
        raise "path #{path} could not be found!" unless File.exist?(path)

        @files = {}
        Dir[File.join(path, '*')].each do |locale_folder|
          next unless File.basename(locale_folder) =~ LOCALE_REX

          file = File.join(locale_folder, relative_file_path).untaint
          next unless File.exist? file

          locale = File.basename(locale_folder)
          @files[locale] = yield(locale, file)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fast_gettext-2.0.3 lib/fast_gettext/translation_repository/base.rb
fast_gettext-2.0.2 lib/fast_gettext/translation_repository/base.rb
fast_gettext-2.0.1 lib/fast_gettext/translation_repository/base.rb
fast_gettext-2.0.0 lib/fast_gettext/translation_repository/base.rb