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-2.0.0.beta2.6 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.beta2.5 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.beta2.4 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.beta2.3 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.beta2.2 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha32 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha31 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha30 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha29 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha28 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha27 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha26 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha24 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha23 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha22 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha21 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha20 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha19 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha18 lib/ui_bibz/utils/internationalization.rb
ui_bibz-2.0.0.alpha16 lib/ui_bibz/utils/internationalization.rb