Sha256: 8af1ac0ee089758dbde083096e36c34e1d9e4cefe87bf0e9e1ca4a73d92bf74a

Contents?: true

Size: 1.26 KB

Versions: 21

Compression:

Stored size: 1.26 KB

Contents

class _i18n
  locale: "en"

  setDefaultLocale: ( _locale ) ->
    debug 'Configuring Language: ' + _locale
    @locale = _locale

  getText: ( _string, _locale = "" ) ->
    _locale = @locale if _locale == ""
    parts = _string.split('.')
    _translated_text = null
    unless AVAILABLE_LOCALES[ _locale ]
      debug "ERROR.I18N.TRANSLATE_TABLE.LOCALE_NOT_EXISTS " + _locale
      return "ERROR.I18N.TRANSLATE_TABLE.LOCALE_NOT_EXISTS"
    currentSegment = AVAILABLE_LOCALES[ _locale ]
    while parts.length
      _next = parts.shift()
      unless currentSegment[ _next ]
        debug "ERROR.I18N.TRANSLATE_TABLE.INVALID_SEGMENT " + _next
        return "ERROR.I18N.TRANSLATE_TABLE.INVALID_SEGMENT"
      currentSegment = currentSegment[ _next ]
    if typeof currentSegment != "string"
      debug "ERROR.I18N.TRANSLATE_TABLE.SEGMENT_NOT_TEXT"
      return "ERROR.I18N.TRANSLATE_TABLE.SEGMENT_NOT_TEXT"
    currentSegment

  pluralizeIf: ( _qty, _singular, _plural, _locale = "" ) ->
    return @getText( _singular, _locale ) if _qty == 1
    @getText( _plural, _locale )

@i18n = new _i18n
@_t = _.bind( @i18n.getText, @i18n )
@_p = _.bind( @i18n.pluralizeIf, @i18n )

# $ ->
#  saved_locale = $.cookie( 'default_locale' )
#  i18n.setDefaultLocale( saved_locale ) if saved_locale

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
iugu-ux-1.0.0 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.9 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.8 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.5 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.4 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.3 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.2 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.1 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.9.0 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.8.9 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.8.8 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.8.7 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.8.6 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.8.5 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.8.0 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.7.1 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.7.0 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.6.7 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.6.6 vendor/assets/javascripts/web-app/i18n.coffee
iugu-ux-0.6.5 vendor/assets/javascripts/web-app/i18n.coffee