-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle different locale #48
Conversation
PRO-5128 As a user I can import content that was exported from a locale with a different name into the current locale, or decide to cancel
Per discussion with stuart in PRO-5123 this is our interim solution, ready to build and unlock productivity for Michelin's team:
Acceptance Criteria See above novella. Cypress tests will have to be included in this. |
} | ||
if (notificationId) { | ||
self.apos.notification.dismiss(req, notificationId, 2000).catch(self.apos.util.error); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean job and notification only if existing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see /api/v1/@apostrophecms/import-export/clean-export
call in app.js below, no job nor notification is instantiated at this step, but we still want to remove the export path
@@ -194,7 +194,7 @@ export default { | |||
} | |||
}); | |||
} catch (error) { | |||
apos.notify(this.$t('aposImportExport:importCleanFailed'), { | |||
apos.notify('aposImportExport:importCleanFailed', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
({ docs, attachmentsInfo } = exportFile); | ||
exportPath = exportFile.exportPath; | ||
|
||
await self.cleanFile(exportFile.filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now clean the archive right after having extracted it so we don't have to think about removing it at several other places
@@ -342,20 +421,20 @@ module.exports = self => { | |||
} | |||
}, | |||
|
|||
async cleanFile(exportPath) { | |||
async cleanFile(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor change: cleanFile
also cleans the archive path
const differentDocsLocale = self.getFirstDifferentLocale(req, docs); | ||
const siteHasMultipleLocales = Object.keys(self.apos.i18n.locales).length > 1; | ||
|
||
// Re-write locale if `overrideLocale` param is passed-on from the import process | ||
// (i.e if the user chose "Yes") | ||
// or re-write locale automatically on a single-locale site | ||
if (differentDocsLocale && (!siteHasMultipleLocales || overrideLocale)) { | ||
self.rewriteDocsWithCurrentLocale(req, docs); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need to override the locale here!
@BoDonkey adding you as a reviewer since I edited the readme ;) |
CHANGELOG.md
Outdated
* Import nows detects if the locale found in the exported docs is different from the current site one. | ||
If the site has only one locale configured, then the docs are automatically re-written with the site locale. | ||
If the site has multiple locales configured, the user is given the possibility to abort the import or re-write the docs with the site locale. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Import nows detects if the locale found in the exported docs is different from the current site one. | |
If the site has only one locale configured, then the docs are automatically re-written with the site locale. | |
If the site has multiple locales configured, the user is given the possibility to abort the import or re-write the docs with the site locale. | |
* Import now detects if the locale found in the exported docs is different from the current site one. If the site has only one locale configured, then the docs are automatically re-written with the site locale. If the site has multiple locales configured, the user can abort the import or re-write the docs with the site locale. Note that this requires Apostrophe 3.60.0 or higher for proper functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BoDonkey removed the
whitespaces to make it single line
README.md
Outdated
Documents will automatically be re-written with the current site locale if only one locale is configured in the `@apostrophecms/i18n` module. | ||
|
||
If multiple locales are configured, the user is asked about aborting the import or continuing it: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documents will automatically be re-written with the current site locale if only one locale is configured in the `@apostrophecms/i18n` module. | |
If multiple locales are configured, the user is asked about aborting the import or continuing it: | |
Exported documents maintain their locale settings. If the locale during import differs from the export locale, and only one locale is configured in the @apostrophecms/i18n module, the documents will be automatically rewritten to align with the new import locale. | |
If multiple locales are set up, the user will be prompted to choose between canceling the import or proceeding with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some documentation changes. Code looks okay to me and works as expected. A "real" engineer might be able to find something that could use improvement. 😃
if (exportPath) { | ||
const filesData = await self.getFilesData(exportPath); | ||
|
||
({ docs, attachmentsInfo } = filesData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what means the fact that this method receives an exportPath? Does it mean that the gzip file has already been cleaned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gzip file is now cleaned as soon as it's extracted (cf. comment below)
This method is provided exportPath
when the user chooses Yes
(continue the import with the current locale), because is archive has already been extracted during the import
method first call.
It just early returned to display the confirmation modal.
So at the 2nd call, we simply give the method back the exportPath
so it knows where the files were extracted during the 1st call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few questions, but LGTM
|
||
// Re-write if user decided to continue the import (`overrideLocale` param sent) | ||
// or if the site has only one locale configured | ||
self.rewriteDocsWithCurrentLocale(req, docs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this method is called twice, another time with the confirmation to change locale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is called only during the 2nd call (when the user chooses Yes), see the early return above
}); | ||
} | ||
|
||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we agree that in this case the export file is cleaned from the import route directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it should be done at line 107, as in a "normal" case where no locale overriding is involved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the typo, please.
CHANGELOG.md
Outdated
@@ -2,6 +2,12 @@ | |||
|
|||
## UNRELEASED | |||
|
|||
### Adds | |||
|
|||
* Import nows detects if the locale found in the exported docs is different from the current site one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Import now..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BoDonkey done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
Import nows detects if the locale found in the exported docs is different from the current site one.
Note that the verification is done beforehand, meaning that no doc is imported yet when the user is asked about continuing or aborting the import.
Technically, when a locale is found different in the docs, if the site is configured with only one locale then the docs are automatically re-written with
req.locale
.However, if multiple locales are configured in the i18n module, then we stop the import and ask the user what we should do.
No
, the import is stopped and the export docs folder is deleted.Yes
, theimport
route is called again with a parameter forcing the re-writing of the docs locale withreq.locale
What are the specific steps to test this change?
On testbed or any a3 project, change the
modules/@apostrophecms/i18n/index.js
config to either have one or multiple locales.Export some docs in a locale and re-import them on another locale.
Yes
orNo
.What kind of change does this PR introduce?
(Check at least one)
Make sure the PR fulfills these requirements: