Module: I18n

Defined in:
common/aspace_i18n_enumeration_support.rb,
backend/app/lib/aspace_i18n.rb

Overview

Define a new :t_raw method that knows how to handle ArchivesSpace-specific enumeration translations.

Called by both the ArchivesSpace backend and frontend, so avoid any Rails-isms here.

Class Method Summary (collapse)

Class Method Details

+ (Object) t(*args)



15
16
17
# File 'backend/app/lib/aspace_i18n.rb', line 15

def self.t(*args)
  self.t_raw(*args)
end

+ (Object) t_raw(*args)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'common/aspace_i18n_enumeration_support.rb', line 9

def self.t_raw(*args)
  key = args[0]
  default = if args[1].is_a?(String)
              args[1]
            else
              (args[1] || {}).fetch(:default, "")
            end

  # String
  if key && key.kind_of?(String) && key.end_with?(".")
    return default
  end

  # Hash / Enumeration Value
  if key && key.kind_of?(Hash) && key.has_key?(:enumeration)
    backend  = config.backend
    locale   = config.locale
    # Null character to cope with enumeration values containing dots.  Eugh.
    translation = backend.send(:lookup, locale, ['enumerations', key[:enumeration], key[:value]].join("\0"), [], {:separator => "\0"}) || default

    if translation && !translation.empty?
      return translation
    end
  end


  self.translate(*args)
end