Change wesbite words as per customer language

praveen545445

Senior Member
Joined
Dec 6, 2017
Messages
866
Reaction score
106
i want to change my website content to my visitor desired language i have the language button option but its just translating only my website menu buttons & some things only not the whole website content so i how can i change that the website is of php so i have less knowledge about that
 
Assuming that you want the translations performed on the server side (PHP) you can use file_get_contents to fetch data from Google Translate API. Then you need to parse the response and get translated text. You need to get API KEY to access the Translate service.

Code:
<?php
$string = 'Hello World';
$source_lang = 'en';
$target_lang = 'zh-CN'

header ( "Content-Type: text/html;charset=utf-8" );
$data = file_get_contents ( 'https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&q='.urlencode($string).'&source='.$source_lang.'&target='.$target_lang );
$data = json_decode ( $data ); 
$translated = $data->data->translations->[0]->translatedText;
echo $translated;

?>
 
Assuming that you want the translations performed on the server side (PHP) you can use file_get_contents to fetch data from Google Translate API. Then you need to parse the response and get translated text. You need to get API KEY to access the Translate service.

Code:
<?php
$string = 'Hello World';
$source_lang = 'en';
$target_lang = 'zh-CN'

header ( "Content-Type: text/html;charset=utf-8" );
$data = file_get_contents ( 'https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&q='.urlencode($string).'&source='.$source_lang.'&target='.$target_lang );
$data = json_decode ( $data );
$translated = $data->data->translations->[0]->translatedText;
echo $translated;

?>
where i have to put this code ?
 
If you don't know how to use PHP. Try google translator plugin. But don't buy a pro version without testing the plugin.
 
Back
Top