Permalink
Browse files

Added ability to test country codes and URLs

  • Loading branch information...
1 parent 00a13a2 commit 979da87c158319e95728168eed2c47e3ab6aad46 Brian Cray committed May 11, 2011
Showing with 31 additions and 3 deletions.
  1. +11 −0 LICENSE
  2. +4 −0 README
  3. +10 −0 translate.html
  4. +6 −3 translator.js
View
11 LICENSE
@@ -0,0 +1,11 @@
+Copyright (C) 2010 Brian Cray
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
View
4 README
@@ -0,0 +1,4 @@
+Some things to know:
+ 1. If you are testing offline, it won't work. But you can set variable test_url to test against a public URL
+ 2. You can set variable test_cc to force a country code for testing
+ 3. If you have portions of your text that shouldn't be translated (such as source code) add "notranslate" as a class name
View
@@ -12,6 +12,16 @@
}
</style>
+ <script type="text/javascript">
+ // if you want to test the translator
+ // samples: fr (france), de (germany), cn (china), il (israel), mx (mexico)
+ // leave blank or remove for auto translation
+ var test_cc = 'fr';
+ // test on a public URL
+ // leave blank or remove for auto translation
+ var test_url = 'http://briancray.com';
+ </script>
+
<script type="text/javascript" src="translator.js"></script>
</head>
View
@@ -1,17 +1,20 @@
(function () {
var loaded = false;
+ test_cc = test_cc || false;
+ test_url = test_url || false;
+
var inject_jsapi = function () {
var h = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.type = 'text/javascript';
s.onreadystatechange = function () {
if (this.readyState === 'loaded' || this.readyState === 'complete') {
- translate(google.loader.ClientLocation && google.loader.ClientLocation.address.country_code, 'en');
+ translate(test_cc || (google.loader.ClientLocation && google.loader.ClientLocation.address.country_code), 'en');
}
};
s.onload = function () {
- translate(google.loader.ClientLocation && google.loader.ClientLocation.address.country_code, 'en');
+ translate(test_cc || (google.loader.ClientLocation && google.loader.ClientLocation.address.country_code), 'en');
};
s.src = 'http://www.google.com/jsapi';
h.appendChild(s);
@@ -70,7 +73,7 @@
};
cc in cc2lang && (function (uri) {
document.location.href = 'http://translate.google.com/translate?langpair=' + lang + '|' + cc2lang[cc] + '&u=' + uri;
- })(document.location.href);
+ })(test_url || document.location.href);
}
};

0 comments on commit 979da87

Please sign in to comment.