@eeacms/volto-cca-policy 0.1.94 → 0.1.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/i18n.cjs +351 -0
  3. package/locales/de/LC_MESSAGES/volto.po +3458 -168
  4. package/locales/eea.cca.pot +141 -0
  5. package/locales/eea.climateadapt.frontpage.pot +524 -0
  6. package/locales/eea.climateadapt.menu.pot +628 -0
  7. package/locales/eea.climateadapt.observatory.frontpage.pot +155 -0
  8. package/locales/eea.climateadapt.pot +2052 -0
  9. package/locales/en/LC_MESSAGES/volto.po +3398 -108
  10. package/locales/es/volto.po +3855 -0
  11. package/locales/fr/LC_MESSAGES/volto.po +3855 -0
  12. package/locales/it/LC_MESSAGES/volto.po +3410 -120
  13. package/locales/pl/LC_MESSAGES/volto.po +3458 -168
  14. package/locales/ro/LC_MESSAGES/volto.po +3398 -108
  15. package/locales/volto.pot +110 -110
  16. package/package.json +2 -1
  17. package/src/components/manage/Blocks/CollectionStatistics/CollectionStatsView.jsx +11 -6
  18. package/src/components/manage/Blocks/Listing/OrganisationCardsListingView.jsx +12 -8
  19. package/src/components/theme/LanguageSwitch.jsx +10 -1
  20. package/src/components/theme/TranslationDisclaimer/LanguagePreference.jsx +85 -0
  21. package/src/components/theme/TranslationDisclaimer/TranslationDisclaimer.jsx +68 -75
  22. package/src/components/theme/Views/CcaEventView.test.jsx +10 -0
  23. package/src/customizations/volto/components/manage/UniversalLink/UniversalLink.jsx +7 -0
  24. package/src/helpers/Constants.jsx +22 -0
  25. package/src/helpers/Utils.jsx +10 -8
  26. package/src/helpers/index.js +4 -4
  27. package/src/index.js +9 -0
  28. package/src/state.js +3 -0
  29. package/src/store/middleware.js +33 -0
  30. package/theme/globals/site.overrides +4 -0
  31. package/theme/globals/views.less +14 -0
  32. package/locales/eea.pot +0 -18
package/CHANGELOG.md CHANGED
@@ -4,6 +4,39 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [0.1.96](https://github.com/eea/volto-cca-policy/compare/0.1.95...0.1.96) - 19 March 2024
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: add language preference; improve redirect middleware [kreafox - [`f234df8`](https://github.com/eea/volto-cca-policy/commit/f234df8a6fdaa2452d52f111d6a23867500af5ec)]
12
+
13
+ #### :bug: Bug Fixes
14
+
15
+ - fix: don't show lang pref message on search pages [kreafox - [`4ac7219`](https://github.com/eea/volto-cca-policy/commit/4ac7219319e57591df0c14f190bc274394747b8a)]
16
+ - fix(merge): remove files [kreafox - [`8a5e900`](https://github.com/eea/volto-cca-policy/commit/8a5e900aec8f021ede09bc410d5103842181a474)]
17
+ - fix: warning messages; clear timeout [kreafox - [`ad5d86b`](https://github.com/eea/volto-cca-policy/commit/ad5d86b5020fe43185786200b1a41095358b0ca2)]
18
+ - fix: use UniversalLink [kreafox - [`b90a20f`](https://github.com/eea/volto-cca-policy/commit/b90a20fe8b90ec9c31feb16f84b1c84d3c6f65df)]
19
+
20
+ #### :nail_care: Enhancements
21
+
22
+ - change: update search query for contributions [kreafox - [`3adcee8`](https://github.com/eea/volto-cca-policy/commit/3adcee81ef6d8ecd5824ecea02d50572b70fd113)]
23
+ - change: improve redirect middleware [kreafox - [`3971cd2`](https://github.com/eea/volto-cca-policy/commit/3971cd2995d57fbb80a5e23eabd41251f14bcbf8)]
24
+
25
+ #### :hammer_and_wrench: Others
26
+
27
+ - test: update snapshots [kreafox - [`448fb35`](https://github.com/eea/volto-cca-policy/commit/448fb357c514f086d8a412f6dc02618a8dbc6278)]
28
+ - i18n stats block [Tiberiu Ichim - [`3dff196`](https://github.com/eea/volto-cca-policy/commit/3dff19612e3312d15b3dff3e1a2d80f0deebd779)]
29
+ - test: update snapshot [kreafox - [`e80e0c0`](https://github.com/eea/volto-cca-policy/commit/e80e0c030d7f12036a8a3ed4136a5868c31a5f2a)]
30
+ - WIP on redirect middleware [Tiberiu Ichim - [`4d18c23`](https://github.com/eea/volto-cca-policy/commit/4d18c234ae29824b1e946ad7adfad378b309cbbf)]
31
+ ### [0.1.95](https://github.com/eea/volto-cca-policy/compare/0.1.94...0.1.95) - 14 March 2024
32
+
33
+ #### :house: Internal changes
34
+
35
+ - style(disclaimer): add margin on homepage [kreafox - [`f385465`](https://github.com/eea/volto-cca-policy/commit/f385465e395d69c9c5fa2464aa6bbddb919a63a2)]
36
+
37
+ #### :hammer_and_wrench: Others
38
+
39
+ - Don't crash when url is an array [Tiberiu Ichim - [`acf22b2`](https://github.com/eea/volto-cca-policy/commit/acf22b2aec3acb14f00167ec64c0f29975d995f2)]
7
40
  ### [0.1.94](https://github.com/eea/volto-cca-policy/compare/0.1.93...0.1.94) - 13 March 2024
8
41
 
9
42
  #### :rocket: New Features
package/i18n.cjs ADDED
@@ -0,0 +1,351 @@
1
+ #!/usr/bin/env node
2
+ /* eslint no-console: 0 */
3
+ /**
4
+ * i18n script.
5
+ * @module scripts/i18n
6
+ */
7
+
8
+ const { find, keys, map, concat, reduce } = require('lodash');
9
+ const glob = require('glob').sync;
10
+ const fs = require('fs');
11
+ const Pofile = require('pofile');
12
+ const babel = require('@babel/core');
13
+
14
+ const path = require('path');
15
+ const projectRootPath = path.resolve('.');
16
+ const packageJson = require(path.join(projectRootPath, 'package.json'));
17
+
18
+ const { program } = require('commander');
19
+ const chalk = require('chalk');
20
+
21
+ /**
22
+ * Extract messages into separate JSON files
23
+ * @function extractMessages
24
+ * @return {undefined}
25
+ */
26
+ function extractMessages() {
27
+ map(
28
+ // We ignore the existing customized shadowed components ones, since most
29
+ // probably we won't be overriding them
30
+ // If so, we should do it in the config object or somewhere else
31
+ // We also ignore the addons folder since they are populated using
32
+ // their own locales files and taken care separatedly in this script
33
+ glob('src/**/*.{js,jsx,ts,tsx}', {
34
+ ignore: ['src/customizations/**', 'src/addons/**'],
35
+ }),
36
+ (filename) => {
37
+ babel.transformFileSync(filename, {}, (err) => {
38
+ if (err) {
39
+ console.log(err);
40
+ }
41
+ });
42
+ },
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Get messages from separate JSON files
48
+ * @function getMessages
49
+ * @return {Object} Object with messages
50
+ */
51
+ function getMessages() {
52
+ return reduce(
53
+ concat(
54
+ {},
55
+ ...map(
56
+ // We ignore the existing customized shadowed components ones, since most
57
+ // probably we won't be overriding them
58
+ // If so, we should do it in the config object or somewhere else
59
+ // We also ignore the addons folder since they are populated using
60
+ // their own locales files and taken care separatedly in this script
61
+ glob('build/messages/src/**/*.json', {
62
+ ignore: [
63
+ 'build/messages/src/customizations/**',
64
+ 'build/messages/src/addons/**',
65
+ ],
66
+ }),
67
+ (filename) =>
68
+ map(JSON.parse(fs.readFileSync(filename, 'utf8')), (message) => ({
69
+ ...message,
70
+ filename: filename.match(/build\/messages\/src\/(.*).json$/)[1],
71
+ })),
72
+ ),
73
+ ),
74
+ (current, value) => {
75
+ let result = current;
76
+ if (current.id) {
77
+ result = {
78
+ [current.id]: {
79
+ defaultMessage: current.defaultMessage,
80
+ filenames: [current.filename],
81
+ },
82
+ };
83
+ }
84
+
85
+ if (result[value.id]) {
86
+ result[value.id].filenames.push(value.filename);
87
+ } else {
88
+ result[value.id] = {
89
+ defaultMessage: value.defaultMessage,
90
+ filenames: [value.filename],
91
+ };
92
+ }
93
+ return result;
94
+ },
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Convert messages to pot format
100
+ * @function messagesToPot
101
+ * @param {Object} messages Messages
102
+ * @return {string} Formatted pot string
103
+ */
104
+ function messagesToPot(messages) {
105
+ return map(keys(messages).sort(), (key) =>
106
+ [
107
+ `#. Default: "${messages[key].defaultMessage.trim()}"`,
108
+ ...map(messages[key].filenames, (filename) => `#: ${filename}`),
109
+ `msgid "${key}"`,
110
+ 'msgstr ""',
111
+ ].join('\n'),
112
+ ).join('\n\n');
113
+ }
114
+
115
+ /**
116
+ * Pot header
117
+ * @function potHeader
118
+ * @return {string} Formatted pot header
119
+ */
120
+ function potHeader() {
121
+ return `msgid ""
122
+ msgstr ""
123
+ "Project-Id-Version: Plone\\n"
124
+ "POT-Creation-Date: ${new Date().toISOString()}\\n"
125
+ "Last-Translator: Plone i18n <plone-i18n@lists.sourceforge.net>\\n"
126
+ "Language-Team: Plone i18n <plone-i18n@lists.sourceforge.net>\\n"
127
+ "Content-Type: text/plain; charset=utf-8\\n"
128
+ "Content-Transfer-Encoding: 8bit\\n"
129
+ "Plural-Forms: nplurals=1; plural=0;\\n"
130
+ "MIME-Version: 1.0\\n"
131
+ "Language-Code: en\\n"
132
+ "Language-Name: English\\n"
133
+ "Preferred-Encodings: utf-8\\n"
134
+ "Domain: volto\\n"
135
+
136
+ `;
137
+ }
138
+
139
+ /**
140
+ * Convert po files into json
141
+ * @function poToJson
142
+ * @return {undefined}
143
+ */
144
+ function poToJson({ registry, addonMode }) {
145
+ const mergeMessages = (result, items, language) => {
146
+ items.forEach((item) => {
147
+ if (item.msgid in result) {
148
+ if (item.msgstr[0] !== '') {
149
+ result[item.msgid] = item.msgstr[0];
150
+ }
151
+ } else {
152
+ result[item.msgid] =
153
+ language === 'en'
154
+ ? item.msgstr[0] ||
155
+ (item.comments[0] && item.comments[0].startsWith('. Default: ')
156
+ ? item.comments[0].replace('. Default: ', '')
157
+ : item.comments[0] &&
158
+ item.comments[0].startsWith('defaultMessage:')
159
+ ? item.comments[0].replace('defaultMessage: ', '')
160
+ : '')
161
+ : item.msgstr[0];
162
+ }
163
+ });
164
+
165
+ return result;
166
+ };
167
+
168
+ map(glob('locales/**/*.po'), (filename) => {
169
+ let { items } = Pofile.parse(fs.readFileSync(filename, 'utf8'));
170
+ const projectLocalesItems = Pofile.parse(fs.readFileSync(filename, 'utf8'))
171
+ .items;
172
+ const lang = filename.match(/locales\/(.*)\/LC_MESSAGES\//)[1];
173
+ const result = {};
174
+
175
+ // Merge volto core locales
176
+ const lib = `node_modules/@plone/volto/${filename}`;
177
+ if (fs.existsSync(lib)) {
178
+ const libItems = Pofile.parse(fs.readFileSync(lib, 'utf8')).items;
179
+ items = [...libItems, ...items];
180
+ mergeMessages(result, items, lang);
181
+ }
182
+
183
+ if (!addonMode) {
184
+ // Merge addons locales
185
+ if (packageJson.addons) {
186
+ registry.getAddonDependencies().forEach((addon) => {
187
+ const addonlocale = `${registry.packages[addon].modulePath}/../${filename}`;
188
+ if (fs.existsSync(addonlocale)) {
189
+ const addonItems = Pofile.parse(
190
+ fs.readFileSync(addonlocale, 'utf8'),
191
+ ).items;
192
+
193
+ mergeMessages(result, addonItems, lang);
194
+ if (require.main === module) {
195
+ // We only log it if called as script
196
+ console.log(`Merging ${addon} locales for ${lang}`);
197
+ }
198
+ }
199
+ });
200
+ }
201
+ }
202
+ // Merge project locales, the project customization wins
203
+ mergeMessages(result, projectLocalesItems, lang);
204
+ fs.writeFileSync(`locales/${lang}.json`, JSON.stringify(result));
205
+ });
206
+ }
207
+
208
+ /**
209
+ * Format header
210
+ * @function formatHeader
211
+ * @param {Array} comments Array of comments
212
+ * @param {Object} headers Object of header items
213
+ * @return {string} Formatted header
214
+ */
215
+ function formatHeader(comments, headers) {
216
+ return [
217
+ ...map(comments, (comment) => `#. ${comment}`),
218
+ 'msgid ""',
219
+ 'msgstr ""',
220
+ ...map(keys(headers), (key) => `"${key}: ${headers[key]}\\n"`),
221
+ '',
222
+ ].join('\n');
223
+ }
224
+
225
+ /**
226
+ * Sync po by the pot file
227
+ * @function syncPoByPot
228
+ * @return {undefined}
229
+ */
230
+ function syncPoByPot() {
231
+ const pot = Pofile.parse(fs.readFileSync('locales/volto.pot', 'utf8'));
232
+ const msgIds = pot.items.map((a) => a.msgid);
233
+
234
+ const localeFiles = fs.readdirSync('./locales');
235
+ const extraPots = localeFiles.filter(
236
+ (filename) => filename.endsWith('.pot') && filename !== 'volto.pot',
237
+ );
238
+
239
+ extraPots.forEach((potFileName) => {
240
+ let extraPot = Pofile.parse(
241
+ fs.readFileSync('locales/' + potFileName, 'utf8'),
242
+ );
243
+ extraPot.items.forEach((item) => {
244
+ if (!msgIds.includes(item.msgid)) {
245
+ msgIds.push(item.msgid);
246
+ pot.items.push(item);
247
+ }
248
+ });
249
+ });
250
+
251
+ map(glob('locales/**/*.po'), (filename) => {
252
+ const po = Pofile.parse(fs.readFileSync(filename, 'utf8'));
253
+
254
+ fs.writeFileSync(
255
+ filename,
256
+ `${formatHeader(po.comments, po.headers)}
257
+ ${map(pot.items, (item) => {
258
+ const poItem = find(po.items, { msgid: item.msgid });
259
+ return [
260
+ `#. ${item.extractedComments[0]}`,
261
+ `${map(item.references, (ref) => `#: ${ref}`).join('\n')}`,
262
+ `msgid "${item.msgid}"`,
263
+ `msgstr "${poItem ? poItem.msgstr : ''}"`,
264
+ ].join('\n');
265
+ }).join('\n\n')}\n`,
266
+ );
267
+ });
268
+ }
269
+
270
+ function main({ addonMode }) {
271
+ console.log('Extracting messages from source files...');
272
+ extractMessages();
273
+ console.log('Synchronizing messages to pot file...');
274
+ // We only write the pot file if it's really different
275
+ const newPot = `${potHeader()}${messagesToPot(getMessages())}\n`.replace(
276
+ /"POT-Creation-Date:(.*)\\n"/,
277
+ '',
278
+ );
279
+ const oldPot = fs
280
+ .readFileSync('locales/volto.pot', 'utf8')
281
+ .replace(/"POT-Creation-Date:(.*)\\n"/, '');
282
+
283
+ if (newPot !== oldPot) {
284
+ fs.writeFileSync(
285
+ 'locales/volto.pot',
286
+ `${potHeader()}${messagesToPot(getMessages())}\n`,
287
+ );
288
+ }
289
+ console.log('Synchronizing messages to po files...');
290
+ syncPoByPot();
291
+ if (!addonMode) {
292
+ let AddonConfigurationRegistry;
293
+ try {
294
+ // Detect where is the registry (if we are in Volto 18 or above for either core and projects)
295
+ if (
296
+ fs.existsSync(
297
+ path.join(
298
+ projectRootPath,
299
+ '/node_modules/@plone/registry/src/addon-registry.js',
300
+ ),
301
+ )
302
+ ) {
303
+ AddonConfigurationRegistry = require(path.join(
304
+ projectRootPath,
305
+ '/node_modules/@plone/registry/src/addon-registry',
306
+ ));
307
+ } else {
308
+ // We are in Volto 17 or below
309
+ // Check if core Volto or project
310
+ if (
311
+ fs.existsSync(
312
+ path.join(projectRootPath, '/node_modules/@plone/volto'),
313
+ )
314
+ ) {
315
+ // We are in a project
316
+ AddonConfigurationRegistry = require(path.join(
317
+ projectRootPath,
318
+ '/node_modules/@plone/volto/addon-registry',
319
+ ));
320
+ } else {
321
+ // We are in core (17 or below)
322
+ AddonConfigurationRegistry = require(path.join(
323
+ projectRootPath,
324
+ 'addon-registry',
325
+ ));
326
+ }
327
+ }
328
+ } catch {
329
+ console.log(
330
+ chalk.red(
331
+ 'Getting the addon registry failed. Are you executing i18n from inside an addon? Try the -a flag.',
332
+ ),
333
+ );
334
+ process.exit();
335
+ }
336
+ console.log('Generating the language JSON files...');
337
+ const registry = new AddonConfigurationRegistry(projectRootPath);
338
+ poToJson({ registry, addonMode });
339
+ }
340
+ console.log('done!');
341
+ }
342
+
343
+ // This is the equivalent of `if __name__ == '__main__'` in Python :)
344
+ if (require.main === module) {
345
+ program.option('-a, --addon', 'run i18n script for addons');
346
+ program.parse(process.argv);
347
+ const options = program.opts();
348
+ main({ addonMode: options.addon });
349
+ }
350
+
351
+ module.exports = { poToJson };