Skip to content
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

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

Closed
sbono2016 opened this issue Oct 11, 2023 · 7 comments · Fixed by #29
Closed

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

sbono2016 opened this issue Oct 11, 2023 · 7 comments · Fixed by #29

Comments

@sbono2016
Copy link

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
Copy link
Member

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
Copy link

QuentinGab commented Nov 18, 2023

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:

  • register cookies in a middleware after all your logic regarding setting the locale. It will work with the actual state of the package.
  • update the package to call @lang or __ in the blade view and only passing localization keys when registering cookies.

@MaartenOste
Copy link

MaartenOste commented Nov 21, 2023

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
Copy link
Member

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
Copy link

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

@petethewizard
Copy link

petethewizard commented Aug 31, 2024

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

@alien-rat
Copy link

I am using 1.2.3 and did everything in the usage section but keep having this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants