Sha256: 409603984396679a9c7cebdcd2a58b191525a34baea4f3eeea7ec551a5f3a30a

Contents?: true

Size: 1.2 KB

Versions: 30

Compression:

Stored size: 1.2 KB

Contents

module Stringex
  module Localization
    module Backend
      class Internal < Base
        DEFAULT_LOCALE = :en

        class << self
          def locale
            @locale || default_locale
          end

          def locale=(new_locale)
            @locale = new_locale.to_sym
          end

          def default_locale
            @default_locale || DEFAULT_LOCALE
          end

          def default_locale=(new_locale)
            @default_locale = @locale = new_locale.to_sym
          end

          def with_locale(new_locale, &block)
            original_locale = locale
            self.locale = new_locale
            yield
            self.locale = original_locale
          end

          def translations
            # Set up hash like translations[:en][:transliterations]["é"]
            @translations ||= Hash.new { |k, v| k[v] = Hash.new({}) }
          end

          def store_translations(locale, scope, data)
            self.translations[locale.to_sym][scope.to_sym] = Hash[data.map { |k, v| [k.to_sym, v] }] # Symbolize keys
          end

          def initial_translation(scope, key, locale)
            translations[locale][scope][key.to_sym]
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
stringex-2.8.6 lib/stringex/localization/backend/internal.rb
stringex-2.8.5 lib/stringex/localization/backend/internal.rb
stringex-2.8.4 lib/stringex/localization/backend/internal.rb
stringex-2.8.3 lib/stringex/localization/backend/internal.rb
stringex-2.8.2 lib/stringex/localization/backend/internal.rb
stringex-2.8.1 lib/stringex/localization/backend/internal.rb
stringex-2.7.1 lib/stringex/localization/backend/internal.rb
stringex-2.7.0 lib/stringex/localization/backend/internal.rb
stringex-2.6.1 lib/stringex/localization/backend/internal.rb
stringex-2.6.0 lib/stringex/localization/backend/internal.rb
stringex-2.5.2 lib/stringex/localization/backend/internal.rb
stringex-2.5.1 lib/stringex/localization/backend/internal.rb
stringex-2.5.0 lib/stringex/localization/backend/internal.rb
stringex-2.4.2 lib/stringex/localization/backend/internal.rb
stringex-2.4.1 lib/stringex/localization/backend/internal.rb
stringex-2.3.0 lib/stringex/localization/backend/internal.rb
stringex-2.2.2 lib/stringex/localization/backend/internal.rb
stringex-2.2.1 lib/stringex/localization/backend/internal.rb
stringex-2.2.0 lib/stringex/localization/backend/internal.rb
stringex-2.1.2 lib/stringex/localization/backend/internal.rb