Reads from the Accept-Language HTTP header.
Also fixed some encoding for ES translations.
Fixes #375
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
public function getTranslations() {
- $locale = trans()->getLocale();
+ $locale = app()->getLocale();
$cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
if (cache()->has($cacheKey) && config('app.env') !== 'development') {
$resp = cache($cacheKey);
public function handle($request, Closure $next)
{
$defaultLang = config('app.locale');
- $locale = setting()->getUser(user(), 'language', $defaultLang);
+ if (user()->isDefault()) {
+ $locale = $defaultLang;
+ $availableLocales = config('app.locales');
+ foreach ($request->getLanguages() as $lang) {
+ if (!in_array($lang, $availableLocales)) continue;
+ $locale = $lang;
+ break;
+ }
+ } else {
+ $locale = setting()->getUser(user(), 'language', $defaultLang);
+ }
app()->setLocale($locale);
Carbon::setLocale($locale);
return $next($request);
*/
'locale' => env('APP_LANG', 'en'),
+ 'locales' => ['en', 'de', 'es', 'fr', 'nl', 'pt_BR', 'sk'],
/*
|--------------------------------------------------------------------------
## Translations
As part of BookStack v0.14 support for translations has been built in. All text strings can be found in the `resources/lang` folder where each language option has its own folder. To add a new language you should copy the `en` folder to an new folder (eg. `fr` for french) then go through and translate all text strings in those files, leaving the keys and file-names intact. If a language string is missing then the `en` translation will be used. To show the language option in the user preferences language drop-down you will need to add your language to the options found at the bottom of the `resources/lang/en/settings.php` file. A system-wide language can also be set in the `.env` file like so: `APP_LANG=en`.
+
+You will also need to add the language to the `locales` array in the `config/app.php` file.
Some strings have colon-prefixed variables in such as `:userName`. Leave these values as they are as they will be replaced at run-time.
'start_a' => ':count usuarios han comenzado a editar esta página',
'start_b' => ':userName ha comenzado a editar esta página',
'time_a' => 'desde que las página fue actualizada',
- 'time_b' => 'en los Ãltimos :minCount minutos',
+ 'time_b' => 'en los últimos :minCount minutos',
'message' => ':start :time. Ten cuidado de no sobreescribir los cambios del otro usuario',
],
'pages_draft_discarded' => 'Borrador descartado, el editor ha sido actualizado con el contenido de la página actual',
'attachments_set_link' => 'Setear Link',
'attachments_delete_confirm' => 'Haga click en borrar nuevamente para confirmar que quiere borrar este adjunto.',
'attachments_dropzone' => 'Arrastre ficheros aquío haga click aquípara adjuntar un fichero',
- 'attachments_no_files' => 'NingÃn fichero ha sido adjuntado',
+ 'attachments_no_files' => 'Ningún fichero ha sido adjuntado',
'attachments_explain_link' => 'Ud. puede agregar un link o si lo prefiere puede agregar un fichero. Esto puede ser un link a otra página o un link a un fichero en la nube.',
'attachments_link_name' => 'Nombre de Link',
'attachment_link' => 'Link adjunto',
$this->langs = array_diff(scandir(resource_path('lang')), ['..', '.']);
}
+ public function test_locales_config_key_set_properly()
+ {
+ $configLocales = config('app.locales');
+ sort($configLocales);
+ sort($this->langs);
+ $this->assertTrue(implode(':', $this->langs) === implode(':', $configLocales), 'app.locales configuration variable matches found lang files');
+ }
+
+ public function test_correct_language_if_not_logged_in()
+ {
+ $loginReq = $this->get('/login');
+ $loginReq->assertSee('Log In');
+
+ $loginPageFrenchReq = $this->get('/login', ['Accept-Language' => 'fr']);
+ $loginPageFrenchReq->assertSee('Se Connecter');
+ }
+
public function test_js_endpoint_for_each_language()
{