使用 PHP 为 AngularJS 设置 cookie 翻译语言环境
Setting cookie for AngularJS translate locale using PHP
我的应用程序使用 Symfony 和 AngularJS。我有一些用 Symfony 本身翻译的,还有一些用 AngularJS angular-translate 翻译的。如何设置 cookie 或会话变量以将 AngularJS 的语言从 PHP 更改?
通过 PHP 设置 cookie:
<?php setcookie("_locale", "en"); ?>
并使用 ngCookies 从 angular 检索它:
angular.module('app', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
// Retrieving the cookie
var locale = $cookies.get('_locale');
// Do something with locale
}]);
我的应用程序使用 Symfony 和 AngularJS。我有一些用 Symfony 本身翻译的,还有一些用 AngularJS angular-translate 翻译的。如何设置 cookie 或会话变量以将 AngularJS 的语言从 PHP 更改?
通过 PHP 设置 cookie:
<?php setcookie("_locale", "en"); ?>
并使用 ngCookies 从 angular 检索它:
angular.module('app', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
// Retrieving the cookie
var locale = $cookies.get('_locale');
// Do something with locale
}]);