Skip to content

Commit

Permalink
Feat: Introduce companyNames option as i18n parameter #CCM-25
Browse files Browse the repository at this point in the history
  * you can pass one or more company names which must be part of your
    consent text
  • Loading branch information
literat committed Nov 19, 2021
1 parent 519182d commit e271230
Show file tree
Hide file tree
Showing 10 changed files with 565 additions and 378 deletions.
25 changes: 15 additions & 10 deletions src/LmcCookieConsentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const defaultOptions = {
onAccept: (cookie, cookieConsent) => {},
onAcceptOnlyNecessary: (cookie, cookieConsent) => {},
onAcceptAll: (cookie, cookieConsent) => {},
companyNames: ['LMC'],
config: {},
};

Expand All @@ -33,6 +34,7 @@ const defaultOptions = {
* @param {function} [args.onAccept] - Callback to be executed when any consent is detected (either given right now or already saved previously)
* @param {function} [args.onAcceptOnlyNecessary] - Callback to be executed when consent with only necessary cookies is detected (either given right now or already saved previously)
* @param {function} [args.onAcceptAll] - Callback to be executed when consent with all cookies is detected (either given right now or already saved previously)
* @param {array} [args.companyNames] - Array of strings with company names used to parametrized translations
* @param {Object} [args.config] - Override default config. See https://github.com/orestbida/cookieconsent/blob/master/Readme.md#all-available-options
* @returns {Object} Instance of the underlying CookieConsent component. For available API, see https://github.com/orestbida/cookieconsent#apis--configuration-parameters
*/
Expand All @@ -51,12 +53,24 @@ const LmcCookieConsentManager = (serviceName, args) => {
onAccept,
onAcceptOnlyNecessary,
onAcceptAll,
companyNames,
config,
} = options;
const cookieName = 'lmc_ccm';
const cookieConsent = window.initCookieConsent();
const isFirstTimeAccept = !cookieConsent.validCookie(cookieName);

const languages = {
cs: configCs({ companyNames }),
de: configDe({ companyNames }),
en: configEn({ companyNames }),
hu: configHu({ companyNames }),
pl: configPl({ companyNames }),
ru: configRu({ companyNames }),
sk: configSk({ companyNames }),
uk: configUk({ companyNames }),
};

cookieConsent.run({
auto_language: autodetectLang, // Enable detection from navigator.language
autorun: true, // Show the cookie consent banner as soon as possible
Expand Down Expand Up @@ -110,16 +124,7 @@ const LmcCookieConsentManager = (serviceName, args) => {
? onAcceptOnlyNecessary(cookie, cookieConsent)
: onAcceptAll(cookie, cookieConsent);
},
languages: {
cs: configCs,
de: configDe,
en: configEn,
hu: configHu,
pl: configPl,
ru: configRu,
sk: configSk,
uk: configUk,
},
languages,
// override default config if necessary
...config,
});
Expand Down
116 changes: 70 additions & 46 deletions src/languages/cs.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,80 @@
export const config = {
consent_modal: {
title: 'Tyto stránky využívají cookies',
description: `Kliknutím na „Přijmout vše“ dáváte souhlas společnosti LMC k využívání souborů Cookies a dalších identifikátorů ve vašem zařízení. Použití těchto Cookies a dalších identifikátorů usnadní navigaci na stránkách, zobrazení personalizovaného obsahu, cílený marketing, analýzu využívání našich produktů a služeb.
import { addSeparators, plural } from '../utils';

const extra = {
and: 'a',
company: 'společnosti',
companies: 'společnostem',
};

/**
* @param {Object} [messages] - Object with extra messages
* @param {array} [args.companyNames] - Array of strings with company names used to parametrized translations
* @returns {Object} Object with translated messages
*/
export const config = (messages) => {
const lang = { ...extra, ...messages };

return {
consent_modal: {
title: 'Tyto stránky využívají cookies',
description: `Kliknutím na „Přijmout vše“ dáváte souhlas ${plural(
lang.companyNames.length,
lang.company,
lang.companies,
)} ${addSeparators(
lang.companyNames,
extra.and,
)} k využívání souborů Cookies a dalších identifikátorů ve vašem zařízení. Použití těchto Cookies a dalších identifikátorů usnadní navigaci na stránkách, zobrazení personalizovaného obsahu, cílený marketing, analýzu využívání našich produktů a služeb.
Více informací naleznete na stránce <a href="https://www.lmc.eu/cs/cookies" target="_blank">Používání cookies</a>.`,
primary_btn: {
text: 'Přijmout vše',
role: 'accept_all',
},
secondary_btn: {
text: 'Přijmout nezbytné',
role: 'accept_necessary',
primary_btn: {
text: 'Přijmout vše',
role: 'accept_all',
},
secondary_btn: {
text: 'Přijmout nezbytné',
role: 'accept_necessary',
},
},
},
settings_modal: {
blocks: [
{
toggle: {
value: 'necessary',
enabled: true,
readonly: true,
settings_modal: {
blocks: [
{
toggle: {
value: 'necessary',
enabled: true,
readonly: true,
},
},
},
{
toggle: {
value: 'ad',
enabled: false,
readonly: false,
{
toggle: {
value: 'ad',
enabled: false,
readonly: false,
},
},
},
{
toggle: {
value: 'analytics',
enabled: false,
readonly: false,
{
toggle: {
value: 'analytics',
enabled: false,
readonly: false,
},
},
},
{
toggle: {
value: 'functionality',
enabled: false,
readonly: false,
{
toggle: {
value: 'functionality',
enabled: false,
readonly: false,
},
},
},
{
toggle: {
value: 'personalization',
enabled: false,
readonly: false,
{
toggle: {
value: 'personalization',
enabled: false,
readonly: false,
},
},
},
],
},
],
},
};
};

export default config;
110 changes: 64 additions & 46 deletions src/languages/de.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,74 @@
export const config = {
consent_modal: {
title: 'Diese Website verwendet Cookies',
description: `Indem Sie auf „Alles akzeptieren“ klicken, stimmen Sie der Verwendung von Cookies und anderen Identifikatoren auf Ihrem Gerät durch LMC zu. Die Verwendung dieser Cookies und anderer Identifikatoren erleichtert die Navigation auf der Website, die Anzeige personalisierter Inhalte, gezieltes Marketing und die Analyse der Nutzung unserer Produkte und Dienstleistungen.
import { addSeparators } from '../utils';

const extra = {
and: 'und',
};

/**
* @param {Object} [messages] - Object with extra messages
* @param {array} [args.companyNames] - Array of strings with company names used to parametrized translations
* @returns {Object} Object with translated messages
*/
export const config = (messages) => {
const lang = { ...extra, ...messages };

return {
consent_modal: {
title: 'Diese Website verwendet Cookies',
description: `Indem Sie auf „Alles akzeptieren“ klicken, stimmen Sie der Verwendung von Cookies und anderen Identifikatoren auf Ihrem Gerät durch ${addSeparators(
lang.companyNames,
extra.and,
)} zu. Die Verwendung dieser Cookies und anderer Identifikatoren erleichtert die Navigation auf der Website, die Anzeige personalisierter Inhalte, gezieltes Marketing und die Analyse der Nutzung unserer Produkte und Dienstleistungen.
Weitere Informationen finden Sie unter <a href="https://www.lmc.eu/en/cookies/" target="_blank">Verwendung von Cookies</a>.`,
primary_btn: {
text: 'Alles akzeptieren',
role: 'accept_all',
},
secondary_btn: {
text: 'Das Notwendigste akzeptieren',
role: 'accept_necessary',
primary_btn: {
text: 'Alles akzeptieren',
role: 'accept_all',
},
secondary_btn: {
text: 'Das Notwendigste akzeptieren',
role: 'accept_necessary',
},
},
},
settings_modal: {
blocks: [
{
toggle: {
value: 'necessary',
enabled: true,
readonly: true,
settings_modal: {
blocks: [
{
toggle: {
value: 'necessary',
enabled: true,
readonly: true,
},
},
},
{
toggle: {
value: 'ad',
enabled: false,
readonly: false,
{
toggle: {
value: 'ad',
enabled: false,
readonly: false,
},
},
},
{
toggle: {
value: 'analytics',
enabled: false,
readonly: false,
{
toggle: {
value: 'analytics',
enabled: false,
readonly: false,
},
},
},
{
toggle: {
value: 'functionality',
enabled: false,
readonly: false,
{
toggle: {
value: 'functionality',
enabled: false,
readonly: false,
},
},
},
{
toggle: {
value: 'personalization',
enabled: false,
readonly: false,
{
toggle: {
value: 'personalization',
enabled: false,
readonly: false,
},
},
},
],
},
],
},
};
};

export default config;
Loading

0 comments on commit e271230

Please sign in to comment.