Sha256: be3f8932d7c45f57d513b4ca572447f7f9c6b74ee026c3db3690aa43493dfc07

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

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

      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(*msgids)
        current_translations.plural(*msgids)
      end

      protected

      def current_translations
        MoFile.empty
      end

      def find_files_in_locale_folders(relative_file_path,path)
        path ||= "locale"
        raise "path #{path} cound 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)
          next unless File.exist? file
          locale = File.basename(locale_folder)
          @files[locale] = yield(locale,file)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
grosser-fast_gettext-0.4.0 lib/fast_gettext/translation_repository/base.rb
grosser-fast_gettext-0.4.2 lib/fast_gettext/translation_repository/base.rb
grosser-fast_gettext-0.4.3 lib/fast_gettext/translation_repository/base.rb
grosser-fast_gettext-0.4.4 lib/fast_gettext/translation_repository/base.rb
grosser-fast_gettext-0.4.5 lib/fast_gettext/translation_repository/base.rb
grosser-fast_gettext-0.4.7 lib/fast_gettext/translation_repository/base.rb
grosser-fast_gettext-0.4.8 lib/fast_gettext/translation_repository/base.rb