@eeacms/volto-cca-policy 0.1.93 → 0.1.95

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 (36) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/babel.config.js +2 -1
  3. package/i18n.cjs +351 -0
  4. package/locales/de/LC_MESSAGES/volto.po +551 -0
  5. package/locales/eea.pot +18 -0
  6. package/locales/en/LC_MESSAGES/volto.po +551 -0
  7. package/locales/it/LC_MESSAGES/volto.po +551 -0
  8. package/locales/pl/LC_MESSAGES/volto.po +565 -0
  9. package/locales/ro/LC_MESSAGES/volto.po +551 -0
  10. package/locales/volto.pot +552 -1
  11. package/package.json +1 -1
  12. package/src/components/index.js +1 -0
  13. package/src/components/manage/Blocks/CaseStudyExplorer/CaseStudyFilters.jsx +14 -2
  14. package/src/components/manage/Blocks/CountryMapHeatIndex/Filter.jsx +44 -8
  15. package/src/components/manage/Blocks/FilterAceContent/FilterAceContentView.jsx +7 -2
  16. package/src/components/manage/Blocks/Listing/EventCardsListingView.jsx +54 -16
  17. package/src/components/manage/Blocks/Listing/OrganisationCardsListingView.jsx +21 -46
  18. package/src/components/theme/TranslationDisclaimer/TranslationDisclaimer.jsx +98 -0
  19. package/src/components/theme/Views/AdaptationOptionView.jsx +88 -26
  20. package/src/components/theme/Views/C3SIndicatorView.jsx +5 -1
  21. package/src/components/theme/Views/CaseStudyView.jsx +76 -17
  22. package/src/components/theme/Views/CcaEventView.jsx +5 -1
  23. package/src/components/theme/Views/DatabaseItemView.jsx +14 -4
  24. package/src/components/theme/Views/DatabaseItemView.test.jsx +10 -0
  25. package/src/components/theme/Views/EventView.jsx +12 -3
  26. package/src/components/theme/Views/NewsItemView.jsx +2 -0
  27. package/src/components/theme/Views/ProjectView.jsx +26 -6
  28. package/src/components/theme/Views/VideoView.jsx +5 -1
  29. package/src/customizations/volto/components/manage/UniversalLink/UniversalLink.jsx +7 -0
  30. package/src/customizations/volto/components/theme/View/DefaultView.jsx +6 -1
  31. package/src/helpers/ContentMetadata.jsx +119 -17
  32. package/src/helpers/ShareInfo.jsx +5 -1
  33. package/src/helpers/Utils.jsx +143 -26
  34. package/src/helpers/index.js +24 -2
  35. package/theme/elements/list.variables +9 -0
  36. package/theme/globals/views.less +34 -9
package/CHANGELOG.md CHANGED
@@ -4,6 +4,47 @@ 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.95](https://github.com/eea/volto-cca-policy/compare/0.1.94...0.1.95) - 14 March 2024
8
+
9
+ #### :house: Internal changes
10
+
11
+ - style(disclaimer): add margin on homepage [kreafox - [`f385465`](https://github.com/eea/volto-cca-policy/commit/f385465e395d69c9c5fa2464aa6bbddb919a63a2)]
12
+
13
+ #### :hammer_and_wrench: Others
14
+
15
+ - Don't crash when url is an array [Tiberiu Ichim - [`acf22b2`](https://github.com/eea/volto-cca-policy/commit/acf22b2aec3acb14f00167ec64c0f29975d995f2)]
16
+ ### [0.1.94](https://github.com/eea/volto-cca-policy/compare/0.1.93...0.1.94) - 13 March 2024
17
+
18
+ #### :rocket: New Features
19
+
20
+ - feat: add translation disclaimer [kreafox - [`5501cb3`](https://github.com/eea/volto-cca-policy/commit/5501cb38b127adc5b0b2a795339e2a9f3cff5fbb)]
21
+ - feat(views): add read more for long list of contributions [kreafox - [`d67099e`](https://github.com/eea/volto-cca-policy/commit/d67099eab657feea1b790108ea4a6a3406960773)]
22
+ - feat(views): add contributions link [kreafox - [`e0cad4c`](https://github.com/eea/volto-cca-policy/commit/e0cad4caaa42028a40fe01d698d88b4dda3bccfd)]
23
+
24
+ #### :nail_care: Enhancements
25
+
26
+ - change(lists): use List from semantic UI [kreafox - [`53ff919`](https://github.com/eea/volto-cca-policy/commit/53ff9196a608dffeb2cb6a6778b151383a44388b)]
27
+ - change(views) : show Observatory contributions [kreafox - [`c03fff4`](https://github.com/eea/volto-cca-policy/commit/c03fff408f73f0916ef10f7c7a56f96f71df567e)]
28
+
29
+ #### :house: Internal changes
30
+
31
+ - style(disclaimer): change color [kreafox - [`ded2a43`](https://github.com/eea/volto-cca-policy/commit/ded2a43270e30b9c948989875698cc9236b709df)]
32
+
33
+ #### :hammer_and_wrench: Others
34
+
35
+ - Refs #266914 - translate event view [Tripon Eugen - [`6f70578`](https://github.com/eea/volto-cca-policy/commit/6f70578b8f0e87204c5206c75cbd9c5859073ecd)]
36
+ - Add pl .po file [Tiberiu Ichim - [`0457389`](https://github.com/eea/volto-cca-policy/commit/0457389d0bd1e24a3d550dabaa67b4ccd16edbeb)]
37
+ - Refs #266914 - case study view and share your info [Tripon Eugen - [`86f6e38`](https://github.com/eea/volto-cca-policy/commit/86f6e3856b9bac49b858d2440d7a4c112749dfca)]
38
+ - Refs #266914 - view adaptation option [Tripon Eugen - [`0defa3e`](https://github.com/eea/volto-cca-policy/commit/0defa3e44f03057ae6e97cad083b9bac32180439)]
39
+ - Wip on i18n [Tiberiu Ichim - [`d6fbdef`](https://github.com/eea/volto-cca-policy/commit/d6fbdef18f8be50fbba0fc2e186b58f4cb875a2f)]
40
+ - Refs #266914 - translation wip [Tripon Eugen - [`1dbf724`](https://github.com/eea/volto-cca-policy/commit/1dbf724c78c86e5160c46b52c0f7ad9d4afcbc85)]
41
+ - Refs #266914 - translation wip content metadata tooltip [Tripon Eugen - [`49b9bba`](https://github.com/eea/volto-cca-policy/commit/49b9bba08060407becb9a17a9af08a1b4574a266)]
42
+ - Refs #266914 - translation wip [Tripon Eugen - [`70cf337`](https://github.com/eea/volto-cca-policy/commit/70cf337a04995c775d599feb33a5906914d0eff1)]
43
+ - Wip on i18n [Tiberiu Ichim - [`e380c2f`](https://github.com/eea/volto-cca-policy/commit/e380c2f55c1936a685b09b69396761b624a4788c)]
44
+ - WIP on i18n [Tiberiu Ichim - [`9534c85`](https://github.com/eea/volto-cca-policy/commit/9534c85ed2a195abffcc5f925f78b862563a8180)]
45
+ - WIP on i18n [Tiberiu Ichim - [`7bccdb2`](https://github.com/eea/volto-cca-policy/commit/7bccdb292722bc24f9ddd06882d1ada5dbfa8ecc)]
46
+ - test: update snapshots [kreafox - [`1121ab0`](https://github.com/eea/volto-cca-policy/commit/1121ab0a979be6a004042b3096bb534fa8c2e6e0)]
47
+ - test: update snapshots [kreafox - [`5c16fee`](https://github.com/eea/volto-cca-policy/commit/5c16fee32a7733fc83722f2f48a661fd982a7214)]
7
48
  ### [0.1.93](https://github.com/eea/volto-cca-policy/compare/0.1.92...0.1.93) - 8 March 2024
8
49
 
9
50
  #### :rocket: New Features
package/babel.config.js CHANGED
@@ -1,7 +1,8 @@
1
- module.exports = function (api) {
1
+ module.exports = function(api) {
2
2
  api.cache(true);
3
3
  const presets = ['razzle'];
4
4
  const plugins = [
5
+ '@babel/plugin-proposal-export-default-from',
5
6
  [
6
7
  'react-intl', // React Intl extractor, required for the whole i18n infrastructure to work
7
8
  {
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 };