Skip to content

Commit

Permalink
updated multilingual to use new google translate api (incl api key us…
Browse files Browse the repository at this point in the history
…age)
  • Loading branch information
Semias committed Jul 10, 2012
1 parent d65625f commit 911f752
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 26 deletions.
10 changes: 6 additions & 4 deletions inc/app/multilingual/boxes/translation/strings/index.php
Expand Up @@ -95,12 +95,14 @@

page_title (intl_get ('Editing Language') . ': ' . $langs[$cgi->lang]['name']);

//page_add_script (site_prefix () . '/js/jquery-1.3.2.min.js');
page_add_script (site_prefix () . '/js/jquery.translate-1.2.6.min.js');
$settings = ini_parse ('inc/app/multilingual/conf/settings.ini.php');
if(!empty($settings['translate_key']['value']) && !empty($settings['enable_translate_key']['value']))
$parameters['apikey'] = $settings['translate_key']['value'];
else
$parameters['apikey'] = '';
page_add_script (site_prefix () . '/js/jquery.translate-1.4.7.min.js');

template_simple_register ('show', $show);
echo template_simple ('translation_strings.spt', $parameters);

//info ($show, true);

?>
30 changes: 30 additions & 0 deletions inc/app/multilingual/conf/settings.ini.php
@@ -0,0 +1,30 @@
; <?php /* DO NOT ALTER THIS LINE, IT IS HERE FOR SECURITY REASONS
;
; WARNING: This file was automatically generated, and it may
; not be wise to edit it by hand. If there is an interface
; to modify files of this type, please use that interface
; instead of manually editing this file. If you are not sure
; or are not aware of such an interface, please talk to your
; Sitellite administrator first.
;
[enable_translate_key]
alt = Enable Google Translation Api Key
type = select
setValues = "eval: array ('1' => 'Yes', '' => 'No')"
value = On
[translate_key]
alt = Google Translation Api Key
value = AIzaSyAAzNFQBo_LLntdkt6Oh3b27xKPECqhVR8
;
; THE END
;
; DO NOT ALTER THIS LINE, IT IS HERE FOR SECURITY REASONS */ ?>
54 changes: 32 additions & 22 deletions inc/app/multilingual/html/translation_strings.spt
@@ -1,5 +1,9 @@
{alt #fff #eee}

{if empty (obj[apikey])}
<div style="float: right">
{intl translate is not enabled}. <a href="http://bvs.semiaslab.nl/usradm-applications-edit-action?appname=multilingual">{intl Add and enable your Google Api Key}</a> {intl to enable translations}
</div>
{end if}
<form method="post" action="{site/prefix}/index/multilingual-translation-strings-action">

<p>
Expand All @@ -23,17 +27,17 @@
<td valign="top" class="field">
{if strlen (loop[_key]) ge 80}
<textarea name="values[{loop/_index}]" id="trv-{loop/_index}" style="width: 100%" rows="4">{if loop[current] ne null}{loop/current}{end if}</textarea><br />
{intl Google Translation}: <span id="tr-{loop/_index}">{intl loading...}</span>
{if empty(loop[current])}{if not empty (obj[apikey])}{intl Translation}: <span id="tr-{loop/_index}">{intl loading...}</span>{end if}{end if}
<a id="tru-{loop/_index}" style="display: none" href="#" onclick="$('#trv-{loop/_index}').attr ('value', $('#tr-{loop/_index}').html ()); return false">{intl Use this!}</a>
{end if}
{if strlen (loop[_key]) ge 40 and strlen (loop[_key]) lt 80}
<textarea name="values[{loop/_index}]" id="trv-{loop/_index}" style="width: 100%" rows="2">{if loop[current] ne null}{loop/current}{end if}</textarea><br />
{intl Google Translation}: <span id="tr-{loop/_index}">{intl loading...}</span>
{if empty(loop[current])}{if not empty (obj[apikey])}{intl Translation}: <span id="tr-{loop/_index}">{intl loading...}</span>{end if}{end if}
<a id="tru-{loop/_index}" style="display: none" href="#" onclick="$('#trv-{loop/_index}').attr ('value', $('#tr-{loop/_index}').html ()); return false">{intl Use this!}</a>
{end if}
{if strlen (loop[_key]) lt 40}
<input name="values[{loop/_index}]" id="trv-{loop/_index}" type="text" style="width: 100%" {if loop[current] ne null}value="{loop/current}"{end if} /><br />
{intl Google Translation}: <span id="tr-{loop/_index}">{intl loading...}</span>
{if empty(loop[current])}{if not empty (obj[apikey])}{intl Translation}: <span id="tr-{loop/_index}">{intl loading...}</span>{end if}{end if}
<a id="tru-{loop/_index}" style="display: none" href="#" onclick="$('#trv-{loop/_index}').attr ('value', $('#tr-{loop/_index}').html ()); return false">{intl Use this!}</a>
{end if}
</td>
Expand All @@ -56,28 +60,34 @@
</p>

</form>
{if not empty (obj[apikey])}

<script type="text/javascript">

$(document).ready (function () {
$.translate (
[
{loop show}
'{loop/_key}'{if loop[_index] lt loop[_total]},{end if}
{end loop}
],
// '{intl/default}', SEMIAS edit PHAGENS 26.10.10, as English 'en' is the default language used by the system, use it hardcoded here.
'en',
'{lang}',
{
complete: function (translations) {
for (i = 0; i < translations.length; i++) {
$('#tr-' + (i + 1)).html ($.trim (translations[i]));
$('#tru-' + (i + 1)).css ('display', 'inline');
}
}
}
);
$.translate.load('{apikey}');
var sourceText = [
{loop show}
{if empty(loop[current])}
'{loop/_key}'{if loop[_index] lt loop[_total]},{end if}
{end if}
{end loop}
];

$.translate(sourceText,'en','{lang}', {
complete: function(translation) {
for (i = 0; i < translations.length; i++) {
$('#tr-' + (i + 1)).html ($.trim (translations[i]));
$('#tru-' + (i + 1)).css ('display', 'inline');
}
},
error: function(error) {
alert(error.message);
for (i = 0; i < sourceText.length; i++)
$('#tr-' + (i + 1)).html("{intl Can't load translation}.");
}
});
});

</script>
{end if}

0 comments on commit 911f752

Please sign in to comment.