Sha256: 342ed537e83cc0be2e8ceffc2799dfdd0051ac8b0a1120c038bb8406928789d2

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 Bytes

Contents

# enrich elements with i18n attributes, classes
$.fn.enrichWithI18nData = () ->
  i18n_keys = I18nViz.extractI18nKeysFromText $(this).text()
  if i18n_keys != null
    $(this)
      .addClass("i18n-viz")
      .data("i18n-keys", i18n_keys)
  $(this)

# clear i18n data from element text
$.fn.clearI18nText = () ->
  $(this).textNodes().each () ->
    $(this).replaceWith $(this).text().replace(I18nViz.global_regex, "")
  $(this)

# extract i18n keys from a textnode (e.g. "translated text--en.translation.key--")
I18nViz.extractI18nKeysFromText = (text) ->
  keys = text.match(I18nViz.global_regex)
  if keys
    keys.forEach (value, index) -> keys[index] = value.replace(/--/g, "")
    keys
  else
    null

# custom :i18n selectors
$.extend $.expr[':'], {
  'i18n-textnode': (el) ->
    I18nViz.regex.test $(el).textNodes().text()
  ,
  'i18n-value-placeholder': (el) ->
    (I18nViz.regex.test($(el).val()) || I18nViz.regex.test($(el).attr('placeholder')))
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i18n_viz-0.3.0 app/assets/javascripts/i18n_viz/processing.js.coffee