Repository navigation
fix: allow partial I18N instances for Upload - #1906
Conversation
| // Assign new I18N object to WC, by deeply merging the existing | ||
| // WC I18N, and the values from the new UploadI18N instance, | ||
| // into an empty object | ||
| getElement().executeJs( | ||
| "const dropFiles = Object.assign({}, this.i18n.dropFiles, $0.dropFiles);" | ||
| + "const addFiles = Object.assign({}, this.i18n.addFiles, $0.addFiles);" | ||
| + "const error = Object.assign({}, this.i18n.error, $0.error);" | ||
| + "const uploadingStatus = Object.assign({}, this.i18n.uploading.status, $0.uploading && $0.uploading.status);" | ||
| + "const uploadingRemainingTime = Object.assign({}, this.i18n.uploading.remainingTime, $0.uploading && $0.uploading.remainingTime);" | ||
| + "const uploadingError = Object.assign({}, this.i18n.uploading.error, $0.uploading && $0.uploading.error);" | ||
| + "const uploading = {" | ||
| + " status: uploadingStatus," | ||
| + " remainingTime: uploadingRemainingTime," | ||
| + " error: uploadingError," + "};" | ||
| + "const units = $0.units || this.i18n.units;" | ||
| + "this.i18n = Object.assign({}, this.i18n, $0, {" | ||
| + " addFiles: addFiles," | ||
| + " dropFiles: dropFiles," | ||
| + " uploading: uploading," + " units: units," | ||
| + "});", | ||
| i18nJson); |
There was a problem hiding this comment.
Couldn't identify an easier / safer way to do a deep merge. Considered:
- importing a merge function from a library like lodash - that might have too big of an impact for this change alone
- copying a merge function from Github / SO - might have bugs or not work as expected in this use case (e.g. merging
unitsarray). Also would be terrible to put such a complex function inline into the Java code - introducing new API to the web component - probably won't happen
Still, I'm open for other ideas on improving this. I tried to make the tests rather extensive to make up for this.
Note that the units array is not merged. If the UploadI18N config specifies one, it will always replace the one from the web component, even if the number of elements don't match. However that is the same behaviour as we have today.
sosa-vaadin
left a comment
There was a problem hiding this comment.
I can only consider using StringBuilder where there's a ton of concatenation. I don't see any major problems with this though.
|
SonarQube analysis reported 21 issues Top 10 issues
|
* fix: allow partial I18N instances for Upload * fix code style issues
* fix: allow partial I18N instances for Upload * fix code style issues
* fix: allow partial I18N instances for Upload * fix code style issues
* fix: allow partial I18N instances for Upload * fix code style issues
|
This ticket/PR has been released with platform 22.0.0.alpha1 and is also targeting the upcoming stable 22.0.0 version. |



Description
Currently the I18N feature of the Upload component only works when setting a fully specified
UploadI18Ninstance. Just overriding a single label like this:does not work, because it results in null values being set in the web components I18N config, which in turn results in null reference errors.
This change fixes that by:
Fixes: No related issue
Type of change
Checklist