a-digital / cookie-consent-banner

Add a configurable cookie consent banner to the website.
MIT License
11 stars 14 forks source link

No line break for message possible #3

Closed olsp closed 6 years ago

olsp commented 6 years ago

When I enter a line break in the message field, the cookie banner no longer works.

mark-adigital commented 6 years ago

Hi,

Thanks, I've just addressed this in a new release.

Hope that helps,

Mark

olsp commented 6 years ago

Great, thank you. Would it be possible to have line breaks in the "Learn More Text" as well?

mark-adigital commented 6 years ago

It would be possible, however given that field populates the link I'm not sure why this would be needed?

olsp commented 6 years ago

Well, in German Privacy Policy is "Datenschutzerklärung". Sometimes it's good to be able to put a line-break or at least a ­ in it ... And talking about languages: is there any chance to translate the text for mulitlanguage sites?

mark-adigital commented 6 years ago

Ok, as of the new release the message and link text will both span lines with a hyphen so ­ will be honoured, and by creating a cookie-consent-banner.php file in the relevant translations folder you can now add translations for the various text settings which will be implemented on output.

olsp commented 6 years ago

Thank you so much, Mark! It's great, that you solved this so quickly.

For the translations, I guess the file needs to look like this, right?

<?php

    return [
        'learn' => 'xxx',
        'dismiss' => 'xxx',
        'message' => 'xxx'
    ];
mark-adigital commented 6 years ago

No worries!

Sorry for the delay over the weekend - but you are correct, the file structure is just as described in the Craft docs.

Hope that helps - are you happy for me to close this issue now?

olsp commented 6 years ago

The translation doesn't work for me. German is the main language of the website, but there is an English Version too. So I create the following file /translations/en/cookie-consent-banner.php with the content as written above. Is there anything wrong about it? Static string translations for other things work fine.

mark-adigital commented 6 years ago

One possible issue if your file is exactly as above would be that the key for the translated text shouldn't be the field names (learn, dismiss, message) - I wasn't sure if those were just placeholder but the correct values should be the text to be translated that is displayed on the German site.

So, if I was doing the opposite and translating English into German my file would look like this:

return [
    'Contact us' => 'Kontaktiere uns',
];

And 'Contact Us' would be the text entered in one of the plugin setting fields. Might that be the issue, or is your file already formatted this way?

olsp commented 6 years ago

Sorry, that's embarrassing for me, of course this was the error. But unfortunately, this still doesn't work:

'Datenschutz&shy;erklärung' => 'privacy protection',

I tried it with and without the ­

I don't have a clue about plugin development, but isn't there a possibility to translate those strings in the CP just like other textfields?

mark-adigital commented 6 years ago

No worries!

Ok, that seems odd as I've been able to simulate the same thing by entering German values into our dev site plugin settings and adding an English translation file and all is working fine. I can also confirm that you do need to include the &shy;.

For the learn more field I entered: Datenschutz&shy;erklärung

Message field: Diese Website verwendet Cookies, um sicherzustellen, dass Sie die beste Erfahrung auf unserer Website erhalten.

Dismiss button text: Verstanden!

And my complete /translations/en/cookie-consent-banner.php file looks like this:

<?php
  return [
    'Diese Website verwendet Cookies, um sicherzustellen, dass Sie die beste Erfahrung auf unserer Website erhalten.' => 'This website uses cookies to ensure you get the best experience on our website.',
    'Datenschutz&shy;erklärung' => 'Privacy Policy',
    'Verstanden!' => 'Got it!',
];

This works fine for me, are you sure there's no other differences with your setup?

I'm sure that what you describe will be possible, yes - but to be honest I haven't played with translations that much myself and I don't think a standard plugin setting field can be so easily translatable through the CP knowing how these are stored, so it would involve adding a separate table/records to the DB referencing each locale, which for the sake of three short text fields is a bit overkill. Maybe as part of a bigger update in the future!

olsp commented 6 years ago

Mark, you are really the best. Thanks for your patience and support. I had a blank character before the string, that's why it didn't work.

Thanks for your great work!

olsp commented 6 years ago

Sorry, one last thing. Does it work for you, if you have line breaks in the message?

mark-adigital commented 6 years ago

No problem - glad you were able to resolve the issue.

Ok, after some trial and error I've tweaked the order of some of the function calls on that field so this works now. What you will need to do is to add a <br /> tag to your translation file where the line break occurs.

So my translation file now looks like this:

<?php
  return [
    'Diese Website verwendet Cookies, um sicherzustellen, <br />dass Sie die beste Erfahrung auf unserer Website erhalten.' => 'This website uses cookies to ensure you get the best experience on our website.',
    'Datenschutz&shy;erklärung' => 'Privacy Policy',
    'Verstanden!' => 'Got it!',
  ];

And you could add a <br> tag to the translated text if you wished too.

olsp commented 6 years ago

Now everything works, you did a great job. Thank you Mark!

mark-adigital commented 6 years ago

No worries, glad we got there!

Thanks for the feedback - the plugin is definitely now better as a result.

bartrylant commented 4 years ago

I've made translation files and put them in the right language folders. However, the consent banner is always shown in English (Dutch is default and all texts are translated from the Dutch version). Website languages are set correctly. Site 1: nl-BE Site 2: fr-BE Site 3: en-GB On every site, the consent banner gets its value from the file in the en folder

ohvitorino commented 4 years ago

I had the same problem. By changing the text in the cp to English and creating a translation file in the correct language I was able to translate the "Message" and the "Learn More Text", but no luck with the buttons or the "Learn More link".

I ended up writing some javascript to change the content on the fly.

drifteaur commented 4 years ago

@ohvitorino I had the same problem too, I've created a pull request to allow translating the buttons and the link too

https://github.com/a-digital/cookie-consent-banner/pull/28

ohvitorino commented 4 years ago

Great! Thanks @drifteaur

mark-adigital commented 4 years ago

And this pull request has now been accepted and released, thanks @ohvitorino and @drifteaur

pimago commented 3 years ago

Hi, my main site German and the second language is English. I created everything like olsp above. But I am always seeing the English text. Also when I am on the default German site. Am I missing something?

mark-adigital commented 3 years ago

I'm not aware of any breaking changes to this. olsp didn't say exactly what he had to update at the time, but this comment seemed to put him on the right track. Can you check against that example and if the issue persists, maybe add a comment like that one with your field values and translations file please?

pimago commented 2 years ago

Hi Mark, this is how my cookie-consent-banner.php file looks like

<?php

return [
    'Mehr erfahren' => 'Learn more',
    'Erlauben' => 'Allow',
    'Ablehnen' => 'Decline',
    'Für ein best mögliches Erlebnis nutzen wir Cookies.' => 'For the best browsing experience we are using cookies.',
];

And in both languages I am seeing the english version. On any machine I tested it on.

olsp commented 2 years ago

Where did you put that file?

pimago commented 2 years ago

It's in /translations/en/cookie-consent-banner.php My main language is also german. The file seems to load properly, but for both languages.

olsp commented 2 years ago

In the settings of the plugin you can set the different texts. What have you written in the text-input for "Learn More Text"?

To check if it really loads for both languages, you could try the following: change the text in your translation file to 'Mehr erfahren' => 'Learn more TEST'. Does this show then show that way in both versions?

pimago commented 2 years ago

The field has "Mehr erfahren" just like in the translation file. When I do your suggested test. I am seeing it for both languages. In the settings the example is in german.

Also sometimes I can see the banner hidden at the bottom of the page to be revoked. But I turned that feature off.

olsp commented 2 years ago

Did you set up the websites with the correct languages in Craft?

pimago commented 2 years ago

Languages for the sites are set to de and en. All other translations are working as expected.

pimago commented 2 years ago

So I reinstalled the plugin. Now for both languages the german message shows. But all the Links are in english. Also the plugin settings in the CP are still all in one big list. Is there something else I can try?

olsp commented 1 year ago

I just had the same issue and here is how I got it sorted. Even though the main language of my site is German, I needed to enter all the texts in the plugin settings in English. I then added the translations in the file /translations/de/cookie-consent-banner.php

So it seems like this only works if English is one the languages involved. I haven't tested other language combinations.