News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Easy page translation for all kinds of languages

Started by flhtcuu, October 18, 2009, 05:59:39 PM

Previous topic - Next topic

flhtcuu

My site caters to the European market so it must be able to handle many languages and the text of the posts must be translated completely or the site is useless. THis MUST include posts, regardless of the original language they were written in.
I incorporated a very simple modification to the code that gives me nearly 100% translation with each and every page and is very simple for my users.
I use the google translation system and made it part of my system and the nice thing is, once the user selects the language it automatically converts the page and does it pretty quickly. It converts all post texts and does it with minimal errors. It solves so many problems and hassles I couldn't believe it!!
Here is how I did it.
I use the default template, so you may have to make slight adjustments.
The code you will need to enter is:

echo '<div id="google_translate_element"></div><script>'."\n";
echo 'function googleTranslateElementInit() {'."\n";
echo 'new google.translate.TranslateElement({'."\n";
echo 'pageLanguage: \'en\''."\n";
echo '}, \'google_translate_element\');'."\n";
echo '}'."\n";
echo '</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>'."\n";
echo ''."\n";


You need to enter it into the index.template.php file. Find this snippet of code.

// Show the menu here, according to the menu sub template.
template_menu();


And immediately after it enter the code I gave above.

This will place a Google translate drop down menu on your screen. It is not huge and will not make your site look much diferent at all and the placement I used makes it easy for everyone to see and use.
I've attached a screenshot of what your site will look like when this is completed.


Costa

Hugo "Costa" Fernandes - PT SMF
Todas as MP's a pedir ajuda são sujeitas a radioactividade, microondas, queimadas e atiradas borda fora.

"At least someone appreciates the fact that I am doing and not thinking..."
"Laziness is counter-revolutionary."

Akyhne

Moved.

Google is a quick way to translate sites, but in no way a decent way to do it.

flhtcuu

I'm not sure why you would say that Google is not a decent way to translate pages?
My wife is from Eastern Europe and speaks and reads several languages, every translation file used by SMF and other bulletin board software systems has problems and after many, many days of comparing to language translation files to Google's translation we found that Google out did them all.
Also, it needs to be mentioned, that NONE of these converted the posted text, they only converted the template text. Google on the other hand converts nearly 100% of the page.
Yes, Google does miss a few words and does miss a few, very few places, but out does every comparison.
If you have something that does better than Google and does posted text I would very much like to see it and I am sure others would too. Why not tell us, rather than just make a blanket statement as you have? Because honestly, my wife and I have done endless amounts of research on this exact topic and we could not find anything that did the entire page and that did it with the least amount of errors as Google has proven.
I have no affiliation with Google, I simply am trying to use the best translator I can for my system and personally have not found anything that handles it better or does as a complete a job as Google does.
I simply wanted to share an easy modification that does, in my opinion, the best translation capable in todays world. But I welcome you to show me a better system.


Akyhne

I can't answer for the languages your wife speak, but I do speak and understand a few languages myself. Google does mainly a decent and understansable translation. But it can never replace a human. Not as it is now.

I don't thing your idea/tip is bad, I just hope you are not going to use it as translation of the SMF software itself.

I've also seen a few mods being translated by Google. They were horrible and made no sense. One thing is common conversations between people, another is a technical explenation. Google does not do the last one properly.

flhtcuu

Oh I totally agree with you 100%. To try to modify the code using Google would be a disaster and nothing replaces a humans ability.
I think anytime we ask a computer to try to translate messages, letters, or any type of text file we are always taking a chance and have to take the best of the worst, since I don't think any software does it 100%.
I was really hoping you had something better than using Google, since as I said, it was the best of the worst kind of thing in my opinion, but worked better than everything else we tested and was simplified.
Thehardest part honestly was finding something that did the complete page and the text within posts. Seems every system, bulletin board, CMS, etc, offere multi-language but only really translate the outer wrapping, not the guts. It's the guts that matter to a user. If a Lithuanian, Ukrainian, Serbian or German accesses the site they need to be able to read the information within the site, not just the menus and presentation information. Google was the only one that went into the guts and did a fairly good job of translating it to a useable format for the user.
This mod is easy enough for anyone to install themselves and hopefully will help bring different languages into their system.

Now, the biggest problem my site personally faces and I have not solved.
A Lithuanian accesses my site, they use the Google translation bar, they can now read posts and reply. BUT, they type their message in Lithuanian. Sure other Lithuanians can read it, but nobody else can, because since it is not English, the Google translation system leaves it alone as is. It would be nice to find a utility that has the capability to take any language and convert it on the fly to another language. But, that would be a time consuming process and probably a huge task to try to undertake. But, sadly it is what I really need.

Sorry, I'm sure this is way more than you cared to know.


Bancherd

Neat  :D

I presume that this is usable with SMF2 as well?

flhtcuu

I've only tested this code on v1.1.1, but if placed correctly it should work regardless of the version.
The code was originally html and I just generically converted it into php to allow for placement into SMF.

I use a frontend CMS that I also have placed this code into so I am assuming that this code will work with anything based on the php language.


muqtada123

now Google updated a translate feature which is visible in the toolbar, its really way to translate full page just in seconds.

uk2us88

So it has to be in English first to translate or can it go in any direction?

RawDepth

#10
Quote from: Bancherd on October 19, 2009, 02:10:45 AM
Neat  :D

I presume that this is usable with SMF2 as well?

Yes, it works in my 2.0 RC2 as well.

However, it didn't look right as shown. The selection box was pushed off to the right and the text was off to the left. Instead I placed the new code just after the following existing code...

// Show the navigation tree.
theme_linktree();

RawDepth

Quote from: uk2us88 on November 19, 2009, 10:58:10 PM
So it has to be in English first to translate or can it go in any direction?
According to Google, the code should be modified slightly depending on what the original language of the website is in. It is easy to do. Go to this page...

http://translate.google.com/translate_tools?hl=en

...and choose different languages. Take notice what (two letters) change in the code as you choose each one.

LHW



qtime

nice one, the modification in the mod section forced to login everytime :).

~Dragon~

Please do not PM or email, Thank respond please post fast to SMF!

bulldog71169

I am getting complaints, based on the delay of thi sloading.  is there a way to put this in a sized container so there is no shift in the page when it loads?

henrik1782

Great tip...

Can anyone advice me how to put it in the upper right corner of the Curve theme. I have a language selection her but I think it will work better with this as all text is translated.

For another site I need the Google translate part under the login section, also curve theme...

Is it possible to have the language selection box the the Google logo part in one line?

I have tried but can only get it to be on the upper left side of the page... and that is not nice.
My favorite mods: Forum Firewall, httBL, MessagePreviewOnHover, BoardHover Mod, VB Style Board Index, Separate Replies and Views Column, Realtime clock by Joker, ENotify, Topic Solved.

henrik1782

#17
Ok... I can se that the translation script can be changed to one line..


echo '<div id="google_translate_element"></div><script>'."\n";
echo 'function googleTranslateElementInit() {'."\n";
echo 'new google.translate.TranslateElement({'."\n";
echo 'pageLanguage: \'da\''."\n";
echo 'layout: google.translate.TranslateElement.InlineLayout.SIMPLE'."\n";
echo '}, \'google_translate_element\');'."\n";
echo '}'."\n";
echo '</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>'."\n";
echo ''."\n";


But I cant get the layout line to work, actually it makes the script to not show at all.

I found out where to put it just under the login section, but have not found out where and how to get it to the top right corner where I now have the Language mod.
My favorite mods: Forum Firewall, httBL, MessagePreviewOnHover, BoardHover Mod, VB Style Board Index, Separate Replies and Views Column, Realtime clock by Joker, ENotify, Topic Solved.

henrik1782

Ok .. fixed the code


echo '<div id="google_translate_element"></div><script>'."\n";
echo 'function googleTranslateElementInit() {'."\n";
echo 'new google.translate.TranslateElement({pageLanguage: \'da\', layout: google.translate.TranslateElement.InlineLayout.SIMPLE'."\n";
echo '}, \'google_translate_element\');'."\n";
echo '}'."\n";
echo '</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>'."\n";
My favorite mods: Forum Firewall, httBL, MessagePreviewOnHover, BoardHover Mod, VB Style Board Index, Separate Replies and Views Column, Realtime clock by Joker, ENotify, Topic Solved.

lucas-ruroken

Adk Portal 3.1 is coming....

Design your universe!

Advertisement: