0

Im tryng to create a response fulfillment in php, but my problem is change the language of month result. I set the php webhook with setlocale, but google assistant always response in english.

header( 'Access-Control-Allow-Headers: *' );
header( 'Access-Control-Allow-Origin: *' );
header( "Access-Control-Allow-Credentials: true" );
header( 'Content-Type: application/json' );
$postdata = file_get_contents( "php://input" );
$input = json_decode( $postdata, true );
setlocale (LC_TIME, 'it_IT.utf8','ita'); 
$intent = $input[ 'queryResult' ][ 'intent' ][ 'displayName' ];
$giorno = $input[ 'queryResult' ][ 'parameters' ][ 'giorno' ];
$guest = $input[ 'queryResult' ][ 'parameters' ][ 'guest' ];
$telefono = $input[ 'queryResult' ][ 'parameters' ][ 'telefono' ];
$tempo = $input[ 'queryResult' ][ 'parameters' ][ 'time' ][ 0 ];
$nome = $input[ 'queryResult' ][ 'parameters' ][ 'nome' ];
$oggi = date( "d F", strtotime($giorno) );

echo "{
    'fulfillmentText': 'Grazie " . $nome . ", ti confermo la tua prenotazione per ".$guest." persone alle ore " . substr( $tempo, -14, 5 ) . " del giorno " . $oggi . ".',
    'fulfillmentMessages': [
            {'text':
            {'text':
            ['Grazie " . $nome . ", ti confermo la tua prenotazione per ".$guest." persone alle ore " . substr( $tempo, -14, 5 ) . " del giorno " . $oggi . ".']
        }}],
    'source':'webhook'
}"

What nI have to change to get month name in italian?

DigitalXP
  • 179
  • 5
  • 18

2 Answers2

0

You should try to use strftime function

$oggi = strftime( "%e %B", strtotime($giorno) );
Andrii Filenko
  • 954
  • 7
  • 17
0

You should use setlocale():

try like below:

setlocale(LC_TIME, 'it_IT');
$month_name = date('F', mktime(0, 0, 0, 1));

Refer this months in local languages , mktime()

In this case it would set it to French. For your case it should be one of the following:

  1. sr_BA - Serbian (Montenegro)
  2. sr_CS - Serbian (Serbia)
  • Dont work....the php file is on my server, in italian.... but seems that google assistant change the lnguage! – DigitalXP Feb 21 '19 at 14:27