Skip to content

Commit

Permalink
Set language used within API controllers to a default value instead o…
Browse files Browse the repository at this point in the history
…f null. Fixes #143
  • Loading branch information
lonnieezell committed Jan 2, 2016
1 parent 1ec3ebb commit 2d6b855
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions myth/Api/Server/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ class ApiController extends BaseController {
*/
protected $authenticate_class = '\Myth\Api\Auth\APIAuthentication';

/**
* The idiom that should be used for the language if
* no specific language is requested in Accept-Language header.
*
* @var string
*/
protected $default_language = 'english';

//--------------------------------------------------------------------

public function __construct()
Expand Down Expand Up @@ -742,7 +750,7 @@ protected function detectLanguage()
{
if ( ! $lang = $this->input->get_request_header('Accept-Language'))
{
return null;
return $this->default_language;
}

// They might have sent a few, make it an array
Expand Down Expand Up @@ -771,7 +779,7 @@ protected function detectLanguage()
}

// Nope, just return the string
return $lang;
return empty($lang) ? $this->default_language : $lang;
}

//--------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions myth/_docs_src/api/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ If the `per_page` var is set to zero, then the `nextURL` and `prevURL` will not
## Multilingual Support
To aid in creating multilingual sites, the controller will automatically parse the `Accept-Language` header and attempt to load the language file specified in `$this->language_file` in that idiom/language. If that language file doesn't exist, it will default to the 'application' language file.

The default language used, if no `Accept-Language` header can be found, is 'english'. This can be changed within any controller that extends the APIController by setting the `default_language` class property to the desired default idiom.

## Class Variables

### $request
Expand Down

0 comments on commit 2d6b855

Please sign in to comment.