fonction pour traduire jours dans "yweather"

Petit nouveau ! | 5 Messages

13 mars 2012, 23:12

Bonsoir,

Cela fait des mois que je cherche un script météo pour mon blog
J'ai enfin un script php qui affiche la météo (5jours) en anglais (TUE, WEN, THU, FRI, SAT ...)
Ce serait sympa si quelqu'un m'indiquait s'il y a un moyen, une fonction ou un script, pour traduire ces jours en français

Par avance, merci.

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

14 mars 2012, 06:27

Salut,

Il faut voir comment l'heure est affichée mais normalement y a moyen d'afficher la chose en français en plaçant les locales.
Regarde les fonctions de date [url=htm://www.php.net/date]date[/url] et la classe datetime.


@+
Il en faut peu pour être heureux ......

Petit nouveau ! | 5 Messages

14 mars 2012, 19:56

Bonjour moogli, le forum,

Merci pour ta réponse, je ne m'y connais pas vraiment en php, de plus, yahoo team semble affirmer que yahoo weather api n'est pas traduisible, cela m'étonne puisque je vois que yahoo propose tout de même des widgets qui, eux, sont en français, enfin je ne sais pas trop. :

http://developer.yahoo.com/forum/Genera ... 03b8ea3d07

Je préconise une solution, mais je ne sais pas la réaliser, c'est de supprimer la ligne (du tableau) qui contient les jours en anglais,
J'aurai alors juste les 3 lignes d'en dessous, contenant la température, maxi, mini et les icones, j'ai essayé et ça marche,
Et de mettre à la place de la ligne supprimée un script php affichant les diminutifs des noms des 5 jours (l'actuel et les 4 prochains)
<body>
<table align="center">
<tr>
<td class="location" colspan="5"><span>Marseille</span></td>
</tr>
<tr valign="top">
<td class="weather" width="25%"><span class="u"><?php echo strtoupper($weather['forecast'][0]['when']) ?></span><br />
	<span style="color:#FFCC00;">Max: <strong><?php echo $weather['forecast'][0]['high'] ?></strong></span><br />
	<span style="color:#33FF99;">Min: <strong><?php echo $weather['forecast'][0]['low'] ?></strong></span><br />
	<img src="<?php echo $weather['forecast'][0]['image'] ?>" alt="php Yahoo Weather Widget" /></td>
<td class="weather" width="25%"><span class="u"><?php echo strtoupper($weather['forecast'][1]['when']) ?></span><br />
	<span style="color:#FFCC00;">Max: <strong><?php echo $weather['forecast'][1]['high'] ?></strong></span><br />
	<span style="color:#33FF99;">Min: <strong><?php echo $weather['forecast'][1]['low'] ?></strong></span><br />
	<img src="<?php echo $weather['forecast'][1]['image'] ?>" alt="php Yahoo Weather Widget" /></td>
<td class="weather" width="25%"><span class="u"><?php echo strtoupper($weather['forecast'][2]['when']) ?></span><br />
	<span style="color:#FFCC00;">Max: <strong><?php echo $weather['forecast'][2]['high'] ?></strong></span><br />
	<span style="color:#33FF99;">Min: <strong><?php echo $weather['forecast'][2]['low'] ?></strong></span><br />
	<img src="<?php echo $weather['forecast'][2]['image'] ?>" alt="php Yahoo Weather Widget" /></td>
<td class="weather" width="25%"><span class="u"><?php echo strtoupper($weather['forecast'][3]['when']) ?></span><br />
	<span style="color:#FFCC00;">Max: <strong><?php echo $weather['forecast'][3]['high'] ?></strong></span><br />
	<span style="color:#33FF99;">Min: <strong><?php echo $weather['forecast'][3]['low'] ?></strong></span><br />
	<img src="<?php echo $weather['forecast'][3]['image'] ?>" alt="php Yahoo Weather Widget" /></td>
<td class="weather" width="25%"><span class="u"><?php echo strtoupper($weather['forecast'][4]['when']) ?></span><br />
	<span style="color:#FFCC00;">Max: <strong><?php echo $weather['forecast'][4]['high'] ?></strong></span><br />
	<span style="color:#33FF99;">Min: <strong><?php echo $weather['forecast'][4]['low'] ?></strong></span><br />
	<img src="<?php echo $weather['forecast'][4]['image'] ?>" alt="php Yahoo Weather Widget" /></td>
</tr>
</table>
</body>
Si ce n'est pas réalisable, ou non recommandable, je laisse tomber de toute façon, et j'essayerai de trouver un autre script.

Par avance merci.

Petit nouveau ! | 5 Messages

16 mars 2012, 17:57

Hello le forum,
Une solution est d'afficher dans un tableau (1 ligne et 5 colonnes) le jour actuel et les 4 suivants, jours en diminutifs.
J’ai un script qui affiche le jour d’aujourd’hui seulement, ce serait bien sympa, si quelqu'un pouvait m’aider à l’adapter.

Code : Tout sélectionner

<html> <head> <title>Test Date</title> </head> <body> <?php //timestamp du moment $timestamp_actuel = time(); //fonction pour convertir un timestamp en date française function convertir($timestamp_actuel) { setlocale(LC_TIME, 'fr_FR.ISO_8859-1'); return strftime("%a ", $timestamp_actuel); } echo convertir($timestamp_actuel); ?> </body> </html>
L'idéal serait d'ajouter une fonction pour transformer les jours (qui sont affichés en minuscules) en majuscules.
Merci pour votre aide.

Petit nouveau ! | 5 Messages

18 mars 2012, 12:40

Bonjour,

J'ai trouvé un moyen en javascript pour afficher les jours dans un tableau, mais cela crée un conflit sur ma page d'accueil :

Code : Tout sélectionner

<html> <head> <script type="text/javascript"> function generateTabJour(){ var jours = new Array('Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'); var now = new Date().getDay(); var tr = document.getElementById('dateJour').rows[0]; for(var i=0; i<5; i++){ var td = tr.cells[i]; var jour = now+i; if(jour>6){ jour = jour-7; } td.innerHTML = jours[jour] } } function init(){ generateTabJour(); } window.onload = init; </script> </head> <body> <table id="dateJour"> <tbody> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td>text1</td> <td>text2</td> <td>text3</td> <td>text4</td> <td>text5</td> </tr> </tbody> </table> </body>
Peut-on faire la même chose en php svp ?

Par avance, merci.

ViPHP
xTG
ViPHP | 7331 Messages

18 mars 2012, 12:44

Oui tu peux tout à fait traduire cela en PHP.
La fonction Date.getDay() est à remplacer par la fonction date() avec le bon argument et le reste reste semblable au niveau algorithmie.