Setting cookie for AngularJS translate locale using PHP

498 views Asked by At

My app uses Symfony and AngularJS. I have translations some with Symfony itself and some with AngularJS angular-translate. How do I set a cookie or session variable to change language for AngularJS from PHP?

1

There are 1 answers

0
michelem On BEST ANSWER

Set the cookie via PHP:

<?php setcookie("_locale", "en"); ?>

and retrieve it from angular with ngCookies:

angular.module('app', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
     // Retrieving the cookie
     var locale = $cookies.get('_locale');
     // Do something with locale
}]);