Skip to content

Commit

Permalink
Merge pull request #4040 from jyhein/f5000_7431
Browse files Browse the repository at this point in the history
Submission and metadata languages separated from UI and form languages
  • Loading branch information
bozana authored Mar 21, 2024
2 parents c34bef3 + d8b4ce6 commit afcf029
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 52 deletions.
4 changes: 2 additions & 2 deletions classes/issue/IssueGalley.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function isPdfGalley()
public function getGalleyLabel()
{
$label = $this->getLabel();
if ($this->getLocale() != Locale::getLocale()) {
$label .= ' (' . Locale::getMetadata($this->getLocale())->getDisplayName() . ')';
if (($locale = $this->getLocale()) && $locale !== Locale::getLocale()) {
$label .= ' (' . Locale::getSubmissionLocaleDisplayNames([$locale])[$locale] . ')';
}
return $label;
}
Expand Down
4 changes: 2 additions & 2 deletions classes/migration/install/JournalsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function up(): void
$table->bigInteger('journal_id')->autoIncrement();
$table->string('path', 32);
$table->float('seq', 8, 2)->default(0)->comment('Used to order lists of journals');
$table->string('primary_locale', 14);
$table->string('primary_locale', 28);
$table->smallInteger('enabled')->default(1)->comment('Controls whether or not the journal is considered "live" and will appear on the website. (Note that disabled journals may still be accessible, but only if the user knows the URL.)');
$table->unique(['path'], 'journals_path');
$table->bigInteger('current_issue_id')->nullable()->default(null);
Expand All @@ -45,7 +45,7 @@ public function up(): void
$table->foreign('journal_id', 'journal_settings_journal_id')->references('journal_id')->on('journals')->onDelete('cascade');
$table->index(['journal_id'], 'journal_settings_journal_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

Expand Down
14 changes: 7 additions & 7 deletions classes/migration/install/OJSMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function up(): void
$table->foreign('section_id', 'section_settings_section_id')->references('section_id')->on('sections')->onDelete('cascade');
$table->index(['section_id'], 'section_settings_section_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

Expand Down Expand Up @@ -107,7 +107,7 @@ public function up(): void
$table->foreign('issue_id', 'issue_settings_issue_id')->references('issue_id')->on('issues')->onDelete('cascade');
$table->index(['issue_id'], 'issue_settings_issue_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

Expand Down Expand Up @@ -143,7 +143,7 @@ public function up(): void
$table->comment('Issue galleys are representations of the entire issue in a single file, such as a complete issue PDF.');
$table->bigInteger('galley_id')->autoIncrement();

$table->string('locale', 14)->nullable();
$table->string('locale', 28)->nullable();

$table->bigInteger('issue_id');
$table->foreign('issue_id', 'issue_galleys_issue_id')->references('issue_id')->on('issues')->onDelete('cascade');
Expand All @@ -169,7 +169,7 @@ public function up(): void
$table->foreign('galley_id', 'issue_galleys_settings_galley_id')->references('galley_id')->on('issue_galleys')->onDelete('cascade');
$table->index(['galley_id'], 'issue_galley_settings_galley_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();
$table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
Expand Down Expand Up @@ -262,7 +262,7 @@ public function up(): void
Schema::create('publication_galleys', function (Blueprint $table) {
$table->comment('Publication galleys are representations of a publication in a specific format, e.g. a PDF.');
$table->bigInteger('galley_id')->autoIncrement();
$table->string('locale', 14)->nullable();
$table->string('locale', 28)->nullable();

$table->bigInteger('publication_id');
$table->foreign('publication_id', 'publication_galleys_publication_id')->references('publication_id')->on('publications')->onDelete('cascade');
Expand Down Expand Up @@ -295,7 +295,7 @@ public function up(): void
$table->foreign('galley_id', 'publication_galley_settings_galley_id')->references('galley_id')->on('publication_galleys')->onDelete('cascade');
$table->index(['galley_id'], 'publication_galley_settings_galley_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

Expand Down Expand Up @@ -337,7 +337,7 @@ public function up(): void
$table->foreign('type_id', 'subscription_type_settings_type_id')->references('type_id')->on('subscription_types')->onDelete('cascade');
$table->index(['type_id'], 'subscription_type_settings_type_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();
$table->string('setting_type', 6);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I9425_SeparateUIAndSubmissionLocales
*
* @brief pkp/pkp-lib#9425 Make submission language selection and metadata forms independent from website language settings
*/

namespace APP\migration\upgrade\v3_5_0;

class I9425_SeparateUIAndSubmissionLocales extends \PKP\migration\upgrade\v3_5_0\I9425_SeparateUIAndSubmissionLocales
{
protected function getContextTable(): string
{
return 'journals';
}
protected function getContextSettingsTable(): string
{
return 'journal_settings';
}
protected function getContextIdColumn(): string
{
return 'journal_id';
}
}
11 changes: 5 additions & 6 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function getCollector(): Collector
public function validate($publication, array $props, Submission $submission, Context $context): array
{
$errors = parent::validate($publication, $props, $submission, $context);

$allowedLocales = $context->getSupportedSubmissionLocales();
$primaryLocale = $submission->getData('locale');
$submissionLocale = $submission->getData('locale');

// Ensure that the specified section exists
$section = null;
Expand All @@ -62,21 +60,22 @@ public function validate($publication, array $props, Submission $submission, Con
if ($section && !$submission->getData('submissionProgress')) {
// Require abstracts for new publications if the section requires them
if (is_null($publication) && !$section->getData('abstractsNotRequired') && empty($props['abstract'])) {
$errors['abstract'][$primaryLocale] = [__('author.submit.form.abstractRequired')];
$errors['abstract'][$submissionLocale] = [__('author.submit.form.abstractRequired')];
}

if (isset($props['abstract']) && empty($errors['abstract'])) {
// Require abstracts in the primary language if the section requires them
if (!$section->getData('abstractsNotRequired')) {
if (empty($props['abstract'][$primaryLocale])) {
if (empty($props['abstract'][$submissionLocale])) {
if (!isset($errors['abstract'])) {
$errors['abstract'] = [];
};
$errors['abstract'][$primaryLocale] = [__('author.submit.form.abstractRequired')];
$errors['abstract'][$submissionLocale] = [__('author.submit.form.abstractRequired')];
}
}

// Check the word count on abstracts
$allowedLocales = $submission->getPublicationLanguages($context->getSupportedSubmissionMetadataLocales());
foreach ($allowedLocales as $localeKey) {
if (empty($props['abstract'][$localeKey])) {
continue;
Expand Down
4 changes: 3 additions & 1 deletion classes/publication/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ protected function mapByProperties(array $props, Publication $publication, bool
);
}

$output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $this->context->getSupportedSubmissionLocales());
$locales = $this->submission->getPublicationLanguages($this->context->getSupportedSubmissionMetadataLocales());

$output = $this->schemaService->addMissingMultilingualValues(PKPSchemaService::SCHEMA_PUBLICATION, $output, $locales);

ksort($output);

Expand Down
3 changes: 2 additions & 1 deletion classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function validateSubmit(Submission $submission, Context $context): array
$abstracts = $publication->getData('abstract');
if ($abstracts) {
$abstractErrors = [];
foreach ($context->getSupportedSubmissionLocales() as $localeKey) {
$allowedLocales = $submission->getPublicationLanguages($context->getSupportedSubmissionMetadataLocales());
foreach ($allowedLocales as $localeKey) {
$abstract = $publication->getData('abstract', $localeKey);
$wordCount = $abstract ? PKPString::getWordCount($abstract) : 0;
if ($wordCount > $section->getAbstractWordCount()) {
Expand Down
8 changes: 7 additions & 1 deletion classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ protected function mapByProperties(array $props, Submission $submission): array
);
}

$output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $this->context->getSupportedSubmissionLocales());
$locales = $this->context->getSupportedSubmissionMetadataLocales();

if (!in_array($primaryLocale = $submission->getData('locale'), $locales)) {
$locales[] = $primaryLocale;
}

$output = $this->schemaService->addMissingMultilingualValues($this->schemaService::SCHEMA_SUBMISSION, $output, $locales);

ksort($output);

Expand Down
19 changes: 10 additions & 9 deletions controllers/grid/articleGalleys/form/ArticleGalleyForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ public function __construct($request, $submission, $publication, $articleGalley
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));

// Ensure a locale is provided and valid
$journal = $request->getJournal();
$locales = $submission->getPublicationLanguages($request->getJournal()->getSupportedSubmissionMetadataLocales(), $articleGalley?->getLanguages());
$this->addCheck(
new \PKP\form\validation\FormValidator(
new \PKP\form\validation\FormValidatorCustom(
$this,
'locale',
'required',
'editor.issues.galleyLocaleRequired'
),
function ($locale) use ($journal) {
return in_array($locale, $journal->getSupportedSubmissionLocaleNames());
}
'editor.issues.galleyLocaleRequired',
fn ($locale) => in_array($locale, $locales)
)
);
}

Expand All @@ -93,9 +91,12 @@ public function fetch($request, $template = null, $display = false)
'supportsDependentFiles' => $articleGalleyFile ? Repo::submissionFile()->supportsDependentFiles($articleGalleyFile) : null,
]);
}
$context = $request->getContext();

$supportedLocales = $request->getContext()->getSupportedSubmissionMetadataLocaleNames() + $this->_submission->getPublicationLanguageNames() + ($this->_articleGalley?->getLanguageNames() ?? []);
ksort($supportedLocales);

$templateMgr->assign([
'supportedLocales' => $context->getSupportedSubmissionLocaleNames(),
'supportedLocales' => $supportedLocales,
'submissionId' => $this->_submission->getId(),
'publicationId' => $this->_publication->getId(),
'formDisabled' => !$this->_isEditable
Expand Down
9 changes: 7 additions & 2 deletions cypress/tests/data/10-ApplicationSetup/20-CreateContext.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ describe('Data suite tests', function() {
cy.get('#appearance [role="status"]').contains('Saved');

cy.get('button[id="languages-button"]').click();
cy.get('input[id^=select-cell-fr_CA-submissionLocale]').click();
cy.contains('Locale settings saved.');
cy.get('input[id^="select-cell-fr_CA-formLocale"]').click();
cy.get('a[id^=component-grid-settings-languages-submissionlanguagegrid-addLanguageModal-button]').click();
cy.get('#locale-fr_CA').should('exist').click();
cy.get('#addLanguageForm button[name="submitFormButton"]').click();
cy.contains('Submission locales updated.').should('exist');
cy.get('input[id^="select-cell-fr_CA-submissionLocale"]').click();
cy.get('input[id^="select-cell-fr_CA-submissionMetadataLocale"]').should('be.checked');

cy.get('button[id="indexing-button"]').click();
cy.get('input[name="searchDescription-en"]').type(Cypress.env('contextDescriptions')['en'], {delay: 0});
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/data/60-content/AmwandengaSubmission.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('Data suite: Amwandenga', function() {
.find('h4').contains('Keywords').siblings('.submissionWizard__reviewPanel__item__value').contains('None provided')
.parents('.submissionWizard__reviewPanel')
.find('h4').contains('Abstract').siblings('.submissionWizard__reviewPanel__item__value').contains(submission.abstract);
cy.get('h3').contains('Details (French)')
cy.get('h3').contains('Details (French (Canada))')
.parents('.submissionWizard__reviewPanel')
.find('h4').contains('Title').siblings('.submissionWizard__reviewPanel__item__value').contains('None provided')
.parents('.submissionWizard__reviewPanel')
Expand All @@ -234,7 +234,7 @@ describe('Data suite: Amwandenga', function() {
cy.get('h3').contains('For the Editors (English)')
.parents('.submissionWizard__reviewPanel')
.find('h4').contains('Comments for the Editor').siblings('.submissionWizard__reviewPanel__item__value').contains('None');
cy.get('h3').contains('For the Editors (French)') // FIXME: Should be French
cy.get('h3').contains('For the Editors (French (Canada))')

// Save for later
cy.get('button').contains('Save for Later').click();
Expand Down
22 changes: 11 additions & 11 deletions cypress/tests/integration/SubmissionWizard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,20 @@ describe('Submission Wizard', function() {
cy.get('label:contains("Abstract *")');
cy.contains('Word Count: 0/500');

// Change submission language to French and section to Reviews
// Change submission language to French (Canada) and section to Reviews
cy.contains('Submitting to the Articles section in English');
cy.get('button:contains("Change")').click();
cy.get('h2:contains("Change Submission Settings")')
.parents('.modal')
.within(() => {
cy.get('label:contains("French")').click();
cy.get('label:contains("French (Canada)")').click();
cy.get('label:contains("Reviews")').click();
cy.get('button:contains("Save")').click();
});

// Forms load with French fields displayed instead of English
cy.contains('Submitting to the Reviews section in French');
cy.get('span.pkpFormLocales__locale:contains("French")');
// Forms load with French (Canada) fields displayed instead of English
cy.contains('Submitting to the Reviews section in French (Canada)');
cy.get('span.pkpFormLocales__locale:contains("French (Canada)")');
cy.get('#titleAbstract-keywords-control-fr_CA').type('Transformation Sociale', {delay: 0});
cy.get('li:contains("Transformation Sociale")');
cy.get('#titleAbstract-keywords-control-fr_CA').type('{downarrow}{enter}', {delay: 0});
Expand All @@ -502,7 +502,7 @@ describe('Submission Wizard', function() {
cy.get('label:contains("Abstract *")').should('not.exist');
cy.get('*:contains("Word Count: 0/500")').should('not.exist');

// Show English fields alongside French fields
// Show English fields alongside French (Canada) fields
cy.get('.pkpStep:contains("Submission Details") button.pkpFormLocales__locale:contains("English")').click();
cy.get('label:contains("Title in English")');
cy.get('label:contains("Keywords in English")');
Expand All @@ -523,7 +523,7 @@ describe('Submission Wizard', function() {
cy.get('button:contains("Continue")').click();
cy.get('button:contains("Continue")').click();

// Check metadata form shows in French only at first
// Check metadata form shows in French (Canada) only at first
const metadata = {
subjects: "Subjects",
disciplines: "Disciplines",
Expand All @@ -539,7 +539,7 @@ describe('Submission Wizard', function() {
cy.get('label:contains("' + metadata[prop] + ' in English")').should('not.be.visible');
});

// Show English fields alongside French fields
// Show English fields alongside French (Canada) fields
cy.get('.pkpStep:contains("For the Editors") button.pkpFormLocales__locale:contains("English")').click();
Object.keys(metadata).forEach((prop) => {
cy.get('label:contains("' + metadata[prop] + ' in English")');
Expand All @@ -551,13 +551,13 @@ describe('Submission Wizard', function() {
// Errors in review
cy.get('button:contains("Continue")').click();
cy.contains('There are one or more problems');
cy.get('h3:contains("Details (French)")')
cy.get('h3:contains("Details (French (Canada))")')
.parents('.submissionWizard__reviewPanel')
.find('h4:contains("Title")')
.parent()
.contains('This field is required.');
cy.contains('The given name is missing in French for one or more of the contributors.');
cy.get('h3:contains("For the Editors (French)")')
cy.contains('The given name is missing in French (Canada) for one or more of the contributors.');
cy.get('h3:contains("For the Editors (French (Canada))")')
.parents('.submissionWizard__reviewPanel')
.find('h4:contains("Subjects")')
.parent()
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<migration class="APP\migration\upgrade\v3_5_0\I9475_RecoverLayoutFiles"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9462_UserUserGroups"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9552_UserGroupsMasthead"/>
<migration class="APP\migration\upgrade\v3_5_0\I9425_SeparateUIAndSubmissionLocales"/>
</upgrade>

<!-- update plugin configuration - should be done as the final upgrade task -->
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Submodule pkp updated 60 files
+8 −8 api/v1/submissions/PKPSubmissionFileController.php
+3 −1 api/v1/vocabs/PKPVocabController.php
+1 −1 classes/author/Repository.php
+3 −1 classes/author/maps/Schema.php
+8 −6 classes/components/listPanels/ContributorsListPanel.php
+28 −0 classes/config/Config.php
+51 −6 classes/context/Context.php
+14 −0 classes/core/DataObject.php
+40 −0 classes/dev/ComposerScript.php
+29 −2 classes/galley/Galley.php
+3 −1 classes/galley/maps/Schema.php
+71 −0 classes/i18n/Locale.php
+6 −0 classes/i18n/interfaces/LocaleInterface.php
+2 −2 classes/migration/install/AnnouncementsMigration.php
+1 −1 classes/migration/install/CategoriesMigration.php
+6 −6 classes/migration/install/CommonMigration.php
+1 −1 classes/migration/install/ControlledVocabMigration.php
+1 −1 classes/migration/install/DoiMigration.php
+1 −1 classes/migration/install/GenresMigration.php
+1 −1 classes/migration/install/HighlightsMigration.php
+1 −1 classes/migration/install/InstitutionsMigration.php
+1 −1 classes/migration/install/LibraryFilesMigration.php
+1 −1 classes/migration/install/LogMigration.php
+2 −2 classes/migration/install/MetadataMigration.php
+2 −2 classes/migration/install/NavigationMenusMigration.php
+2 −2 classes/migration/install/ReviewFormsMigration.php
+1 −1 classes/migration/install/RolesAndUserGroupsMigration.php
+1 −1 classes/migration/install/SubmissionFilesMigration.php
+4 −4 classes/migration/install/SubmissionsMigration.php
+1 −1 classes/migration/install/TombstoneMigration.php
+131 −0 classes/migration/upgrade/v3_5_0/I9425_SeparateUIAndSubmissionLocales.php
+8 −0 classes/observers/listeners/SendSubmissionAcknowledgement.php
+40 −0 classes/publication/PKPPublication.php
+4 −4 classes/publication/Repository.php
+12 −1 classes/services/PKPContextService.php
+27 −0 classes/submission/PKPSubmission.php
+7 −3 classes/submission/Repository.php
+5 −5 classes/submissionFile/Repository.php
+28 −0 classes/submissionFile/SubmissionFile.php
+3 −1 classes/submissionFile/maps/Schema.php
+8 −8 classes/template/PKPTemplateManager.php
+6 −2 composer.json
+3 −2 controllers/grid/admin/languages/AdminLanguageGridHandler.php
+21 −0 controllers/grid/languages/LanguageGridCellProvider.php
+90 −48 controllers/grid/languages/LanguageGridHandler.php
+131 −0 controllers/grid/languages/form/AddLanguageForm.php
+4 −1 controllers/grid/settings/languages/ManageLanguageGridHandler.php
+152 −0 controllers/grid/settings/languages/SubmissionLanguageGridHandler.php
+2 −1 controllers/wizard/fileUpload/FileUploadWizardHandler.php
+9 −2 controllers/wizard/fileUpload/form/SubmissionFilesMetadataForm.php
+24 −0 locale/en/manager.po
+36 −8 pages/authorDashboard/PKPAuthorDashboardHandler.php
+24 −28 pages/submission/PKPSubmissionHandler.php
+38 −9 pages/workflow/PKPWorkflowHandler.php
+25 −1 schemas/context.json
+1 −1 schemas/submission.json
+2 −0 templates/admin/contextSettings.tpl
+1 −1 templates/admin/systemInfo.tpl
+35 −0 templates/controllers/grid/languages/addLanguageForm.tpl
+2 −0 templates/management/website.tpl
4 changes: 2 additions & 2 deletions pages/submission/SubmissionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function getSubmittingTo(Context $context, Submission $submission, arr
'submission.wizard.submittingToSectionInLanguage',
[
'section' => $section->getLocalizedTitle(),
'language' => Locale::getMetadata($submission->getData('locale'))->getDisplayName(),
'language' => Locale::getSubmissionLocaleDisplayNames([$submission->getData('locale')])[$submission->getData('locale')],
]
);
} elseif ($sectionCount) {
Expand All @@ -108,7 +108,7 @@ protected function getSubmittingTo(Context $context, Submission $submission, arr
return __(
'submission.wizard.submittingInLanguage',
[
'language' => Locale::getMetadata($submission->getData('locale'))->getDisplayName(),
'language' => Locale::getSubmissionLocaleDisplayNames([$submission->getData('locale')])[$submission->getData('locale')],
]
);
}
Expand Down
Loading

0 comments on commit afcf029

Please sign in to comment.