PHP Classes

Localized version

Recommend this page to a friend!

      Google Weather API  >  All threads  >  Localized version  >  (Un) Subscribe thread alerts  
Subject:Localized version
Summary:Is it possible to get the weather localized?
Messages:9
Author:Niels Fanĝe
Date:2010-02-22 15:52:48
Update:2010-10-15 07:47:19
 

  1. Localized version   Reply   Report abuse  
Picture of Niels Fanĝe Niels Fanĝe - 2010-02-22 15:52:48
Hi,

First off: Very nice package! Can I get the weather report text in Danish (or any language other than English) as it is shown here:
google.com/ig/directory?hl=da&url=w ...

?

Thanks,

Niels

  2. Re: Localized version   Reply   Report abuse  
Picture of Niels Fanĝe Niels Fanĝe - 2010-02-22 16:01:52 - In reply to message 1 from Niels Fanĝe
I get it: If I add "&hl=da" instead of =en I get it in Danish. However... this is the result:
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xA0 0x25 0x22 0x2F in C:\Apache\htdocs\scripts\gweather\google_weather_api.php on line 24

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Mest skyet"/><temp_f data="32"/><temp_c data="0"/><humidity data="Fugtighed: 100 in C:\Apache\htdocs\scripts\gweather\google_weather_api.php on line 24

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in C:\Apache\htdocs\scripts\gweather\google_weather_api.php on line 24

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\Apache\htdocs\scripts\gweather\google_weather_api.php:24 Stack trace: #0 C:\Apache\htdocs\scripts\gweather\google_weather_api.php(24): SimpleXMLElement->__construct('<?xml version="...') #1 C:\Apache\htdocs\scripts\gweather\example.php(8): weather->get() #2 {main} thrown in C:\Apache\htdocs\scripts\gweather\google_weather_api.php on line 24

-------
Seems your script doesn't like funny characters like ĉĝċ... :o)

-Niels

  3. Re: Localized version   Reply   Report abuse  
Picture of Niels Fanĝe Niels Fanĝe - 2010-02-22 16:16:17 - In reply to message 2 from Niels Fanĝe
Got it: I changed line 23 of the api.php to this:
$xml_str = utf8_encode(file_get_contents($requestAddress,0));

-this utf8-encodes the string, and the error goes away.

Thank you, me! :o)

-Niels

  4. Re: Localized version   Reply   Report abuse  
Picture of Daniel Ivicic Daniel Ivicic - 2010-02-25 01:03:12 - In reply to message 1 from Niels Fanĝe
im getting negative temps,
for exmaple:
Min: -14 &#8451;
Max: -11 &#8451;

but should be:
Min: 14 &#8451;
Max: 11 &#8451;

  5. Re: Localized version   Reply   Report abuse  
Picture of Niels Fanĝe Niels Fanĝe - 2010-02-25 15:21:54 - In reply to message 4 from Daniel Ivicic
Min 14 and Max 11 does not make sense, either? Are you sure you have picked the right city?

  6. Re: Localized version   Reply   Report abuse  
Picture of Abbas Ali Butt Abbas Ali Butt - 2010-05-04 09:19:21 - In reply to message 3 from Niels Fanĝe
Thanx Niels

  7. Re: Localized version   Reply   Report abuse  
Picture of Alberto Alberto - 2010-10-14 19:28:23 - In reply to message 5 from Niels Fanĝe
hi dude, well i get the same error when try to use another languaje but i fixed using the utf8_encoder like niels write, also use it again in the day_of_week['data'] to get ok the display using the spanish languaje that have accents like Sábado.

But i get the same Min: & Max: with negative values, so can you tell me in what format the xml is displayed the value? is in farenheit? i also check the formula to convert °F to °C and is ok. so what happend here?

  8. Re: Localized version   Reply   Report abuse  
Picture of Alberto Alberto - 2010-10-14 19:51:17 - In reply to message 7 from Alberto
OK, sorry now i undestand why appear negative the value of min & max and in my case is because is not neccesary user the convert function because i use Languaje 'es' instead of 'en' in

$requestAddress = "http://www.google.com/ig/api?weather=".trim(urlencode($this->location))."&hl=es";

so the convertion is allready done in the xml value in °C that is what i need, so you must check and compare first in what format you need if and check the XML file, who? just write the url in the IE and put your city like this

google.com/ig/api?weather=chicago&h ...

and you can compare the values openning another one with other langueje like english like this:

google.com/ig/api?weather=pachuca&h ...

  9. Re: Localized version   Reply   Report abuse  
Picture of Niels Fanĝe Niels Fanĝe - 2010-10-15 07:47:19 - In reply to message 8 from Alberto
Hi,
In google_weather_api.php I have added "&encoding='UTF-8'" to the $requestAddress var.
In the php function that actually displays the weather I add a UTF8 decode function to each weather element, such as:
utf8_decode($weather->current->wind_condition['data'])
Everything is now shown to my Danish satisfaction, including the letters ĉĝċĈĜĊ. ;o)
-Niels