Module: Hexx::Services::TranslationDSL

Included in:
Base
Defined in:
lib/hexx-services/translation_dsl.rb

Overview

The module provides features to do translations in the current service’s scope

Examples:

class MyService
  include TranslationDSL
end

service = MyService.new
service.translate :foo
# => "translation missing: en.services.my_service.foo"

Instance Method Summary collapse

Instance Method Details

#translate(name, options) ⇒ String #translate(name, *) ⇒ String

Translates a name in the scope of the current service

Overloads:

  • #translate(name, options) ⇒ String

    Translates a symbolic argument with given options

    Parameters:

    • name (Symbol)
    • options (Hash)

    Returns:

    • (String)
  • #translate(name, *) ⇒ String

    Stringifies non-symbolic argument

    Parameters:

    • name (#to_s)

    Returns:

    • (String)


38
39
40
41
# File 'lib/hexx-services/translation_dsl.rb', line 38

def translate(name, **options)
  return name.to_s unless name.instance_of? Symbol
  I18n.t name, options.merge(scope: [:services, self.class.pathname.to_sym])
end