Thursday 1 March 2012

add google translate with selected language, google translate api with selected language

function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: ‘en’,
includedLanguages: ‘ja’,
defaultLanguage: ‘ja’,
multilanguagePage: true
}, ‘google_translate_element’);
}

set google translater default language, google translate default language

We can set google translate default language
by working with cookies
for this first use google translate to translate your web page
then see what cookies he has created
(for this right click on your web page then page info
then security then view cookies and click on googtrans you see what is the translation he is using and what is the path and what is the domain or host name )
and put this all data in setcookies function
example
setcookie(“googtrans”, “/en/ja”, time()+3600, “/”, “www.example.com”);
//setcookie(“googtrans”, “en/ja”);
setcookie(“googtrans”, “/en/en”, time()+3600, “/”, “.example.com”);

call a function regularly , call a function after a particular time period, call function continue


function getdata(){
var langu = jQuery(“.goog-te-combo”).html(‘<option value=”">Select Lanugage</option><option value=”en”>English</option><option value=”ja”>Japanese</option>’);
jQuery(“.goog-te-gadget”).css({“margin-top”:”0px”});
intervaltime();
}
</script>



<script>
function intervaltime(){
window.setInterval(function(){
getdata();
}, 5000);
}
$(function() {
setTimeout(getdata, 3000);
});
</script>

drupal 6 basic form , create form in drupal

<?php
function test_myform($form_state) {
// Access log settings:
$options = array('1' => t('Enabled'), '0' => t('Disabled'));
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Access log settings'),
'#tree' => TRUE,
);
$form['access']['log'] = array(
'#type' => 'radios',
'#title' => t('Log'),
'#default_value' =>  variable_get('log', 0),
'#options' => $options,
'#description' => t('The log.'),
);
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
$form['access']['timer'] = array(
'#type' => 'select',
'#title' => t('Discard logs older than'),
'#default_value' => variable_get('timer', 259200),
'#options' => $period,
'#description' => t('The timer.'),
);
// Description
$form['details'] = array(
'#type' => 'fieldset',
'#title' => t('Details'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['details']['description'] = array(
'#type' => 'textarea',
'#title' => t('Describe it'),
'#default_value' =>  variable_get('description', ''),
'#cols' => 60,
'#rows' => 5,
'#description' => t('Log description.'),
);
$form['details']['admin'] = array(
'#type' => 'checkbox',
'#title' => t('Only admin can view'),
'#default_value' => variable_get('admin', 0),
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 30,
'#maxlength' => 64,
'#description' => t('Enter the name for this group of settings'),
);
$form['hidden'] = array('#type' => 'value', '#value' => 'is_it_here');
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
function test_page() {
return drupal_get_form(‘test_myform’);
}
?>