[Koha-devel] Google transliteration for koha opac. Trouble with IE..

savitra sirohi savitra.sirohi at osslabs.biz
Tue Oct 6 08:24:06 CEST 2009


Kousubha,

We have done this already, here is the patch.

Thanks,
Savitra Sirohi
Nucsoft OSS labs
http://www.osslabs.biz

This is available only on the masthead search box in the OPAC.

User has to enter a word in english and press space or return to
transliterate the word. The destination language can be selected from
a drop down list. User can temporarily turn on/off the feature by
using "ctrl +g".

A system preference - GoogleIndicTransliteration can be used to turn
on this feature.
---
 koha-tmpl/opac-tmpl/prog/en/css/opac.css           |    5 +++
 .../opac-tmpl/prog/en/includes/doc-head-close.inc  |    5 +++
 koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc  |    4 +-
 .../prog/en/js/googleindictransliteration.js       |   29 ++++++++++++++++++++
 opac/opac-main.pl                                  |    5 +++
 opac/opac-search.pl                                |    5 +++
 6 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 koha-tmpl/opac-tmpl/prog/en/js/googleindictransliteration.js

diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css
b/koha-tmpl/opac-tmpl/prog/en/css/opac.css
index de320d6..0c5c8d6 100644
--- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css
+++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css
@@ -1097,6 +1097,11 @@ float : right;
 width: 100%;
 }

+#translControl{
+float : left;
+padding-left : .4em;
+}
+
 .clearfix:after {
    content: ".";
    display: block;
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc
b/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc
index 2238fba..eeed1a5 100644
--- a/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc
@@ -80,3 +80,8 @@
       //]]>
 </script><!-- /TMPL_IF -->
 <link rel="unapi-server" type="application/xml" title="unAPI"
href="<!-- TMPL_VAR NAME="OPACBaseURL" -->/cgi-bin/koha/unapi" />
+<!-- TMPL_IF NAME="GoogleIndicTransliteration" -->
+        <script type="text/javascript"
src="http://www.google.com/jsapi"></script>
+        <script type="text/javascript" language="javascript"
src="<!-- TMPL_VAR NAME="themelang"
-->/js/googleindictransliteration.js"></script>
+<!-- /TMPL_IF -->
+
diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
index b118d18..058615b 100644
--- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc
@@ -55,9 +55,9 @@
        <option value="callnum">Call Number</option>
               <!-- /TMPL_IF --></select>
 <!-- TMPL_IF NAME="ms_value" -->
-        <input type="text" name="q" value="<!-- TMPL_VAR
ESCAPE="HTML" NAME="ms_value" -->" class="left" style="width: 35%;
font-size: 111%;" />
+        <input type="text" id = "transl1" name="q" value="<!--
TMPL_VAR ESCAPE="HTML" NAME="ms_value" -->" class="left" style="width:
35%; font-size: 100%;"/><div id="translControl"></div>
 <!-- TMPL_ELSE -->
-        <input type="text" name="q" class="left" style="width: 35%;
font-size: 111%;" />
+        <input type="text" id = "transl1" name="q" class="left"
style="width: 35%; font-size: 100%;"/><div id="translControl"></div>
 <!-- /TMPL_IF -->
   <!-- TMPL_UNLESS NAME="opac_limit_override" -->
       <!-- TMPL_IF name="mylibraryfirst" -->
diff --git a/koha-tmpl/opac-tmpl/prog/en/js/googleindictransliteration.js
b/koha-tmpl/opac-tmpl/prog/en/js/googleindictransliteration.js
new file mode 100644
index 0000000..414cadd
--- /dev/null
+++ b/koha-tmpl/opac-tmpl/prog/en/js/googleindictransliteration.js
@@ -0,0 +1,29 @@
+      // Load the Google Transliteration API
+      google.load("elements", "1", {
+            packages: "transliteration"
+          });
+
+       function onLoad() {
+        var options = {
+          sourceLanguage: 'en',
+          destinationLanguage: ['hi','kn','ml','ta','te'],
+          shortcutKey: 'ctrl+g',
+          transliterationEnabled: true
+        };
+
+        // Create an instance on TransliterationControl with the required
+        // options.
+        var control =
+            new
google.elements.transliteration.TransliterationControl(options);
+
+        // Enable transliteration in the textfields with the given ids.
+        var ids = [ "transl1" ];
+        control.makeTransliteratable(ids);
+
+        // Show the transliteration control which can be used to toggle between
+        // English and Hindi and also choose other destination language.
+        control.showControl('translControl');
+      }
+      google.setOnLoadCallback(onLoad);
+
+
diff --git a/opac/opac-main.pl b/opac/opac-main.pl
index 5a56db0..1f4d8d5 100755
--- a/opac/opac-main.pl
+++ b/opac/opac-main.pl
@@ -56,4 +56,9 @@ $template->param(
    koha_news_count => $koha_news_count
 );

+# If GoogleIndicTransliteration system preference is On Set paramter
to load Google's javascript in OPAC search screens
+if (C4::Context->preference('GoogleIndicTransliteration')) {
+        $template->param('GoogleIndicTransliteration' => 1);
+}
+
 output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index ae7f4ea..e1e66a9 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -640,4 +640,9 @@ if ($cgi->param('format') && $cgi->param('format')
=~ /rss/) {
    $content_type = 'html'
 }

+# If GoogleIndicTransliteration system preference is On Set paramter
to load Google's javascript in OPAC search screens
+if (C4::Context->preference('GoogleIndicTransliteration')) {
+        $template->param('GoogleIndicTransliteration' => 1);
+}
+
 output_with_http_headers $cgi, $cookie, $template->output, $content_type;
--
1.5.6



On Mon, Oct 5, 2009 at 7:03 PM, Koustubha Kale <kmkale at anantcorp.com> wrote:
> Hi all,
>
> I need a bit of help
>
> I am trying to integrate google transliteration with koha opac search
> box. This makes it easier to search indian language keywords for
> english keyboard users.
>
> I have it working with Firefox at www.granthalaya.org; but in IE I
> dont get the language selection box. The transliteration still works
> but the language selection dropdown does not appear. I cant make out
> anything from the error message displayed either. The error says
> "line: 40 char: 243 unexpected call to method or property access.Code
> : 0" If I use the same google transliteration code in a simple html
> page in IE it works. So I am doubly puzzled so as to where to look for
> the problem. What could it be?
>
> Can someone please have a look at the site in both IE and Firefox and
> suggest something?
>
> Regards,
> Koustubha Kale
> Anant Corporation
>
> Contact Details :
> Address  : 103, Armaan Residency, R. W Sawant Road, Nr. Golden Dyes
> Naka, Thane (w),
>         Maharashtra, India, Pin : 400601.
> TeleFax  : +91-22-21720108, +91-22-21720109
> Mobile     : +919820715876
> Website  : http://www.anantcorp.com
> Blog : http://www.anantcorp.com/blog/?author=2
> _______________________________________________
> Koha-devel mailing list
> Koha-devel at lists.koha.org
> http://lists.koha.org/mailman/listinfo/koha-devel
>



More information about the Koha-devel mailing list