From 8a206e1e9644f7c1b026e7227e1c1f11975749e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9A=D0=B0=D0=BB=D0=B8=D0=BD=D0=B8=D0=BD?= Date: Fri, 27 Feb 2015 14:06:30 +0300 Subject: [PATCH] Appended the checks of existing of translated attributes --- dist/lang/translator.js | 45 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/dist/lang/translator.js b/dist/lang/translator.js index 043a8060..aa1e94c5 100644 --- a/dist/lang/translator.js +++ b/dist/lang/translator.js @@ -8,7 +8,7 @@ * If you wish to translate some new texsts you should do two things: * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. * 2. Mark that text it templates this way New Phrase or . - * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate. + * The main thing here is attribute data-sw-translate. Only inner text, title-attribute and value-attribute are going to translate. * */ SwaggerTranslator = { @@ -16,29 +16,38 @@ SwaggerTranslator = { _words:[], translate: function() { - var $this = this; - $("[data-sw-translate]").each( - function() { - $(this).html( - $this._tryTranslate($(this).html()) - ); - $(this).val( - $this._tryTranslate($(this).val()) - ); - $(this).attr( - 'title', - $this._tryTranslate($(this).attr('title')) - ); - } - ) + var $this = this; + $("[data-sw-translate]").each( + function() { + if ($(this).text() && $(this).children().length == 0) { + $(this).text( + $this._tryTranslate($(this).text()) + ); + } + + if ($(this).val()) { + $(this).val( + $this._tryTranslate($(this).val()) + ); + } + + + if ($(this).attr('title')) { + $(this).attr( + 'title', + $this._tryTranslate($(this).attr('title')) + ); + } + } + ) }, _tryTranslate: function(word) { - return this._words[word] != undefined ? this._words[word] : word; + return this._words[word] != undefined ? this._words[word] : word; }, learn: function(wordsMap) { - this._words = wordsMap; + this._words = wordsMap; } }