Sha256: 8e39c5fce7450e5cd462ea55b6392d0e5cea301e41cfb182aaf5ec446f811aaa

Contents?: true

Size: 954 Bytes

Versions: 39

Compression:

Stored size: 954 Bytes

Contents

#= require alchemy/alchemy.translations

window.Alchemy = {} if typeof(window.Alchemy) is 'undefined'

Alchemy.I18n =

  KEY_SEPARATOR: /\./

  # Translates given string
  #
  translate: (key, replacement) ->
    if !Alchemy.locale?
      throw 'Alchemy.locale is not set! Please set Alchemy.locale to a locale string in order to translate something.'
    translations = Alchemy.translations[Alchemy.locale]
    if translations
      if @KEY_SEPARATOR.test(key)
        keys = key.split(@KEY_SEPARATOR)
        translation = translations[keys[0]][keys[1]] || key
      else
        translation = translations[key] || key
      if replacement
        translation.replace(/%\{.+\}/, replacement)
      else
        translation
    else
      Alchemy.debug "Translations for locale #{Alchemy.locale} not found!"
      key

# Global utility method for translating a given string
#
Alchemy.t = (key, replacement) ->
  Alchemy.I18n.translate(key, replacement)

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
alchemy_cms-4.0.6 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-3.6.7 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-3.6.6 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.3.2 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.2.4 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.3.1 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.2.3 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.3.0 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.2.2 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.1.2 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.1.1 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.2.1 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.2.0 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.2.0.rc1 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.1.0 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.0.5 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.0.4 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.1.0.rc1 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-4.0.3 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee
alchemy_cms-3.6.5 app/assets/javascripts/alchemy/alchemy.i18n.js.coffee