I am using google translate for my Core PHP project.The issue I am facing is when I set english as a default language i.e. if any user opens the website in any other country the default language pf page transaltion would be English.I have added this code which works fine If any user open site in Dubai
function googleTranslateElementInit() {
setCookie('googtrans', '/en/en',1);
new google.translate.TranslateElement({
pageLanguage: 'en',
includedLanguages: 'en'
}, 'google_translate_element');
}
function setCookie(key, value, expiry) {
var expires = new Date();
expires.setTime(expires.getTime() + (expiry * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
The issue is it sets the default language to English but it changes the google traslation dropdown values to arabic.Here is the screenshot.
Issue
I am pretty much stuck in this.Any help would be appreciated.
I did some R and D on how google translation works and added some code also but it did not work upto my expectations.
Related
I'm currently trying my hands on WordPress plugind developement for an exercise and came across some little snag.
The plugin is designed to display a simple poll in a widget on the front page. Once the visitor has voted, I use setcookie to drop a cookie containing his vote for 30 days, and some simple code to change the widget so that it shows the results and the user cannot vote again until a new poll is proposed. The problem is, voting is still possible, the results are never shown. Looking at the logs with the developer's tools, I found that the cookie is deleted the second it lands on the client browser. Does anybody know why, and how I can correct that?
Here's the code. First, the action hook:
public function __construct()
{
parent::__construct('poll_plugin', __('Polls', 'poll_plugin'), array('description' => __('Simple poll widget', 'poll_plugin')));
add_action('init', array($this, 'save_votes'));
}
Then, the actual action:
public function save_votes()
{
global $wpdb;
/*Cookie setting, 30 days expiration */
if ( isset($_POST['option']) && !isset($_COOKIE['Poll_Votes']))
{
unset($_COOKIE['Poll_Votes']);
setcookie('Poll_Votes', $choix, 30 * DAYS_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);
$choix = $_POST['option'];
$id_choix = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}poll_options WHERE label = '$choix'");
$wpdb->query("UPDATE {$wpdb->prefix}poll_results SET total = total+1 WHERE option_id = '$id_choix'");
};
/*Testing the presence of a new poll */
$vote = $_COOKIE['Poll_Votes'];
/*If the cookie's value isn't found in the db, the poll's changed, so we reset the cookie*/
if (is_null($wpdb->get_var("SELECT * FROM {$wpdb->prefix}poll_options WHERE label = '$vote'")))
{
setcookie('Poll_Votes', '', time()-3600);
}
}
Quick note here, I already tried commenting the line designed to unset the cookie, it changed nothing.
The only other time where the cookie is mentioned is via the $_COOKIE global, in a isset().
And lastly, please forgive my english, I'm french :)
I want to detect my client country or locale which they open website from or get the browser recommended language.
For Example, if you open the browser in Japan it will give me country code or country name current user opened like "en-jp" or "japan".
After Searching I found out that "Zend Framework" has function to detect the user/environmental in Zend_locale.
So I wonder if I can do the same in laravel 4 or if not what solution you suggest in any method (php, javascript, checking ip, etc.)?
Thank you in advanced.
Ok I know the answers of my questions as following:
How to detect the client country?
As far as I know we need to use geoIP service to detect the client IP which can tell where the client using from (e.g. maxmind)
But this is not solution to detect and alter my website language, if you looking for this solution in laravel 4 I will show you in next question
How to check the language that client want to use? (locale in laravel4)
In summarize I found some of ways that can get which language that client want to use by following:
HTTP Header (HTTP_ACCEPT_LANGUAGE) in $_SERVER['HTTP_ACCEPT_LANGUAGE'] equal to Request::server('HTTP_ACCEPT_LANGUAGE') in laravel4. Which these header tell us the language that current client browser want to use.
Direct request - In this condition we will get direct request from client which language they want to use. For easy example like we give them the
<select>
<option val="en">English</option>
<option val="th">Thailand</option>
</select>
And they select from it send to server via url Ex: www.Test.com/en
Cookies (optional) - We can get the cookies from browser which we provide the language that last use by current user. Which is we must send the cookies after they visited the site for first times.
Before I use it I store the support languages array in app/config/app.php by following:
'languages' => array('en','th','jp'),
All of it I modify the code in app/filter.php to get all above data and processing with my app by following:
App::before(function($request){
// 1. get the request langugage
$url_lang = Request::segment(1);
// 2. get Cookie langugage
$cookie_lang = Cookie::get('language');
// 3. Get the Browser Request language
$browser_lang = substr(Request::server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
// 4. Start Checking the request language
// Check that Language tha request is support or not?
if(!empty($url_lang) AND in_array($url_lang, Config::get('app.languages')))
{
// Check whether the request url lang not same as remember in cookies
if($url_lang != $cookie_lang)
{
// Cookie::forever('language',$url_lang);
Session::put('language', $url_lang);
}
// Set the App Locale
App::setLocale($url_lang);
}
// Check that has Language in Forever Cookie and is it support or not?
else if(!empty($cookie_lang) AND in_array($cookie_lang, Config::get('app.languages')))
{
// Set App Locale
App::setLocale($cookie_lang);
}
// Check the browser request langugae is support in app?
else if(!empty($browser_lang) AND in_array($browser_lang, Config::get('app.languages')))
{
// Check whether the request url lang not same as remember in cookies
if($browser_lang != $cookie_lang)
{
// Cookie::forever('language',$browser_lang);
Session::put('language', $browser_lang);
}
// Set Browser Lang
App::setLocale($browser_lang);
}
else
{
// Default Application Setting Language
App::setLocale(Config::get('app.locale'));
}});
And after event of app is following:
App::after(function($request, $response){
$lang = Session::get('language');
if(!empty($lang))
{
// Send The language Cookies
$response->withCookie(Cookie::forever('language',$lang));
}
});
Hope this will help you out.
I use this Ip2Country for Laravel 4.2 that can retrieve a users country based on a given IP address. Creates a local database that utilizes the MaxMind GeoIP data, so no run time external API calls.
https://github.com/smalldogs/ip2country
I haven't tried this package, but you can probably use this:
https://github.com/webpatser/laravel-countries
If that doesn't get you all you need, you can probably combine it with the built in App::setLocale('en');
Referenced in:
http://cheats.jesse-obrien.ca
Speaks ohm89!
I used the following technique to capture the priority user linguam and show my site in your language:
1º - I created two new arrays in my app.php, alt_langs (supported by my site) and locale_prefix (language prefix to url):
'locale' => 'pt', // Default is en.
'alt_langs' => array ('pt', 'en', 'es'), // Supported by my site
'locale_prefix' => '', // Dinamic array.
2º - In routes.php file:
// Get the first segment url, ex.: mysite.com/pt and put this in locale_prefix array item:
if (in_array(Request::segment(1), Config::get('app.alt_langs'))) {
App::setLocale(Request::segment(1));
Config::set('app.locale_prefix', Request::segment(1));
}
// Here i usin the prexix to show right language site:
Route::group(array('prefix'=>Config::get('app.locale_prefix')), function()
{
Route::get('', array('uses' => 'HomeController#index'));
});
// And here i usin the http_accept_language to redirect him to default browser language:
Route::get('/', function(){
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
return Redirect::to($lang);
});
I hope I have helped.o/
GA: content>event>overview>event label.
I am using download tracker and I would like to make my reports "user friendlier",
the problem is, "this.href" function provide the "label" section in GA the name, which in that case takes the whole url (href="http://nameTheWebsite*/wp-content/uploads/2010/07/somethingToRead.pdf") and I would like to see only "somethingToRead.pdf" in my report.
the tracking code is:
_gaq.push(['_trackEvent','Download','PDF', this.href]);"
I am using WP.
now, I did some homework, and I believe that substr(this.href , -10) function could help but I don't know how to do it right.
Any help would be highly appreciatedץ
Thanks in advance.
Gal
substr(this.href, -10) will only work correctly, whenever the filename is accidentially 10 characters long.
A more sophisticated solution would be something like this:
var page = this.href.splitOnLast('/'); // this should return an array with two elements: path and filename
page = (page.length > 1) ? page[1].substr(1) : page[0]; // just in case there is no / in the this.href
_gaq.push(['_trackEvent','Download','PDF', page]);
Now you should get "somethingToRead.pdf" in your Google Analytics tracking.
I want to add the current time to the country name in JQVMAP. Like this: Eqypt-05:30 AM
By default, when we hover the mouse over a country, it only shows the country name in world map. I also want to add the current time. Please help me.
Pleasing to consult the documentation regarding:
onRegionOver: function(event, code, region)
{
// log out the region and or code to see the ID
if (window.console) console.log( region );
},
http://jqvmap.com/
youll need to do a time conversion hash/object based on element ID or similar
var foo = { "jqvmap1_thisID";"+5","jqvmap1_anotherID":"-2" };
then do the conversion
(not writing all the pseudo code)
OR you could have script that sets the labels onload, and then updates (settimeout 5000), though this is not ideal at all.
good luck!
Bo
I have the code for a javascript calendar and it works perfectly as it creates it when the page loads. However I was wondering if it's possible to add events to it. I found a plugin (jQuery) that enables the user to hover over a td with class "event" and an event will be displayed. So since this calendar will not be used by me but by someone else who knows nothing about developing I was wondering if there is a way to make a php file or upload or something so she can upload the event. I mean, let's say she wants an event on the 3rd then she uploads a file php reads it and tells javascript to add the class "event" that date and jQuery does the rest. Is it possible? I can't even figure out how to do it and I really hope I explained myself. Here's my javascript btw.
function buildCal(){
var d = new Date();
var month = d.getMonth()+1;
var year = d.getFullYear();
var monthName=['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
var daysInMonth=[31,0,31,30,31,30,31,31,30,31,30,31];
var objectDay = new Date(year, month-1, 1); //fix date bug when current day is 31st
objectDay.od=objectDay.getDay()+1; //fix date bug when current day is 31st
var todaydate=new Date()
var scanfortoday=(year==todaydate.getFullYear() && month==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
daysInMonth[1]=(((objectDay.getFullYear()%100!=0)&&(objectDay.getFullYear()%4==0))||(objectDay.getFullYear()%400==0))?29:28;
var t='<div class="main"><table class="main" cols="7" cellpadding="0" border="0" cellspacing="0">';
t+='<h3 class="monthCSS" align="center">'+monthName[month-1]+' - '+year+'</h3><tr align="center">';
for(s=0;s<7;s++)t+='<td class="daysofweek">'+"DoLuMaMiJuViSa".substr(s*2,2)+'</td>';
t+='</tr><tr align="center">';
for(i=2;i<=42;i++){
var x=((i-objectDay.od>=0)&&(i-objectDay.od<daysInMonth[month-1]))? i-objectDay.od+1 : ' ';
if (x==scanfortoday)
x='<td class="today">'+x+'</td>'
t+='<td class="days">'+x+'</td>';
if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';
}
Something else, as you can see here, it adds blankspaces until it gets to an actual date. I was trying to make it check if(x was not a number) then add a td class="padding" however to do this I was trying to use x.match(/[0-9]+/) but it didn't seem to work and it would also be the first time I try to use regex with javascript would anyone know why is that wrong? or how to actually check for it?
Edit
Something odd is happening with this script and I don't know why, I tried to change from
t+='<td class="days">'+x+'</td>';
to
t+='<td class="days' + x +'">'+x+'</td>';
this, so I could select each td, but when I do this a new td is generated which contains
<td id="days<td class=" today="">1</td>
I have NO idea why this happens, I just know it is messing with the code because afterwards I get a "> printed (because of quotes mis-match caused by this new td...why is this happening?
The calendar systems I've created use a full php array of the month. so that you can iterate over it and for every corresponding blank day table cell there is a blank array for the day.
e.g.
$calendar_dates = array(
[week_1] = array(
[sun] = Null
[mon] = NULL
[tue] = array(
[events] = array(
event_id => 'event name'
event_name => ''
event_time => ''
)
[wed]
...
)
[week_1] => array()
...........
)
I build the days array by just creating an array from the specified date and current week
then I hit the databse to get events in that range
then cycle through the events and attatch them to the calendar array.
works like charm.
To get it to work with javascript just have it echo some specific javascript in the head of the html file that control the opening and closing of the calendar days.
give you client a simple login page to input/edit events in a webform.
It sounds like you're wanting to push event data from the server to your webpage containing the calendar. While this is possible, it's difficult and generally not worth the effort. You would be better off building some AJAX into your calendar and polling the server for event updates every 5 or 10 minutes or so. This will introduce some delay between when new events are uploaded and when they display on the calendar, but will be much easier to develop.