-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multilingual website translations issue #71
Comments
@ShapesGraphicStudio u can switch it based on App::setlocale()
|
I also have an issue with multilingual site. The problem is that the
I temporary solved with a "re-translation" directly in blade file. Are there any other solutions? For details, see:
<?php
namespace Whitecube\LaravelCookieConsent;
abstract class CookiesServiceProvider extends ServiceProvider
{
public function register()
{
$this->booted(function () {
$this->registerCookies();
});
}
// ...
<?php
namespace Whitecube\LaravelCookieConsent;
class CookiesCategory
{
// ...
public function __construct(string $key)
{
$this->key = $key;
$this->setAttribute('title', $this->translate('categories.' . $key . '.title', ucfirst($key)));
$this->setAttribute('description', $this->translate('categories.' . $key . '.description'));
}
// ... My temporary solution in the file // ...
<div class="cookies__sections">
@foreach ($cookies->getCategories() as $category)
<div class="cookies__section">
<label for="cookies-policy-check-{{ $category->key() }}" class="cookies__category">
@if ($category->key() === 'essentials')
<input type="hidden" name="categories[]" value="{{ $category->key() }}" />
<input type="checkbox" name="categories[]" value="{{ $category->key() }}" id="cookies-policy-check-{{ $category->key() }}" checked="checked" disabled="disabled" />
@else
<input type="checkbox" name="categories[]" value="{{ $category->key() }}" id="cookies-policy-check-{{ $category->key() }}" />
@endif
<span class="cookies__box">
<strong class="cookies__label">
@lang("cookieConsent::cookies.categories.{$category->key()}.title")
</strong>
</span>
@php $description = __("cookieConsent::cookies.categories.{$category->key()}.description") @endphp
@if (filled($description))
<p class="cookies__info">
{{ $description }}
</p>
@endif
</label>
<div class="cookies__expandable" id="cookies-policy-{{ $category->key() }}">
<ul #class="cookies__definitions">
@foreach ($category->getCookies() as $cookie)
<li class="cookies__cookie">
<p class="cookies__name">
{{ $cookie->name }}
</p>
<p class="cookies__duration">
{{ \Carbon\CarbonInterval::minutes($cookie->duration)->cascade() }}
</p>
@php
$langkey = $cookie->name;
if ($category->key() === 'essentials') {
if (\Str::endsWith($langkey, '_consent')) {
$langkey = 'consent';
} else if (\Str::endsWith($langkey, '_session')) {
$langkey = 'session';
} else if (\Str::lower($langkey) === 'xsrf-token') {
$langkey = 'csrf';
}
} else if (\Str::startsWith($langkey, '_ga_')) {
$langkey = '_ga_ID';
}
$description = __("cookieConsent::cookies.defaults.{$langkey}")
@endphp
@if (filled($description))
<p class="cookies__description">
{{ $description }}
</p>
@endif
</li>
@endforeach
</ul>
</div>
<a href="#cookies-policy-{{ $category->key() }}" class="cookies__details">
@lang('cookieConsent::cookies.details.more')
</a>
</div>
@endforeach
</div>
// ... |
The Cookie Consent Service Provider should execute after the Route Service Provider in order to get translations to work properly. |
In my case, the language is set in a middleware. The middleware is executed always AFTER any provider. |
Same for me, the language is set in a middleware. |
Hi,
First, nice package, thanks!
I'm having a little issue thought as some texts seems to rely on APP_LOCALE setting in .env file.
I'm having a multilingual website and this should be set to current language.
Some strings are being translated when user changes language like:
_ 'more' => 'More details',
...
_ 'save' => 'Save settings',
But some are not like:
_ 'essentials' => [
'title' => 'Essential cookies',
'description' => 'There are some cookies that we have to include in order for certain web pages to function. For this reason, they do not require your consent.',
],
This is what I get when APP_LOCALE=fr and current language = en:

With APP_LOCALE=en and current language = en everything is in english.
With APP_LOCALE=fr and current language = fr everything is in french.
Any idea on how I could fix this please?
The text was updated successfully, but these errors were encountered: