Skip to content

Commit

Permalink
Merge pull request #18 from giacomo/custom-lang
Browse files Browse the repository at this point in the history
feat: prepare custom language feature
  • Loading branch information
giacomo authored Jul 11, 2024
2 parents 4b9a1be + 14b5443 commit 20c9325
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 55 deletions.
56 changes: 33 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,39 @@ import { NgxCookieConsentModule } from '@localia/ngx-cookie-consent';

## Configuration

| Name | Type | Default | Description |
|-----------------------|----------------------------------|--------------------|------------------------------------------------------------------------------------|
| privacyPolicyUrl | string | TranslatableString | '#' | URL to your privacy policy ⚠ required ⚠ |
| imprintUrl | string | TranslatableString | '#' | URL to your imprint ⚠ required ⚠ |
| defaultLanguage | string | 'en' | Default language for the cookie consent banner |
| availableLanguages | string[] | ['en', 'de', 'it'] | Available languages for the cookie consent banner |
| showLanguageSwitcher | boolean | true | Show language switcher |
| showBadgeOpener | boolean | true | Show badge opener |
| openerPosition | enum | 'left-bottom' | Position of the badge eg. 'left-top', 'right-top' , 'left-bottom' , 'right-bottom' |
| customOpenerClass | string | '' | Custom class for the badge opener |
| customClass | string | '' | Custom class for the cookie consent banner |
| cookiePrefix | string | 'cookieconsent_' | Prefix for the cookie consent banner |
| cookieExpiryDays | number | 365 | Expiry days for the cookie consent banner |
| showCookieDetails | boolean | false | Show cookie details |
| showFunctionalCookies | boolean | true | Show functional cookies |
| functionalCookies | CookieItem[] | [] | Functional cookies |
| showMarketingCookies | boolean | true | Show marketing cookies |
| marketingCookies | CookieItem[] | [] | Marketing cookies |
| showEssentialCookies | boolean | true | Show essential cookies |
| essentialCookies | CookieItem[] | [] | Essential cookies |
| showOtherTools | boolean | true | Show other tools |
| otherTools | CookieItem[] | [] | Other tools |
| excludeRoutes | string[] | [] | Exclude routes eg. ['/privacy-policy'] |
| Name | Type | Default | Description |
|-----------------------|-----------------------------------|-------------------|------------------------------------------------------------------------------------|
| privacyPolicyUrl | string | TranslatableString | '#' | URL to your privacy policy ⚠ required ⚠ |
| imprintUrl | string | TranslatableString | '#' | URL to your imprint ⚠ required ⚠ |
| defaultLanguage | string | 'en' | Default language for the cookie consent banner |
| availableLanguages | string[] | ['en', 'de', 'it'] | Available languages for the cookie consent banner |
| customLanguage | CustomLanguageConfig | null | null | Custom language for the cookie consent banner |
| showLanguageSwitcher | boolean | true | Show language switcher |
| showBadgeOpener | boolean | true | Show badge opener |
| openerPosition | enum | 'left-bottom' | Position of the badge eg. 'left-top', 'right-top' , 'left-bottom' , 'right-bottom' |
| customOpenerClass | string | '' | Custom class for the badge opener |
| customClass | string | '' | Custom class for the cookie consent banner |
| cookiePrefix | string | 'cookieconsent_' | Prefix for the cookie consent banner |
| cookieExpiryDays | number | 365 | Expiry days for the cookie consent banner |
| showCookieDetails | boolean | false | Show cookie details |
| showFunctionalCookies | boolean | true | Show functional cookies |
| functionalCookies | CookieItem[] | [] | Functional cookies |
| showMarketingCookies | boolean | true | Show marketing cookies |
| marketingCookies | CookieItem[] | [] | Marketing cookies |
| showEssentialCookies | boolean | true | Show essential cookies |
| essentialCookies | CookieItem[] | [] | Essential cookies |
| showOtherTools | boolean | true | Show other tools |
| otherTools | CookieItem[] | [] | Other tools |
| excludeRoutes | string[] | [] | Exclude routes eg. ['/privacy-policy'] |

### CustomLanguageConfig interface
| Name | Type | Description |
|----------------|------------------------------------------|-------------------------------------------------------------------------------------------|
| languageKey | string | Key for the custom language eg. 'custom' |
| languageName | string | Name for the custom language eg. 'Custom' |
| customIconPath | string | null | Path to the custom icon eg. 'assets/images/custom-icon.svg' |
| translations | translations: { [key: string]: string }; | Translations for the custom language as object please copy a example in languages folder. |


### CookieItem interface

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"karma-spec-reporter": "^0.0.36",
"ng-packagr": "^17.2.1",
"typescript": "~5.3.3"
}
},
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
}
56 changes: 33 additions & 23 deletions projects/ngx-cookie-consent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,39 @@ import { NgxCookieConsentModule } from '@localia/ngx-cookie-consent';

## Configuration

| Name | Type | Default | Description |
|-----------------------|----------------------------------|--------------------|------------------------------------------------------------------------------------|
| privacyPolicyUrl | string | TranslatableString | '#' | URL to your privacy policy ⚠ required ⚠ |
| imprintUrl | string | TranslatableString | '#' | URL to your imprint ⚠ required ⚠ |
| defaultLanguage | string | 'en' | Default language for the cookie consent banner |
| availableLanguages | string[] | ['en', 'de', 'it'] | Available languages for the cookie consent banner |
| showLanguageSwitcher | boolean | true | Show language switcher |
| showBadgeOpener | boolean | true | Show badge opener |
| openerPosition | enum | 'left-bottom' | Position of the badge eg. 'left-top', 'right-top' , 'left-bottom' , 'right-bottom' |
| customOpenerClass | string | '' | Custom class for the badge opener |
| customClass | string | '' | Custom class for the cookie consent banner |
| cookiePrefix | string | 'cookieconsent_' | Prefix for the cookie consent banner |
| cookieExpiryDays | number | 365 | Expiry days for the cookie consent banner |
| showCookieDetails | boolean | false | Show cookie details |
| showFunctionalCookies | boolean | true | Show functional cookies |
| functionalCookies | CookieItem[] | [] | Functional cookies |
| showMarketingCookies | boolean | true | Show marketing cookies |
| marketingCookies | CookieItem[] | [] | Marketing cookies |
| showEssentialCookies | boolean | true | Show essential cookies |
| essentialCookies | CookieItem[] | [] | Essential cookies |
| showOtherTools | boolean | true | Show other tools |
| otherTools | CookieItem[] | [] | Other tools |
| excludeRoutes | string[] | [] | Exclude routes eg. ['/privacy-policy'] |
| Name | Type | Default | Description |
|-----------------------|-----------------------------------|-------------------|------------------------------------------------------------------------------------|
| privacyPolicyUrl | string | TranslatableString | '#' | URL to your privacy policy ⚠ required ⚠ |
| imprintUrl | string | TranslatableString | '#' | URL to your imprint ⚠ required ⚠ |
| defaultLanguage | string | 'en' | Default language for the cookie consent banner |
| availableLanguages | string[] | ['en', 'de', 'it'] | Available languages for the cookie consent banner |
| customLanguage | CustomLanguageConfig | null | null | Custom language for the cookie consent banner |
| showLanguageSwitcher | boolean | true | Show language switcher |
| showBadgeOpener | boolean | true | Show badge opener |
| openerPosition | enum | 'left-bottom' | Position of the badge eg. 'left-top', 'right-top' , 'left-bottom' , 'right-bottom' |
| customOpenerClass | string | '' | Custom class for the badge opener |
| customClass | string | '' | Custom class for the cookie consent banner |
| cookiePrefix | string | 'cookieconsent_' | Prefix for the cookie consent banner |
| cookieExpiryDays | number | 365 | Expiry days for the cookie consent banner |
| showCookieDetails | boolean | false | Show cookie details |
| showFunctionalCookies | boolean | true | Show functional cookies |
| functionalCookies | CookieItem[] | [] | Functional cookies |
| showMarketingCookies | boolean | true | Show marketing cookies |
| marketingCookies | CookieItem[] | [] | Marketing cookies |
| showEssentialCookies | boolean | true | Show essential cookies |
| essentialCookies | CookieItem[] | [] | Essential cookies |
| showOtherTools | boolean | true | Show other tools |
| otherTools | CookieItem[] | [] | Other tools |
| excludeRoutes | string[] | [] | Exclude routes eg. ['/privacy-policy'] |

### CustomLanguageConfig interface
| Name | Type | Description |
|----------------|------------------------------------------|-------------------------------------------------------------------------------------------|
| languageKey | string | Key for the custom language eg. 'custom' |
| languageName | string | Name for the custom language eg. 'Custom' |
| customIconPath | string | null | Path to the custom icon eg. 'assets/images/custom-icon.svg' |
| translations | translations: { [key: string]: string }; | Translations for the custom language as object please copy a example in languages folder. |


### CookieItem interface

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-cookie-consent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@localia/ngx-cookie-consent",
"version": "2.2.0",
"version": "2.3.0",
"description": "Angular module to display a cookie consent banner without other dependencies.",
"author": "Giacomo Barbalinardo <me@giacomo.dev>",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface CustomLanguageConfig {
languageKey: string;
languageName: string;
customIconPath: string|null;
translations: { [key: string]: string };
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { CookieItem } from './cookie-item.interface';
import { TranslatableString } from './translatable-string.interface';
import { CustomLanguageConfig } from "./custom-language-config.interface";

@Injectable({
providedIn: 'root'
Expand All @@ -10,6 +11,7 @@ export class NgxCookieConsentConfigService {
imprintUrl?: string | TranslatableString = '#';
defaultLanguage?: string = 'en';
availableLanguages?: string[] = ['en', 'de', 'it', 'pt', 'fr'];
customLanguage?: CustomLanguageConfig|null = null;
showLanguageSwitcher?: boolean = true;
showBadgeOpener?: boolean = true;
openerPosition?: 'left-top' | 'right-top' | 'left-bottom' | 'right-bottom' = 'left-bottom';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
<i class="flag-icon flag-{{ lang }}"></i> {{ translate('language', lang) }}
</div>
</div>
<div class="dropdown__item" *ngIf="customLanguage"
[ngClass]="{'dropdown__item--active': activeLang === customLanguage.languageKey}">
<div class="dropdown__item_text" (click)="switchLanguage(customLanguage.languageKey)">
<i class="flag-icon flag-custom">
<img *ngIf="customLanguage.customIconPath" [src]="customLanguage.customIconPath" alt="{{ customLanguage.languageKey }}" width="34px" height="26px">
</i> {{ customLanguage.languageName }}
</div>
</div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 20c9325

Please sign in to comment.