whitecube / laravel-cookie-consent

Register, configure and ask for cookies consent in a EU-compliant way
MIT License
312 stars 37 forks source link

Some Sections in the Cookies View Do Not Translate Certain Parts #15

Closed sbono2016 closed 8 months ago

sbono2016 commented 11 months ago

Thank you for the plugin; this is exactly what I was looking for for many weeks.

I encountered a minor issue in the view related to translation.

I had to make some code changes to make it work:"

+- line 37 : From:

<span class="cookies__box">
      <strong class="cookies__label">{{ $category->title }}</strong>
  </span>
  @if($category->description)
      <p class="cookies__info">{{ $category->description }}</p>
  @endif

To:

<span class="cookies__box">
    <strong class="cookies__label">@lang('cookieConsent::cookies.categories.'.$category->key().'.title')</strong>
</span>
@if($category->description)
    <p class="cookies__info">@lang('cookieConsent::cookies.categories.'.$category->key().'.description')</p>
@endif

The same issue also exists with the cookie description, but I haven't found a way to modify it yet... +- line 48 :

<li class="cookies__cookie">
  <p class="cookies__name">{{ $cookie->name }}</p>
  <p class="cookies__duration">{{ \Carbon\CarbonInterval::minutes($cookie->duration)->cascade() }}</p>
  @if($cookie->description)
      <p class="cookies__description">{{ $cookie->description }}</p>
  @endif
</li>
toonvandenbos commented 10 months ago

Hi @sbono2016,

This is weird. I'm not sure the suggested fix is appropriate since you can add your own categories (which are not necessarily defined inside cookieConsent::cookies.categories). Also, I think it would be interesting to know why the default method didn't work in your case so we can figure out whether there is a problem with your project or with the package itself in a specific setup.

Could you elaborate? Thanks!

QuentinGab commented 9 months ago

Hi, I run into the same situation (mixed locales) and I just want to add some context about translation and the cookie registration process with service provider.

The doc says to register cookies in the boot method of a serviceProvider, but doing that raise a major problem: The locale is probably not already setup, because the boot method is called before any other code of you app (middleware, controller, ...) it will probably fallback to the default locale causing mixed languages to be rendered in the final result.

I would recommend 2 solutions:

MaartenOste commented 9 months ago

Same issue here. The default language of my app is "nl" and when switching to "en", some translations stay in "nl". Most translations come through, but the category title and description and the "defaults" seem to be failing (see images).

I've created a CookieServiceprovider and added this provider as the last provider in my config/app.php. Registering the cookies in the AppServiceProvider doesn't seem to make a difference.

Screenshot 2023-11-21 at 14 11 11 Screenshot 2023-11-21 at 14 11 04

toonvandenbos commented 8 months ago

What @QuentinGab mentioned is accurate. Defining cookies while booting Laravel is indeed too ealry, that's why I created PR #29 which is providing a publishable CookiesServiceProvider responsible for calling the cookies definition at the right moment in Laravel's booting lifecycle.

This will be published as v1.1.0 soon, please upgrade and read the updated "Usage" section in the docs.

petethewizard commented 5 days ago

I am using 1.2 and did everything in the usage section but keep having this problem. Any ideas?

petethewizard commented 5 days ago

I am using "codezero/laravel-localized-routes", maybe it has something to do with it? I've dd'd the locale just at the beginning of registerCookies and it still is 'en' when it should be 'de'. I guess I should not define them there but where then? I tried adding the cookies registration to custom middleware but I get the same problem, however when I added to the 'web' group the translations got fixed but now the popup appears each time no matter whether I agree or not to the cookies!!! Baffling. @toonvandenbos