Added the ability to set the default PHP locale and override via multilang config #299

This commit is contained in:
Andy Miller
2015-09-07 16:54:48 -06:00
parent 5827fe4a22
commit 87ddd619de
3 changed files with 33 additions and 2 deletions

View File

@@ -238,7 +238,29 @@ form:
languages.home_redirect.include_route:
type: toggle
label: PLUGIN_ADMIN.HOME_REDIRECT_INCLUDE_ROUTE
help: PLUGIN_ADMIN.HOME_REDIRECT_INCLUDE_ROUTE
help: PLUGIN_ADMIN.HOME_REDIRECT_INCLUDE_ROUTE_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
languages.http_accept_language:
type: toggle
label: PLUGIN_ADMIN.HTTP_ACCEPT_LANGUAGE
help: PLUGIN_ADMIN.HTTP_ACCEPT_LANGUAGE_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
languages.override_locale:
type: toggle
label: PLUGIN_ADMIN.OVERRIDE_LOCALE
help: PLUGIN_ADMIN.OVERRIDE_LOCALE_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES

View File

@@ -1,5 +1,6 @@
absolute_urls: false # Absolute or relative URLs for `base_url`
timezone: '' # Valid values: http://php.net/manual/en/timezones.php
default_locale: # Default locale (defaults to system)
param_sep: ':' # Parameter separator, use ';' for Apache on windows
languages:
@@ -10,7 +11,8 @@ languages:
home_redirect:
include_lang: true # Include language in home redirect (/en)
include_route: false # Include route in home redirect (/blog)
http_accept_language: false # Attempt to set the language based on http_accept_language header in the browser
override_locale: false # Override the default or system locale with language specific one
home:
alias: '/home' # Default path for home, ie /

View File

@@ -192,6 +192,13 @@ class Grav extends Container
date_default_timezone_set($this['config']->get('system.timezone'));
}
// Initialize Locale if set and configured
if ($this['language']->enabled() && $this['config']->get('system.languages.override_locale')) {
setlocale(LC_ALL, $this['language']->getLanguage());
} elseif ($this['config']->get('system.default_locale')) {
setlocale(LC_ALL, $this['config']->get('system.default_locale'));
}
$debugger->startTimer('streams', 'Streams');
$this['streams'];
$debugger->stopTimer('streams');