From 2cee519d1c3645b165898789f9f09fc37627e173 Mon Sep 17 00:00:00 2001 From: Andreas Kotowicz Date: Mon, 21 Nov 2011 19:15:43 +0100 Subject: [PATCH] translate code changes: - change js code, so that 'click' and not 'change' will trigger the translation. - do not assume that English is the source language - the comments might be in a different language. --- helpdesk/templates/helpdesk/base.html | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/helpdesk/templates/helpdesk/base.html b/helpdesk/templates/helpdesk/base.html index 38de46ea..3c550a2c 100644 --- a/helpdesk/templates/helpdesk/base.html +++ b/helpdesk/templates/helpdesk/base.html @@ -29,7 +29,7 @@ $.translate(function(){ //when the Google Language API is loaded $.translate().ui({ tags: ["select", "option"], - //a function that filters the languages: + // a function that filters the languages: {% if helpdesk_settings.HELPDESK_TRANSLATE_TICKET_COMMENTS_LANG %} filter: {{ helpdesk_settings.HELPDESK_TRANSLATE_TICKET_COMMENTS_LANG|safe }}, {% else %} @@ -41,24 +41,23 @@ function(langCode, lang){ return $.translate.capitalize(lang); }, - //whether to include the UNKNOWN:"" along with the languages: + // whether to include the UNKNOWN:"" along with the languages: includeUnknown: false, }) - .change(function(){ - $('#translate_block').translate( 'en', { //revert to english first - not: 'select, pre' - }) - - .translate( 'en', $(this).val(), { - not: 'select, pre', - async: true, - toggle: true, - walk: false - }); + .click(function(){ // when selecting a language - 'change' is not enough, because your first language in the menu might be your target language + $('#translate_block').translate( '', $(this).val(), { // translate from current language to the selected language + not: '.option, select, pre, .translate_dropdown', // exclude these elements + fromOriginal: true, // always translate from original version (even after the page has been translated) + async: true, // this prevents the browser from freezing on larger sites by executing each DOM filtering iteration with a delay + toggle: true, // all translation will be cached (stored with $.data) and used if it's found, or translated to otherwise + walk: true // finds elements having textnodes and translates only their content; on very large and complex pages this might take some time + }) }) - .val('English') //select English as default - .appendTo('#translate_dropdown'); //insert the dropdown to the page + .appendTo('#translate_dropdown'); // insert the dropdown menu to the page + + //insert Google's logo after the dropdown: + $.translate.getBranding().appendTo('#translate_dropdown'); }); {% endif %}