Skip to content

Commit 9add368

Browse files
authored
Merge pull request #3625 from tdonohue/fix_klaro_translations_8x
Fix Klaro translations by forcing Klaro to use a zy language code that DSpace will translate
2 parents 8a6db0d + 6076423 commit 9add368

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/app/shared/cookies/browser-klaro.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('BrowserKlaroService', () => {
108108

109109
mockConfig = {
110110
translations: {
111-
zz: {
111+
zy: {
112112
purposes: {},
113113
test: {
114114
testeritis: testKey,
@@ -166,8 +166,8 @@ describe('BrowserKlaroService', () => {
166166

167167
it('addAppMessages', () => {
168168
service.addAppMessages();
169-
expect(mockConfig.translations.zz[appName]).toBeDefined();
170-
expect(mockConfig.translations.zz.purposes[purpose]).toBeDefined();
169+
expect(mockConfig.translations.zy[appName]).toBeDefined();
170+
expect(mockConfig.translations.zy.purposes[purpose]).toBeDefined();
171171
});
172172

173173
it('translateConfiguration', () => {

src/app/shared/cookies/browser-klaro.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class BrowserKlaroService extends KlaroService {
111111
initialize() {
112112
if (!environment.info.enablePrivacyStatement) {
113113
delete this.klaroConfig.privacyPolicy;
114-
this.klaroConfig.translations.zz.consentNotice.description = 'cookies.consent.content-notice.description.no-privacy';
114+
this.klaroConfig.translations.zy.consentNotice.description = 'cookies.consent.content-notice.description.no-privacy';
115115
}
116116

117117
const hideGoogleAnalytics$ = this.configService.findByPropertyName(this.GOOGLE_ANALYTICS_KEY).pipe(
@@ -258,12 +258,12 @@ export class BrowserKlaroService extends KlaroService {
258258
*/
259259
addAppMessages() {
260260
this.klaroConfig.services.forEach((app) => {
261-
this.klaroConfig.translations.zz[app.name] = {
261+
this.klaroConfig.translations.zy[app.name] = {
262262
title: this.getTitleTranslation(app.name),
263263
description: this.getDescriptionTranslation(app.name),
264264
};
265265
app.purposes.forEach((purpose) => {
266-
this.klaroConfig.translations.zz.purposes[purpose] = this.getPurposeTranslation(purpose);
266+
this.klaroConfig.translations.zy.purposes[purpose] = this.getPurposeTranslation(purpose);
267267
});
268268
});
269269
}
@@ -277,7 +277,7 @@ export class BrowserKlaroService extends KlaroService {
277277
*/
278278
this.translateService.setDefaultLang(environment.defaultLanguage);
279279

280-
this.translate(this.klaroConfig.translations.zz);
280+
this.translate(this.klaroConfig.translations.zy);
281281
}
282282

283283
/**

src/app/shared/cookies/klaro-configuration.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const GOOGLE_ANALYTICS_KLARO_KEY = 'google-analytics';
2323

2424
/**
2525
* Klaro configuration
26-
* For more information see https://kiprotect.com/docs/klaro/annotated-config
26+
* For more information see https://klaro.org/docs/integration/annotated-configuration
2727
*/
2828
export const klaroConfiguration: any = {
2929
storageName: ANONYMOUS_STORAGE_NAME_KLARO,
@@ -53,21 +53,30 @@ export const klaroConfiguration: any = {
5353

5454
htmlTexts: true,
5555

56+
/*
57+
Force Klaro to use our custom "zy" lang configs defined below.
58+
*/
59+
lang: 'zy',
60+
5661
/*
5762
You can overwrite existing translations and add translations for your app
5863
descriptions and purposes. See `src/translations/` for a full list of
5964
translations that can be overwritten:
60-
https://github.com/KIProtect/klaro/tree/master/src/translations
65+
https://github.com/klaro-org/klaro-js/tree/master/src/translations
6166
*/
6267
translations: {
6368
/*
64-
The `zz` key contains default translations that will be used as fallback values.
65-
This can e.g. be useful for defining a fallback privacy policy URL.
66-
FOR DSPACE: We use 'zz' to map to our own i18n translations for klaro, see
69+
For DSpace we use this custom 'zy' key to map to our own i18n translations for klaro, see
6770
translateConfiguration() in browser-klaro.service.ts. All the below i18n keys are specified
6871
in your /src/assets/i18n/*.json5 translation pack.
72+
This 'zy' key has no special meaning to Klaro & is not a valid language code. It just
73+
allows DSpace to override Klaro's own translations in favor of DSpace's i18n keys.
74+
NOTE: we do not use 'zz' as that has special meaning to Klaro and is ONLY used as a "fallback"
75+
if no other translations can be found within Klaro. Currently, a bug in Klaro means that
76+
'zz' is never used as there's no way to exclude translations:
77+
https://github.com/klaro-org/klaro-js/issues/515
6978
*/
70-
zz: {
79+
zy: {
7180
acceptAll: 'cookies.consent.accept-all',
7281
acceptSelected: 'cookies.consent.accept-selected',
7382
close: 'cookies.consent.close',

0 commit comments

Comments
 (0)