Module: Hanami::Extensions::Action::I18nHelper

Includes:
Helpers::I18nHelper::Methods
Defined in:
lib/hanami/extensions/action/i18n_helper.rb

Overview

Action translation and localization helpers.

These helpers are automatically available on Hanami::Action when the i18n gem is bundled.

When relative translation keys (with a leading dot) are given, they are expanded against a the action's name. For example, t(".not_found") within Main::Actions::Posts::Show becomes "posts.show.not_found".

Examples:

Basic translation in an action

module Main
  module Actions
    module Posts
      class Create < Main::Action
        def handle(req, res)
          res.flash[:notice] = t("messages.post_created")
          res.redirect_to routes.path(:posts)
        end
      end
    end
  end
end

Relative key lookup

# In Main::Actions::Posts::Show, this looks up "posts.show.not_found"
t(".not_found")

See Also:

Since:

  • 3.0.0

Constant Summary

Constants included from Helpers::I18nHelper::Methods

Helpers::I18nHelper::Methods::HTML_SAFE_TRANSLATION_KEY

Method Summary

Methods included from Helpers::I18nHelper::Methods

#localize, #translate, #translate!