Sha256: 10c67688eeeddb1b39e872b7a4aadc9f2bdffa8f1792766809fb089072be5417

Contents?: true

Size: 667 Bytes

Versions: 54

Compression:

Stored size: 667 Bytes

Contents

module UiBibz::Utils
  class Internationalization

    def initialize translation, options = {}
      @translation = translation
      @options     = options
    end

    def translate
      I18n.t(@translation, options_with_default)
    end

  private

    def options_with_default
      @options[:default] = translate_default unless @options[:default].nil?
      @options
    end

    # To know if translation missing
    def i18n_set? key
      I18n.t key, :raise => true rescue false
    end

    def translate_default
      I18n.t([*@options[:default]].select{ |translation| i18n_set? translation }.first, default: [*@options[:default]].last)
    end

  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
ui_bibz-1.2.3 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.2.2 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.2.1 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.2.0 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.7 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.6 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.5 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.4 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.3 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.2 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.1 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.1.0 lib/ui_bibz/utils/internationalization.rb
ui_bibz-1.0.0 lib/ui_bibz/utils/internationalization.rb
ui_bibz-0.9.0 lib/ui_bibz/utils/internationalization.rb