I need to dynamically translate 2 strings to Spanish in the following JS, namely "Date" and "Read more" if the html-document's language code is set to Spanish (html lang="es"):
$.each(data,function(post, postInfo) {
jsonArray.push( postEntry + '<a href="' + postInfo.link + '" class="preview-title"><h2>' + postInfo.title + '</h2></a><div class="preview-meta">Date: ' + postInfo.date + '</div><p>' + postInfo.preview + '...</p><div class="read-more"><a href="' + postInfo.link + '" class="link-button">Read more</a></div>' + postFooter);
});
I am unsure how to approach this in the best way.
Getting the language code as a string would probably work with this:
var languageCode = $('html').attr('lang');
And then you could implement a simple check like:
if (languageCode === 'es') {
...
} else {
...
}
Would appreciate your advice how to approach this.