mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-20 03:16:18 +00:00
Enabled translation when not logged in
Reads from the Accept-Language HTTP header. Also fixed some encoding for ES translations. Fixes #375
This commit is contained in:
parent
92108d710d
commit
ad4642c2c4
6 changed files with 34 additions and 4 deletions
|
@ -46,7 +46,7 @@ class HomeController extends Controller
|
||||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function getTranslations() {
|
public function getTranslations() {
|
||||||
$locale = trans()->getLocale();
|
$locale = app()->getLocale();
|
||||||
$cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
|
$cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
|
||||||
if (cache()->has($cacheKey) && config('app.env') !== 'development') {
|
if (cache()->has($cacheKey) && config('app.env') !== 'development') {
|
||||||
$resp = cache($cacheKey);
|
$resp = cache($cacheKey);
|
||||||
|
|
|
@ -15,7 +15,17 @@ class Localization
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
$defaultLang = config('app.locale');
|
$defaultLang = config('app.locale');
|
||||||
|
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);
|
$locale = setting()->getUser(user(), 'language', $defaultLang);
|
||||||
|
}
|
||||||
app()->setLocale($locale);
|
app()->setLocale($locale);
|
||||||
Carbon::setLocale($locale);
|
Carbon::setLocale($locale);
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
|
@ -58,6 +58,7 @@ return [
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'locale' => env('APP_LANG', 'en'),
|
'locale' => env('APP_LANG', 'en'),
|
||||||
|
'locales' => ['en', 'de', 'es', 'fr', 'nl', 'pt_BR', 'sk'],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
@ -44,6 +44,8 @@ Once done you can run `phpunit` in the application root directory to run all tes
|
||||||
|
|
||||||
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`.
|
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.
|
Some strings have colon-prefixed variables in such as `:userName`. Leave these values as they are as they will be replaced at run-time.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
|
@ -166,7 +166,7 @@ return [
|
||||||
'start_a' => ':count usuarios han comenzado a editar esta página',
|
'start_a' => ':count usuarios han comenzado a editar esta página',
|
||||||
'start_b' => ':userName ha 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_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',
|
'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',
|
'pages_draft_discarded' => 'Borrador descartado, el editor ha sido actualizado con el contenido de la página actual',
|
||||||
|
@ -189,7 +189,7 @@ return [
|
||||||
'attachments_set_link' => 'Setear Link',
|
'attachments_set_link' => 'Setear Link',
|
||||||
'attachments_delete_confirm' => 'Haga click en borrar nuevamente para confirmar que quiere borrar este adjunto.',
|
'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_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_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',
|
'attachments_link_name' => 'Nombre de Link',
|
||||||
'attachment_link' => 'Link adjunto',
|
'attachment_link' => 'Link adjunto',
|
||||||
|
|
|
@ -14,6 +14,23 @@ class LanguageTest extends TestCase
|
||||||
$this->langs = array_diff(scandir(resource_path('lang')), ['..', '.']);
|
$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()
|
public function test_js_endpoint_for_each_language()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue