I'm looking for a way to get a user default language by the country. For example I have windows in english but still I would like to get my country 2 letter language ("cs")
You can see an example of what I want, In the source code of http://search.conduit.com/ using (Autocompleteplus) as well. This is what I see:
window.language = "en-us";
window.countryCode = "cz";
window.suggestBaseUrl = "http://api.autocompleteplus.com/?q=UCM_SEARCH_TERM&l=cs&c=cz&callback=acp_new";
You can see the api url has inside "l=cs&c=cz" how did they get this information? I would like to have the same thing I use the same autocompleteplus method just need a way to generate the l=(user true langague)&c=(country code) and performance is important as well. It's autosuggestions for my website search.
This is Ed from AutoComplete+. Getting the user country is typically done when using our API through server side implementations. There are however some open APIs that can assist you. Regardless, you can use our autocomplete feed without the user country. Feel free to contact us directly for further info at http://www.autocompleteplus.com
Thanks,
--ed
Related
I just started a course on php, and we have to each make and present a simple program of our choosing that takes one input and automatically generates a different output.
I chose to make a program that automatically takes a text that a user types into a forum's text field, and run it through google translate, and translates the text into another language in the same textfield, ready to edit. The problem is, when I incorporated the Google Translate API guideline according to the official Google Webmaster's guide, it translates everything EXCEPT what is inside textfields.
Anyone know if there is a way to work around it?
Thanks in advance for your help.
Ok, it is as easy as this, but still remains a hack:
<?php
$ch = curl_init("http://translate.google.com/translate_a/t?client=t&sl=en&tl=de&q=Hello%20World");
curl_exec($ch);
curl_close($ch);
?>
What you need to change is sl, tl and q values.
sl = Input language
tl = Output language
q = Your text, that will be translated
The response will look like this:
[[["Hallo Welt","Hello World","",""]],,"en",,[["Hallo Welt",[1],true,false,999,0,2,0]],[["Hello World",1,[["Hallo Welt",999,true,false]],[[0,11]],"Hello World"]],,,[["en"]],70]
Shouldn't be to difficult to extract the first array.
I have PHP-MySQL Website with admin panel. I can enter data from admin panel and they display on user side web pages. Now, I want that I should be able to insert text data in English language from admin panel and they should display in 3 different languages at user side.
At user side, I want to give options for visitors to select language preference and user sides pages should display in that selected language. Right now I am completely unaware for what programming related changes I will need to make on user sides pages to make this possible.
I have searched and read some articles on internet but frankly could not find solution that will work for my case. So please help me.
Following things are used / set in my working environment.
Windows Server 2003
PHP 5.2.17
MySQL 5.0.51a (UTF-8 Unicode (utf8))
XHTML 1.0 Transitional
meta charset=iso-8859-1
Thank you in advance,
KRA
Assuming you have all your language variables and/or html views separated out into some sort of structure, you could always just use a cookie.
Have your site check for the presence of said cookie and if it doesn't exist, then have the site revert to the default language, otherwise adjust the language accordingly.
Ex:
Have a form with dropdown values for each language and when it is submitted, set the language cookie variable:
setcookie('userLanguage',$language_value,strtotime("+1 year"));
The first parameter is the name of the cookie variable, the second is the value (in this case, the user's language selection, and the third is the expiry date of the cookie (I made it one year, but you can set it to whatever you like).
The next step really depends on how your site is setup, but I'll assume that you have your language text in a db or handled in some intelligent way. Either way, you need to retrieve the cookie:
if ($_COOKIE['userLanguage'] <> '')
// Do some language stuff here based on the value of $_COOKIE['userLanguage']
else
// Do some stuff here for default language
That's about it. There are a lot of different ways to handle the actual language conversion, but the act of getting the user's preference and remembering it is pretty much as basic as 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.
<?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;
?>
Server responses are JSON objects with that structure:
{
"data": {
"translations": [
{
"translatedText": "Hallo Welt",
"detectedSourceLanguage": "en"
}
]
}
}
More info about basic concept is avaliable on:
http://baris.aydinoglu.info/coding/google-translate-api-in-php.
Documentation of Google Translate API queries:
http://code.google.com/apis/language/translate/v2/using_rest.html
You may use this and save the relevant data to your database. You may have separate columns for each language in your database table. Once the text / data is entered by the admin, you have to convert them using the solution and save them to relevant columns on the SAME row. The user may be given data from the relevant column according to their language selection.
Well this depends alot on how you store your textual data. If you have it in a db (mysql) then i suggest that you have a collumn that stands for the language. Then you could have either a session variable or a specific url or something else that gives you some indication of which language the user is requesting.
What you need is some way to figure out what kind of language your user wants, after that it's quite easy.
Have you tried anything yet?
Use language Files in your website.
For example,
For english -en.php
For French -fr.php
This files will have variables that will be used in front User end.User can select any language and on selecting, your code will load the following language
In your case, you are using database, so you can have this thing in your tables instead of Database
so your Front files will consist of variables instead of Text and this variables will be replace by language variables(Either from database or from files, its your choice) when user select a language
And yes, you need to put a default language.
Use following links to implement :-
http://scriptdigital.com/divers/phplocalization.html
http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/
http://code.google.com/p/slsphp/
Use this method.
Its working for me.
Switching languages on a website with PHP
I've done it in oyutrade.com
I'm thinking about a project, where I need such informations as described in the title. Does the Google Maps API provide something like this, or does anyone know how to get these informations?
Project will be done in PHP, HTML and Javascript.
AFAIK Google doesn't provide this information via the API. The only thing I can think of is getting the image, and then detecting the colour. A map of colour hex values against point type might give you what you need.
However, this may well break the Terms and Conditions, depending on what you're doing.
Is it possible to find geolocation using zip code using PHP.
For example, if i am entering the zip code i need to find the name of that particular zipcode.
Is that possible? if yes kindly explain me how?
Thanks in advance
See the duplicate question on how to turn an address into coordinates using the Google Geocoding service.
A query in the format [zipcode], United States, e.g..
72116, United States
should always work for you.
Try maps.google.com to simulate the request.
The XML returned from the Google Service will contain the official place name, as well as other information like county and state names etc.
You can do this through Javascript and PHP using Google's Map API - check this question for an example of how this is used.
I dont think it can be done solely through PHP however because you'd need to access an API's data and they normally (not always) do this through javascript.
You should check the API documentation.
You can access the Geocoding API solely using PHP.. you don't even need an API Key anymore.
http://code.google.com/apis/maps/articles/phpsqlgeocode.html
So if understand this correctly, you want to know the City/State of the zip code you have entered?
Maybe you should look into the Access database here :
http://databases.about.com/od/access/a/zipcodedatabase.htm
And if you find it useful, just convert it into a MySQL table and use as you please.
I develop a wap portal for games. My problem is to detect handset device perfectly. My games provider provide me the supported handset list like this:
Nokia6300, SGH-X200, MOT-C261, SIE-CX70, SAMSUNG-SGH-Z140
So, I have to detect the supported games for the particular wap user.
I can easily detect the handset for nokia devices using below command:
require_once('../TeraWurfl.php');
$wurflObj = new TeraWurfl();
$matched = $wurflObj->getDeviceCapabilitiesFromAgent();
$brand_name = $wurflObj->getDeviceCapability("brand_name");
$model_name = $wurflObj->getDeviceCapability("model_name");
$handset=$brand_name. $model_name;
//Nokia6300,Nokia6600 etc.
But the problem is for siemence ,Motorola ,some Samsung sets,and lot of others.
Let say the user agent:
SIE-CX70/36 UP.Browser/7.0.2.2.156(GUI) MMP/2.0 Profile/MIDP-2.0 Configuration/CLDC-1.1
Provide me the model name: CX70 and Brand Name: Siemens.
So if I concatenate then get the value: SiemensCX70.But the actual is: SIE-CX70.
So, Information mis-match.
Now my question is how can I detection the perfect handset.
Please help me to retrieve the actual info.
Thanks
riad
I guess you have already figured this out, there is no easy way to do this, you will need to maintain a mapping on your side that maps the WURFLMODELNAME to the actual handset that your client gives. This way you can have a better Display of the handset names. Make sure you can do a many to one mapping so that you can map 1 or many WURFL Model Names to 1 Handset Display name.
You could utilize UAProf, a URL of RDF format which describes handset capabilities, together with the user agent because UAProf does not always exist in the header. I won't say it's perfect because there is always some exception. I have seen a RDF file which has invalid format. But it might be helpful for your case.
Please refer to this simple example (Restlet):
http://shengchien.blogspot.com/2010/09/restful-mobile-detection.html