lithium\action\Request::locale PHP Method

locale() public method

Sets or returns the current locale string. For more information, see "Globalization" in the manual.
public locale ( string $locale = null ) : string
$locale string An optional locale string like `'en'`, `'en_US'` or `'de_DE'`. If specified, will overwrite the existing locale.
return string Returns the currently set locale string.
    public function locale($locale = null)
    {
        if ($locale) {
            $this->_locale = $locale;
        }
        if ($this->_locale) {
            return $this->_locale;
        }
        if (isset($this->params['locale'])) {
            return $this->params['locale'];
        }
    }

Usage Example

 public function testLocaleDetection()
 {
     $request = new Request();
     $this->assertNull($request->locale());
     $request->params['locale'] = 'fr';
     $this->assertEqual('fr', $request->locale());
     $request->locale('de');
     $this->assertEqual('de', $request->locale());
 }