Closed GoogleCodeExporter closed 8 years ago
Reply from developer:
Please can you provide an example of the code you used to try and insert the
script onto your site? Thanks!
Original comment by phathway@gmail.com
on 6 Jan 2011 at 10:39
Comment from radu21mm:
hello, yes,: / 2. Specify the IDs for all major regions (I.e. HTML elements) in
your site that should have their contents translated. Note that an ID can only
be used to identify a single element on a page (for elements which appear
multiple times, use Class Names instead - see below). The script will translate
each element separately; any elements that cannot be found on a page will be
ignored: /
var GL_classIds = [["nav", ["l_sidebar"], ["sidebar"], ["footer"], ["login"],
]; my website is built in php and each website page is builted from 3 files
(head, body, footer). I don't know where to put the language script code. My
website contain a script that create contacts forms, and is to difficult for my
to know where to insert the new script. thank you
Original comment by phathway@gmail.com
on 6 Jan 2011 at 10:40
Reply from developer:
Have you checked the example file (example.html) that comes with the script? If
you check the HTML source code of this file, you'll see that it contains
comments that explain how it interacts with the script...
For example, the list with an ID of 'navigation' is written in English, and
will be translated by the script from this into another language.
Other content - for example each <div> with a class of 'entry' - might have
been written in ANY language, which is therefore automatically detected during
translation.
--
The script works broadly in the same way for sites built in PHP as for sites
that just use basic HTML - you need to imagine what HTML is output after your
page has been generated via PHP.
Basically, you should insert the following code somewhere inside your 'body'
PHP file, so that it gets output as HTML wherever you want the list of
languages to be displayed on the page:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="translate.js"></script>
<div id="mlt_languagelist"></div>
Then you need to work out the following: "What are the main regions of my page?"
For example, many sites have a navigation menu, and various blocks of content,
such as multiple blog entries,. These regions are defined using HTML - i.e.
each region should have a class name (e.g. <div class="blog-entry">) or ID
(e.g. <div id="navigation">). You need to decide what language the text inside
each region is likely to be (or whether the script should detect this
automatically). You should then alter the 'translate.js' file to include a list
of every region on your generated page, along with the language to translate it
from (if known) - please see the documentation above and the example file for
help with this. Upload the script and your PHP files to your server, and
hopefully it will work correctly...
Does any of this help? If not, please let me know. Thanks!
Original comment by phathway@gmail.com
on 6 Jan 2011 at 10:41
Comment from radu21mm:
hello, i tried, but i didn't find id or class, <div style="FONT-SIZE: 0.9em"> .
almost all my div don't contain id or class. If you want i can send you my
bodyhome.php file, and maybe you give me some clues. thank you
Original comment by phathway@gmail.com
on 6 Jan 2011 at 10:42
NEW reply from developer:
Because you own the PHP file, I'd imagine that it should be possible to adjust
it so that the DIVs do contain class names or IDs? If you did not have access
to it, that would make things much more problematic ;)
Please feel free to send me the PHP file (e.g. using the 'Attach a file' button
below), and I'll try and offer further advice.
By the way, the reason that you need to specify the regions for the script to
work, is that Google isn't always very good at automatically detecting
languages, and this makes errors less likely. A much longer technical
explanation can be found at:
http://code.google.com/p/multi-language-translation/wiki/Documentation#Why_Do_I_
Need_to_Specify_the_Regions_to_Translate_on_Each_Page?
It's good practice to add an ID or class name to DIVs in any case, as it should
make your page easier to maintain (e.g. if you decide in the future that you
want to change the appearance of your site)...
Thanks - hope this helps!
Original comment by phathway@gmail.com
on 6 Jan 2011 at 10:56
hello, thank you, i'll attach my main php body file.
Original comment by radu2...@googlemail.com
on 8 Jan 2011 at 5:52
Attachments:
For most sites, I would at this stage look through and identify the main
content areas, and then add an ID or class to each individual region - e.g. by
changing the HTML to <div class="introduction"> (or <p class="intro"> etc).
However, looking through your body page, it appears that all text is written in
a single language (i.e. English), and there's a much easier way of achieving
the same thing:
1. Adjust the top of the script (i.e. the top 4 variables in translate.js) to
read:
var GL_baseLang = "en";
var GL_classIds = [["standard"]];
var GL_classNames = [];
var GL_curLang = "";
2. Change the BODY tag (which is probably within your 'head' PHP file) to read:
<body id="standard">
3. Adjust your body PHP file to include the following code wherever you want
the list of translatable languages to appear:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="translate.js"></script>
<div id="mlt_languagelist"></div>
E.g. In the attached file, I've altered the code to display it in your left
sidebar (below the 'How To Do It' section).
4. Upload your body file, head file and translate.js file, making sure they are
all located within the same folder.
---
Please let me know if it works! If in the future you update the page to contain
text written in multiple languages we'll have to look at this further, but for
now this should work fine.
Hope this helps :)
Original comment by phathway@gmail.com
on 9 Jan 2011 at 7:49
Attachments:
hello, thank you, it's working, you are a star, :). i'm really happy
Original comment by radu2...@googlemail.com
on 10 Jan 2011 at 5:14
You're welcome :)
I'm hoping to release an update to this script fairly soon that will make it
easier to use on single-language websites...
If you have any further questions or need any more assistance, please let me
know.
Original comment by phathway@gmail.com
on 10 Jan 2011 at 8:34
Original issue reported on code.google.com by
phathway@gmail.com
on 6 Jan 2011 at 10:38