Welcome to the Cumulus Support forum.

Latest Cumulus MX release v3.1.2 build 3055 - 4 November 2019.
Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014

See the Wiki for downloading either version.

translate $Currentsolardescription in Spanis

Discussion of Ken True's web site templates

Moderator: saratogaWX

Post Reply
josebp
Posts: 48
Joined: Tue 13 Apr 2010 11:37 am
Weather Station: Davis Vantage Pro2
Operating System: WINDOWS 10
Location: Sevilla, España
Contact:

translate $Currentsolardescription in Spanis

Post by josebp » Mon 10 Jun 2019 2:48 pm

Hi, I have TweetWX-conditions.php running for Twitter
I have modified $ Currentsolardescription but it does not translate in Spanish:
16:30 27.4ºC (Max 27ºC / Min 18ºC) Clear
This is the code I use:

Code: Select all

<<?php
/* TweetWX-conditions.php

 This package is based on code by Joe Chung at http://nullinfo.wordpress.com/oauth-twitter/
 
 Repackaged for TweetWX by Ken True - Saratoga-weather.org  08-Jun-2010
 Docs at http://saratoga-weather.org/scripts-TweetWX.php
 TweetWX-conditions.php  V1.00 - 11-Jun-2010 - Initial relase

 This utility function should be used once to get the OAuth request_token and request_token_secret
 for use in the next step of setup.
 
*/

if (phpversion() < 5) {
  echo 'Failure: This Script requires PHP version 5 or greater. You only have PHP version: ' . phpversion();
  exit;
}

// --------------- settings ----------------------
require_once("Settings.php");
require_once("common.php");
$tweetWXdir = './';
$wxdir = './';  // path to the advforecast2.php
$tweetTags = '#Tiempo actual en #Sevilla Más información en www.tiempoensevilla.es';  // customize for your Twitter tags and/or website url (shortened)
// ----------- end settings ----------------------

require_once($tweetWXdir . 'TweetWX-globals.php');

// Fill in the next 2 variables from the values produced in TweetWX-setup2.php.
$access_token = ''; // oauth_token
$access_token_secret = ''; // oauth_token_secret


include_once($wxdir . 'CUtags.php');
$uomTemp = 'ºC';
$uomWind = $WX['windunit'];
$uomBaro = $WX['pressunit'];
$uomRain = $WX['rainunit'];
$dirlabel = $WX['wdir'];
$temperature = $WX['temp'];
$avgspd = $WX['wspeed'];
$maxgst = $WX['wgustTM'];
$baro = $WX['press'];
$dayrn = $WX['rfall'];
$time = substr($WX['time'],0,5);
$maxtemp = $WX['tempTH'];
$mintemp = $WX['tempTL'];

//$sTemp = round(strip_units($temperature),0);
$sHum  = $WX['hum'];
$sWind = "$dirlabel " . round($avgspd,0)."->".round(strip_units($maxgst),0).$uomWind;
  if (preg_match('|0->0|',$sWind) ){
	$sWind = "Calma";
  }
//$sBaro = sprintf("%01.1f",strip_units($baro));
//$sRain = sprintf("%01.1f",strip_units($dayrn));

$message = fixup_time($time)." $temperature$uomTemp (Max ".round(strip_units($maxtemp),0)."$uomTemp/Min ".round(strip_units($mintemp),0).
		   "$uomTemp) $Currentsolardescription Hum: $sHum% Viento: $sWind ".
           "Presión: $baro$uomBaro Lluvia: $dayrn$uomRain-";
$message .= ' ' . $tweetTags;
$message = trim($message);
if (strlen($message) > 200) {
	echo $message . ' too long ('.strlen($message). ") -- reducing size<br/>\n";
	$message = preg_replace('|Mostly cloudy with clear patches|is','Mostly Cloudy',$message);
	$message = preg_replace('|Scattered|is','Sctd',$message);
}
		   
echo $message."<br/>len=".strlen($message)."<br/>status=";

$utfmessage = iconv('ISO-8859-1','UTF-8',$message);

// POST a tweet using OAuth authentication
$retarr = post_tweet(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
                           $utfmessage, $access_token, $access_token_secret,
                           true, true);

// print_r($retarr);

exit(0);

//=========================================================================
// change the hh:mm AM/PM to h:mmam/pm format
function fixup_time ( $WDtime ) {
  //if ($WDtime == "00:00: AM") { return ''; }
  //$WDtime = preg_replace('|^00:|','12:',$WDtime);
  return date('G:i' , strtotime($WDtime));
}


//  
  function fixupCondition( $inCond ) {
    global $DebugMode;
	
    $Cond = str_replace('_',' ',$inCond);
	$Cond = strtolower($Cond);
	$Cond = preg_replace('| -|','',$Cond);
	$Cond = trim($Cond);
	$dt = '';
	
	$vals = array();
	if(strpos($Cond,'/') !==false) {
		$dt .= "<!-- vals split on slash -->\n";
		$vals = explode("/",$Cond);
	}
	if(strpos($Cond,',') !==false) {
		$dt .= "<!-- vals split on comma -->\n";
		$vals = explode(",",$Cond);
	}
	$ocnt = count($vals);
	if($ocnt < 1) { return(langtransstr(trim($inCond))); }
	foreach ($vals as $k => $v) { 
	  if($DebugMode) { $dt .= "<!-- v='$v' -->\n"; }
	  $v = ucfirst(strtolower(trim($v)));
	  $vals[$k] = langtransstr($v); 
	  if($DebugMode) { $dt .= "<!-- vals[$k]='".$vals[$k]."' -->\n"; }
	}
	
	if($vals[0] == '') {$junk = array_shift($vals);}
	if(isset($vals[2]) and $vals[0] == $vals[2]) {$junk = array_pop($vals);}
	reset($vals);
	$t = join(', ',$vals);
	
//	return($Cond . "' orig=$ocnt n=" . count($vals) ." t='$t'");
    if($DebugMode) {
      $Currentsolardescription = "<!-- fixupCondition in='$inCond' out='$Currentsolardescription' ocnt='$ocnt' -->" . $dt . $Currentsolardescription;
	}
    return($Currentsolardescription);
  
  }

//=========================================================================


// strip trailing units from a measurement
// i.e. '30.01 in. Hg' becomes '30.01'
function strip_units ($data) {
  preg_match('/([\d\.\+\-]+)/',$data,$t);
  return $t[1];
}

?>
The function fixupCondition part is working well in:
http://tiempoensevilla.es/wxcunow.php


Thank you,
Regards,
Jose Ramon
Image

User avatar
saratogaWX
Posts: 991
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: translate $Currentsolardescription in Spanis

Post by saratogaWX » Mon 10 Jun 2019 3:39 pm

The translation for $Currentsolardescription is done inside the Saratoga template wx...php pages only -- the tag is not otherwise translated.

For example, In ajax-dashboard the fixupCondition($Currentsolardescription) function is used to split/translate the words/phrases based on values in the $LANGTRANS array which is loaded by common.php when a wx...php page is loaded.

It will be quite complicated to replicate all of that for the TweetWX-conditions script which runs outside the template, and doesn't have language support built-in.

josebp
Posts: 48
Joined: Tue 13 Apr 2010 11:37 am
Weather Station: Davis Vantage Pro2
Operating System: WINDOWS 10
Location: Sevilla, España
Contact:

Re: translate $Currentsolardescription in Spanis

Post by josebp » Mon 10 Jun 2019 5:03 pm

Gracias Ken.
Regards,
José Ramón
Image

Post Reply