Skip to content

Commit

Permalink
Make submission language selection and metadata forms independent fro…
Browse files Browse the repository at this point in the history
…m website language settings
  • Loading branch information
jyhein committed Feb 19, 2024
1 parent 6433db4 commit fa0dbc6
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 58 deletions.
9 changes: 4 additions & 5 deletions classes/dev/ComposerScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ public static function weblateFilesDownload(): void
{
try {
$dirPath = dirname(__FILE__, 3) . "/lib/weblateLanguages";
$urlCsvFilePath = "$dirPath/urlCsv.txt";
$langFilePath = "$dirPath/languages.json";

$urlCsv = !file_exists($urlCsvFilePath) ?: file_get_contents($urlCsvFilePath);
if (!is_string($urlCsv)) {
throw new Exception(__METHOD__ . " : File $urlCsvFilePath does not exist !");
$urlCsv = 'https://raw.githubusercontent.com/WeblateOrg/language-data/main/languages.csv';

if (!is_dir($dirPath)) {
mkdir($dirPath);
}

$streamContext = stream_context_create(['http' => ['method' => 'HEAD']]);
Expand Down
9 changes: 6 additions & 3 deletions classes/i18n/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Locale implements LocaleInterface
/** Max lifetime for the locale metadata cache, the cache is built by scanning the provided paths */
protected const MAX_CACHE_LIFETIME = '1 hour';

/** @var string Max lifetime for the submission locales cache. */
protected const MAX_SUBMISSION_LOCALES_CACHE_LIFETIME = '1 year';

/**
* @var callable Formatter for missing locale keys
* Receives the locale key and must return a string
Expand Down Expand Up @@ -566,15 +569,15 @@ private function _getSubmissionLocaleNames(): array
{
return $this->submissionLocaleNames ??= (function (): array {
$file = Core::getBaseDir() . '/' . PKP_LIB_PATH . '/lib/weblateLanguages/languages.json';
$key = __METHOD__ . self::MAX_CACHE_LIFETIME . sha1($file);
$expiration = DateInterval::createFromDateString(static::MAX_CACHE_LIFETIME);
$key = __METHOD__ . self::MAX_SUBMISSION_LOCALES_CACHE_LIFETIME . filemtime($file);
$expiration = DateInterval::createFromDateString(self::MAX_SUBMISSION_LOCALES_CACHE_LIFETIME);
return Cache::remember($key, $expiration, fn (): array => collect($this->getLocales())
->map(function (LocaleMetadata $lm, string $l): string {
$cl = $this->convertSubmissionLocaleCode($l);
$n = locale_get_display_name($cl, 'en');
return ($n && $n !== $cl) ? $n : $lm->getDisplayName('en', true);
})
->merge(json_decode(file_get_contents($file), true) ?: [])
->merge(json_decode(file_get_contents($file) ?: [], true) ?: [])
->sortKeys()
->toArray());
})();
Expand Down
2 changes: 1 addition & 1 deletion classes/i18n/interfaces/LocaleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface LocaleInterface extends \Illuminate\Contracts\Translation\Translator

/** Regular expression to validate and extract pieces of a locale code */
public const LOCALE_EXPRESSION = '/^(?P<language>[a-z]{2})(?:_(?P<country>[A-Za-z]{2,4}))?(?:@(?P<script>[A-Za-z\d]{5,8}|\d[A-Za-z\d]{3}))?$/';
public const LOCALE_EXPRESSION_SUBMISSION = '/^(?P<language>[A-Za-z]{2,4})(?:[_-](?P<script>[A-Za-z]{4,5}|[0-9]{4}))?(?:[_-](?P<country>[A-Za-z]{2}|[0-9]{3}))?(?:@(?P<script_at>[A-Za-z_]{2,30}))?$/';
public const LOCALE_EXPRESSION_SUBMISSION = '/^(?P<language>[A-Za-z]{2,4})(?:[_-](?P<script>[A-Za-z]{4,5}|[0-9]{4}))?(?:[_-](?P<country>[A-Za-z]{2}|[0-9]{3}))?(?:@(?P<variant>[a-z]{2,30})(?:[_-](?P<variant_script>(?&script)))?)?$/';

/**
* Attempts to retrieve the primary locale for the current context, if not available, then for the site.
Expand Down
4 changes: 2 additions & 2 deletions classes/migration/install/AnnouncementsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function up(): void
$table->foreign('type_id')->references('type_id')->on('announcement_types')->onDelete('cascade');
$table->index(['type_id'], 'announcement_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 Expand Up @@ -76,7 +76,7 @@ public function up(): void
$table->foreign('announcement_id')->references('announcement_id')->on('announcements')->onDelete('cascade');
$table->index(['announcement_id'], 'announcement_settings_announcement_id');

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

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/CategoriesMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function up(): void
$table->foreign('category_id')->references('category_id')->on('categories')->onDelete('cascade');
$table->index(['category_id'], 'category_settings_category_id');

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

Expand Down
12 changes: 6 additions & 6 deletions classes/migration/install/CommonMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function up(): void
$table->comment('A singleton table describing basic information about the site.');
$table->bigIncrements('site_id');
$table->bigInteger('redirect')->default(0)->comment('If not 0, redirect to the specified journal/conference/... site.');
$table->string('primary_locale', 14)->comment('Primary locale for the site.');
$table->string('primary_locale', 28)->comment('Primary locale for the site.');
$table->smallInteger('min_password_length')->default(6);
$table->string('installed_locales', 1024)->default('en')->comment('Locales for which support has been installed.');
$table->string('supported_locales', 1024)->comment('Locales supported by the site (for hosted journals/conferences/...).')->nullable();
Expand All @@ -60,7 +60,7 @@ public function up(): void
$table->comment('More data about the site, including localized properties such as its name.');
$table->bigIncrements('site_setting_id');
$table->string('setting_name', 255);
$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->mediumText('setting_value')->nullable();
$table->unique(['setting_name', 'locale'], 'site_settings_unique');
});
Expand Down Expand Up @@ -111,7 +111,7 @@ public function up(): void
$table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade');
$table->index(['user_id'], 'user_settings_user_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 @@ -171,7 +171,7 @@ public function up(): void
$table->foreign('notification_id')->references('notification_id')->on('notifications')->onDelete('cascade');
$table->index(['notification_id'], 'notification_settings_notification_id');

$table->string('locale', 14)->nullable();
$table->string('locale', 28)->nullable();
$table->string('setting_name', 64);
$table->mediumText('setting_value');
$table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
Expand Down Expand Up @@ -200,7 +200,7 @@ public function up(): void
$table->comment('Default email templates created for every installed locale.');
$table->bigIncrements('email_templates_default_data_id');
$table->string('email_key', 255)->comment('Unique identifier for this email.');
$table->string('locale', 14)->default('en');
$table->string('locale', 28)->default('en');
$table->string('name', 255);
$table->string('subject', 255);
$table->text('body')->nullable();
Expand Down Expand Up @@ -230,7 +230,7 @@ public function up(): void
$table->foreign('email_id', 'email_templates_settings_email_id')->references('email_id')->on('email_templates')->onDelete('cascade');
$table->index(['email_id'], 'email_templates_settings_email_id');

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

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/ControlledVocabMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function up(): void
$table->foreign('controlled_vocab_entry_id', 'c_v_e_s_entry_id')->references('controlled_vocab_entry_id')->on('controlled_vocab_entries')->onDelete('cascade');
$table->index(['controlled_vocab_entry_id'], 'c_v_e_s_entry_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
2 changes: 1 addition & 1 deletion classes/migration/install/DoiMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function up(): void
$table->comment('More data about DOIs, including the registration agency.');
$table->bigIncrements('doi_setting_id');
$table->bigInteger('doi_id');
$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/GenresMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function up(): void
$table->foreign('genre_id')->references('genre_id')->on('genres')->onDelete('cascade');
$table->index(['genre_id'], 'genre_settings_genre_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
2 changes: 1 addition & 1 deletion classes/migration/install/HighlightsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function up(): void
$table->foreign('highlight_id')->references('highlight_id')->on('highlights')->onDelete('cascade');
$table->index(['highlight_id'], 'highlight_settings_highlight_id');

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

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/InstitutionsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function up(): void
$table->foreign('institution_id')->references('institution_id')->on('institutions')->onDelete('cascade');
$table->index(['institution_id'], 'institution_settings_institution_id');

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

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/LibraryFilesMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function up(): void
$table->foreign('file_id')->references('file_id')->on('library_files')->onDelete('cascade');
$table->index(['file_id'], 'library_file_settings_file_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|date)');
Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/LogMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function up(): void
$table->foreign('log_id', 'event_log_settings_log_id')->references('log_id')->on('event_log')->onDelete('cascade');
$table->index(['log_id'], 'event_log_settings_log_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();
$table->unique(['log_id', 'setting_name', 'locale'], 'event_log_settings_unique');
Expand Down
4 changes: 2 additions & 2 deletions classes/migration/install/MetadataMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function up(): void
$table->foreign('citation_id', 'citation_settings_citation_id')->references('citation_id')->on('citations')->onDelete('cascade');
$table->index(['citation_id'], 'citation_settings_citation_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 Expand Up @@ -92,7 +92,7 @@ public function up(): void
$table->foreign('filter_id')->references('filter_id')->on('filters')->onDelete('cascade');
$table->index(['filter_id'], 'filter_settings_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
4 changes: 2 additions & 2 deletions classes/migration/install/NavigationMenusMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function up(): void
$table->foreign('navigation_menu_item_id', 'navigation_menu_item_settings_navigation_menu_id')->references('navigation_menu_item_id')->on('navigation_menu_items')->onDelete('cascade');
$table->index(['navigation_menu_item_id'], 'navigation_menu_item_settings_navigation_menu_item_id');

$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->longText('setting_value')->nullable();
$table->string('setting_type', 6);
Expand Down Expand Up @@ -83,7 +83,7 @@ public function up(): void
$table->foreign('navigation_menu_item_assignment_id', 'assignment_settings_navigation_menu_item_assignment_id')->references('navigation_menu_item_assignment_id')->on('navigation_menu_item_assignments')->onDelete('cascade');
$table->index(['navigation_menu_item_assignment_id'], 'navigation_menu_item_assignment_settings_n_m_i_a_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
4 changes: 2 additions & 2 deletions classes/migration/install/ReviewFormsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function up(): void
$table->foreign('review_form_id', 'review_form_settings_review_form_id')->references('review_form_id')->on('review_forms')->onDelete('cascade');
$table->index(['review_form_id'], 'review_form_settings_review_form_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 Expand Up @@ -80,7 +80,7 @@ public function up(): void
$table->foreign('review_form_element_id', 'review_form_element_settings_review_form_element_id')->references('review_form_element_id')->on('review_form_elements')->onDelete('cascade');
$table->index(['review_form_element_id'], 'review_form_element_settings_review_form_element_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
2 changes: 1 addition & 1 deletion classes/migration/install/RolesAndUserGroupsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function up(): void
$table->comment('More data about user groups, including localized properties such as the name.');
$table->bigIncrements('user_group_setting_id');
$table->bigInteger('user_group_id');
$table->string('locale', 14)->default('');
$table->string('locale', 28)->default('');
$table->string('setting_name', 255);
$table->mediumText('setting_value')->nullable();

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/SubmissionFilesMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function up(): void
$table->foreign('submission_file_id')->references('submission_file_id')->on('submission_files')->onDelete('cascade');
$table->index(['submission_file_id'], 'submission_file_settings_submission_file_id');

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

Expand Down
8 changes: 4 additions & 4 deletions classes/migration/install/SubmissionsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function up(): void
$table->datetime('date_submitted')->nullable();
$table->datetime('last_modified')->nullable();
$table->bigInteger('stage_id')->default($this->defaultStageId);
$table->string('locale', 14)->nullable();
$table->string('locale', 28)->nullable();

$table->smallInteger('status')->default(PKPSubmission::STATUS_QUEUED);

Expand All @@ -66,7 +66,7 @@ public function up(): void
$table->foreign('submission_id')->references('submission_id')->on('submissions')->onDelete('cascade');
$table->index(['submission_id'], 'submission_settings_submission_id');

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

Expand All @@ -81,7 +81,7 @@ public function up(): void
// The foreign key relationship on this table is defined with the publications table.
$table->bigInteger('publication_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 @@ -120,7 +120,7 @@ public function up(): void
$table->foreign('author_id', 'author_settings_author_id')->references('author_id')->on('authors')->onDelete('cascade');
$table->index(['author_id'], 'author_settings_author_id');

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

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/TombstoneMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function up(): void
$table->foreign('tombstone_id', 'data_object_tombstone_settings_tombstone_id')->references('tombstone_id')->on('data_object_tombstones')->onDelete('cascade');
$table->index(['tombstone_id'], 'data_object_tombstone_settings_tombstone_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
Loading

0 comments on commit fa0dbc6

Please sign in to comment.