Sha256: bec3409dd5a2f76023afbb1c46af2a4bdda702b9c781a4e613cfbdcf79bd976f

Contents?: true

Size: 1.31 KB

Versions: 69

Compression:

Stored size: 1.31 KB

Contents

// This library provide a helper to recover current translation
// Note: To use this you will need load js translations like this:
// <script> var I18n_data = <%= I18n.backend.send(:translations)[current_locale.to_sym][:admin][:js].to_json.html_safe %> </script>

// return translation of a key
// sample: I18n('button.edit', 'Editar %{title}', {title: 'Articulo'})  ==> Edit
// return String with the translation
// default_val: (String) this value is returned if there is no exist translation for key
// if default_val is empty, will be returned the last key titleized
// data: (hash) replacement values in the value, sample: {title: 'my title'}
var I18n = function(key, default_val, data){
    var res = '';
    try { res = eval("I18n_data." + key); }catch(e){}
    if (!res) res = default_val ? default_val : ("" + key.split(".").pop()).titleize();

    // replacements
    data = data || {}
    for(key in data){
        res = res.replace("%{"+key+"}", data[key])
    }
    return res;
}

// helper to convert not found translations key into titleized string
String.prototype.titleize = function() {
    var words = this.replace(/_/g, " ").split(' ')
    var array = []
    for (var i=0; i<words.length; ++i) {
        array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
    }
    return array.join(' ')
}

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
camaleon_cms-2.9.0 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.8.3 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.8.2 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.8.1 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.8.0 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.7.5 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.7.4 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.7.3 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.7.2 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.7.1 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.7.0 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.6.4 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.6.3 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.6.2 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.6.1 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.6.0.1 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.6.0 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.5.3.1 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.5.3 app/assets/javascripts/camaleon_cms/admin/_i18n.js
camaleon_cms-2.5.2 app/assets/javascripts/camaleon_cms/admin/_i18n.js