Skip to content

Instantly share code, notes, and snippets.

@vdwijngaert
Created July 6, 2015 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdwijngaert/f4fbda7dd930a8888bdf to your computer and use it in GitHub Desktop.
Save vdwijngaert/f4fbda7dd930a8888bdf to your computer and use it in GitHub Desktop.
Export WPML String translations
var $ = jQuery,
strings = [];
$("#icl_string_translations").find(">tbody>tr").each(function() {
var $tr = $(this),
$tds = $tr.find("td"),
trans = {};
trans.context = $tds.get(1).innerText;
var $translationCell = $($tds.get(4));
trans.text = $translationCell.find(".icl-st-original").text();
trans.translations = [];
var $translations = $translationCell.find(".icl_st_form");
$translations.each(function() {
var translation = {},
$translation = $(this);
console.log($translation);
translation.language = $translation.find('input[name="icl_st_language"]').val();
translation.text = $translation.find('textarea[name="icl_st_translation"]').val();
trans.translations.push(translation);
});
strings.push(trans);
});
var $overlay = $("<div>").css({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
background: 'white',
color: 'black',
padding: '50',
boxSizing: 'border-box',
zIndex: 5000000,
overflow: 'scroll'
});
var $table = $("<table>").css({
width: '100%',
});
$.each(strings, function() {
var $tr = $("<tr>");
$tr.append('<td>' + this.text + '</td>');
var $transtext = $("<td>");
$.each(this.translations, function() {
$transtext.append($('<strong>').text(this.language + ': ')).append($('<span></span>').text(this.text)).append($('<br>'));
});
$tr.append($transtext);
$tr.appendTo($table);
});
$overlay.append('<h2>' + strings[0].context + '</h2>');
$overlay.append($table).appendTo($('body'));
console.log(JSON.stringify(strings));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment