Skip to content

Commit

Permalink
fix: restrict moment.js locales to supported languages (#5207)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico authored Sep 21, 2023
1 parent 9be2045 commit 14091a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/5207.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
restrict moment.js locales to supported languages @mamico
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
"jest": "26.6.3",
"jest-environment-jsdom": "^26",
"jsonwebtoken": "9.0.0",
"moment-locales-webpack-plugin": "1.2.0",
"react-error-overlay": "6.0.9",
"react-is": "^16.13.1",
"release-it": "^16.1.3",
Expand Down
10 changes: 4 additions & 6 deletions razzle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const AddonConfigurationRegistry = require('./addon-registry');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

const fileLoaderFinder = makeLoaderFinder('file-loader');

Expand Down Expand Up @@ -133,12 +134,9 @@ const defaultModify = ({
}

config.plugins.unshift(
// restrict moment.js locales to en/de
// see https://github.com/jmblog/how-to-optimize-momentjs-with-webpack for details
new webpack.ContextReplacementPlugin(
/moment[/\\]locale$/,
new RegExp(Object.keys(languages).join('|')),
),
// restrict moment.js locales to supported languages
// see https://momentjs.com/docs/#/use-it/webpack/ for details
new MomentLocalesPlugin({ localesToKeep: Object.keys(languages) }),
new LodashModuleReplacementPlugin({
shorthands: true,
cloning: true,
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,7 @@ __metadata:
lodash-webpack-plugin: 0.11.6
mini-css-extract-plugin: 2.7.2
moment: 2.29.4
moment-locales-webpack-plugin: 1.2.0
object-assign: 4.1.1
pofile: 1.0.10
postcss: 8.4.13
Expand Down Expand Up @@ -16985,6 +16986,13 @@ __metadata:
languageName: node
linkType: hard

"lodash.difference@npm:^4.5.0":
version: 4.5.0
resolution: "lodash.difference@npm:4.5.0"
checksum: ecee276aa578f300e79350805a14a51be8d1f12b3c1389a19996d8ab516f814211a5f65c68331571ecdad96522b863ccc484b55504ce8c9947212a29f8857d5a
languageName: node
linkType: hard

"lodash.escaperegexp@npm:^4.1.2":
version: 4.1.2
resolution: "lodash.escaperegexp@npm:4.1.2"
Expand Down Expand Up @@ -17837,6 +17845,18 @@ __metadata:
languageName: node
linkType: hard

"moment-locales-webpack-plugin@npm:1.2.0":
version: 1.2.0
resolution: "moment-locales-webpack-plugin@npm:1.2.0"
dependencies:
lodash.difference: ^4.5.0
peerDependencies:
moment: ^2.8.0
webpack: ^1 || ^2 || ^3 || ^4 || ^5
checksum: bb5daebfc2f2bd0c003b9d576893531edc6ac3c884c77fc4c3a7c8d228340c9a26a5c7676c8e4505922eebb1309f2defbcf619a1706d7d7e579039690df2487b
languageName: node
linkType: hard

"moment@npm:2.29.4, moment@npm:2.x, moment@npm:>=1.6.0":
version: 2.29.4
resolution: "moment@npm:2.29.4"
Expand Down

2 comments on commit 14091a5

@tiberiuichim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this is fine. I wonder if it's relevant to making localized dates according to user's browser prefered language, which may be unconnected to Volto's translations.

@erral
Copy link
Member

@erral erral commented on 14091a5 Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this is fine. I wonder if it's relevant to making localized dates according to user's browser prefered language, which may be unconnected to Volto's translations.

I think it is not at all. I think that the dates shown in the interface should be connected to the language of the content.

Something similar happened in classic ui when the date-picker JS was removed and everything started relying on browsers' native translations:

plone/mockup#1328

Please sign in to comment.