Skip to content
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

Feature/main/i6328 improved localization #7336

Merged
merged 20 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8f9d32a
pkp/pkp-lib#6328 Updated localization framework
jonasraoni Sep 12, 2021
d4c4f71
pkp/pkp-lib#6328 Updated usage of Locale
jonasraoni Sep 25, 2021
1499ea1
pkp/pkp-lib#6328 Removed requireComponents
jonasraoni Aug 14, 2021
9d458af
pkp/pkp-lib#6328 Introduced functions in place of named constants for…
jonasraoni Oct 13, 2021
b3664d2
pkp/pkp-lib#6328 Moved the PKPXMLParser::_getStream() method to the F…
jonasraoni Oct 13, 2021
4c37b31
pkp/pkp-lib#6328 Updated the VersionCheck to use SimpleXMLElement (si…
jonasraoni Oct 13, 2021
2844779
pkp/pkp-lib#6328 Added field to configure the time zone in the instal…
jonasraoni Oct 24, 2021
773c416
pkp/pkp-lib#6328 Added pluralization support for the Smarty templates…
jonasraoni Oct 24, 2021
7bb51ec
pkp/pkp-lib#6328 Fixed the "SESSION_DISABLE_INIT" by not initializing…
jonasraoni Oct 25, 2021
74fb5e2
pkp/pkp-lib#6328 Removed client encoding and references to LATIN1/ISO…
jonasraoni Nov 14, 2021
19e1b91
pkp/pkp-lib#6328 Removed method getAllLocales
jonasraoni Nov 15, 2021
be35521
pkp/pkp-lib#6328 Moved IsoCodesFactory to the Locale
jonasraoni Nov 25, 2021
a320d65
pkp/pkp-lib#6328 Removed locales.xml and unused dtd and xml files
jonasraoni Nov 24, 2021
ebc238d
pkp/pkp-lib#6328 Minor updates
jonasraoni Nov 28, 2021
6cdd1cf
pkp/pkp-lib#6328 Recovered most used methods from PKPLocale class for…
jonasraoni Feb 9, 2022
903706c
pkp/pkp-lib#6328 Recovered constants due to backwards compatibility w…
jonasraoni Feb 10, 2022
4483934
pkp/pkp-lib#6328 Renamed Application::isReady() to isUnderMaintenance
jonasraoni Feb 13, 2022
1a699ab
pkp/pkp-lib#6328 Added description to facade methods
jonasraoni Feb 13, 2022
e750625
pkp/pkp-lib#6328 Updated VersionCheck to not cache virtual paths
jonasraoni Feb 13, 2022
f80c4ad
pkp/pkp-lib#6328 Standardized cache code
jonasraoni Feb 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Support/Jobs/BaseJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace PKP\Support\Jobs;

use APP\core\Application;
use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function __construct()

protected function defaultConnection(): string
{
if (defined('RUNNING_UPGRADE')) {
if (Application::isUnderMaintenance()) {
return 'sync';
}

Expand Down
11 changes: 0 additions & 11 deletions api/v1/submissions/PKPSubmissionHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\i18n\AppLocale;
use APP\notification\Notification;
use APP\notification\NotificationManager;
use APP\submission\Collector;
Expand Down Expand Up @@ -379,11 +378,6 @@ protected function getSubmissionCollector(array $queryParams): Collector
*/
public function get($slimRequest, $response, $args)
{
AppLocale::requireComponents(
LOCALE_COMPONENT_PKP_READER,
LOCALE_COMPONENT_PKP_SUBMISSION
);

$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);

$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /** @var UserGroupDAO $userGroupDao */
Expand All @@ -403,8 +397,6 @@ public function get($slimRequest, $response, $args)
*/
public function add($slimRequest, $response, $args)
{
AppLocale::requireComponents(LOCALE_COMPONENT_APP_AUTHOR);

$request = $this->getRequest();

// Don't allow submissions to be added via the site-wide API
Expand Down Expand Up @@ -693,7 +685,6 @@ public function addPublication($slimRequest, $response, $args)
public function versionPublication($slimRequest, $response, $args)
{
$request = $this->getRequest();
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION); // notification.type.submissionNewVersion
$submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
$publication = Repo::publication()->get((int) $args['publicationId']);

Expand Down Expand Up @@ -837,8 +828,6 @@ public function publishPublication($slimRequest, $response, $args)
return $response->withStatus(403)->withJsonError('api.publication.403.alreadyPublished');
}

AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);

$submissionContext = $request->getContext();
if (!$submissionContext || $submissionContext->getId() !== $submission->getData('contextId')) {
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
Expand Down
4 changes: 2 additions & 2 deletions api/v1/users/PKPUserHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

use APP\facades\Repo;
use APP\i18n\AppLocale;
use PKP\facades\Locale;
use PKP\handler\APIHandler;
use PKP\plugins\HookRegistry;
use PKP\security\authorization\ContextAccessPolicy;
Expand Down Expand Up @@ -123,7 +123,7 @@ public function getMany($slimRequest, $response, $args)
->assignedToCategoryIds(isset($params['assignedToCategory']) ? [$params['assignedToCategory']] : null)
->filterByRoleIds($params['roleIds'] ?? null)
->searchPhrase($params['searchPhrase'] ?? null)
->orderBy($orderBy, $orderDirection, [AppLocale::getLocale(), $request->getSite()->getPrimaryLocale()])
->orderBy($orderBy, $orderDirection, [Locale::getLocale(), $request->getSite()->getPrimaryLocale()])
->limit($params['count'] ?? null)
->offset($params['offset'] ?? null)
->filterByStatus($params['status'] ?? $collector::STATUS_ALL);
Expand Down
9 changes: 3 additions & 6 deletions api/v1/vocabs/PKPVocabHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

use APP\core\Application;
use APP\i18n\AppLocale;
use PKP\core\APIResponse;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
Expand All @@ -29,8 +28,8 @@
use PKP\submission\SubmissionLanguageDAO;
use PKP\submission\SubmissionSubjectDAO;
use Slim\Http\Request;
use Sokil\IsoCodes\IsoCodesFactory;
use Stringy\Stringy;
use PKP\facades\Locale;

class PKPVocabHandler extends APIHandler
{
Expand Down Expand Up @@ -77,7 +76,7 @@ public function getMany(Request $slimRequest, APIResponse $response, array $args
$requestParams = $slimRequest->getQueryParams();

$vocab = $requestParams['vocab'] ?? '';
$locale = $requestParams['locale'] ?? AppLocale::getLocale();
$locale = $requestParams['locale'] ?? Locale::getLocale();
$term = $requestParams['term'] ?? null;

if (!in_array($locale, $context->getData('supportedSubmissionLocales'))) {
Expand All @@ -98,11 +97,9 @@ public function getMany(Request $slimRequest, APIResponse $response, array $args
$entries = $submissionDisciplineEntryDao->getByContextId($vocab, $context->getId(), $locale, $term)->toArray();
break;
case SubmissionLanguageDAO::CONTROLLED_VOCAB_SUBMISSION_LANGUAGE:
/** @var IsoCodesFactory */
$isoCodes = app(IsoCodesFactory::class);
$words = array_filter(PKPString::regexp_split('/\s+/', $term), 'strlen');
$languageNames = [];
foreach ($isoCodes->getLanguages(IsoCodesFactory::OPTIMISATION_IO) as $language) {
foreach (Locale::getLanguages() as $language) {
if ($language->getAlpha2() && $language->getType() === 'L' && $language->getScope() === 'I' && Stringy::create($language->getLocalName())->containsAny($words, false)) {
$languageNames[] = $language->getLocalName();
}
Expand Down
6 changes: 0 additions & 6 deletions classes/announcement/Repository.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace PKP\announcement;

use APP\core\Request;
use APP\i18n\AppLocale;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use PKP\core\Core;
Expand Down Expand Up @@ -106,11 +105,6 @@ public function getSchemaMap(): maps\Schema
*/
public function validate(?Announcement $object, array $props, array $allowedLocales, string $primaryLocale): array
{
AppLocale::requireComponents(
LOCALE_COMPONENT_PKP_MANAGER,
LOCALE_COMPONENT_APP_MANAGER
);

$validator = ValidatorFactory::make(
$props,
$this->schemaService->getValidationRules($this->dao->schema, $allowedLocales),
Expand Down
8 changes: 4 additions & 4 deletions classes/author/Author.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PKP\author;

use APP\i18n\AppLocale;
use PKP\facades\Locale;
use PKP\db\DAORegistry;

use PKP\identity\Identity;
Expand All @@ -34,7 +34,7 @@ class Author extends Identity
public function &getLocalizedData($key, $preferredLocale = null)
{
if (is_null($preferredLocale)) {
$preferredLocale = AppLocale::getLocale();
$preferredLocale = Locale::getLocale();
}
$localePrecedence = [$preferredLocale];
// the submission locale is the default locale
Expand All @@ -43,8 +43,8 @@ public function &getLocalizedData($key, $preferredLocale = null)
}
// for settings other than givenName, familyName and affiliation (that are required)
// consider also the application primary locale
if (!in_array(AppLocale::getPrimaryLocale(), $localePrecedence)) {
$localePrecedence[] = AppLocale::getPrimaryLocale();
if (!in_array(Locale::getPrimaryLocale(), $localePrecedence)) {
$localePrecedence[] = Locale::getPrimaryLocale();
}
foreach ($localePrecedence as $locale) {
if (empty($locale)) {
Expand Down
6 changes: 0 additions & 6 deletions classes/category/Repository.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace PKP\category;

use APP\core\Request;
use APP\i18n\AppLocale;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use PKP\plugins\HookRegistry;
Expand Down Expand Up @@ -105,11 +104,6 @@ public function getSchemaMap(): maps\Schema
*/
public function validate(?Announcement $object, array $props, array $allowedLocales, string $primaryLocale): array
{
AppLocale::requireComponents(
LOCALE_COMPONENT_PKP_MANAGER,
LOCALE_COMPONENT_APP_MANAGER
);

$validator = ValidatorFactory::make(
$props,
$this->schemaService->getValidationRules($this->dao->schema, $allowedLocales),
Expand Down
19 changes: 8 additions & 11 deletions classes/cliTool/CommandLineTool.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@

use APP\core\Application;
use APP\core\PageRouter;
use APP\facades\Repo;
use PKP\core\Registry;
use PKP\db\DAORegistry;
use PKP\plugins\PluginRegistry;
use PKP\security\Role;
use PKP\session\SessionManager;

/** Initialization code */
define('PWD', getcwd());
chdir(dirname(INDEX_FILE_LOCATION)); /* Change to base directory */
if (!defined('STDIN')) {
jonasraoni marked this conversation as resolved.
Show resolved Hide resolved
define('STDIN', fopen('php://stdin', 'r'));
}
define('SESSION_DISABLE_INIT', 1);
require('./lib/pkp/includes/bootstrap.inc.php');

use APP\facades\Repo;
use APP\i18n\AppLocale;
use PKP\core\Registry;

use PKP\db\DAORegistry;
use PKP\plugins\PluginRegistry;
use PKP\security\Role;
require_once './lib/pkp/includes/bootstrap.inc.php';
SessionManager::disable();

class CommandLineTool
{
Expand Down Expand Up @@ -69,7 +67,6 @@ public function __construct($argv = [])
$request->setRouter($router);

// Initialize the locale and load generic plugins.
AppLocale::initialize($request);
PluginRegistry::loadCategory('generic');

$this->argv = isset($argv) && is_array($argv) ? $argv : [];
Expand Down
4 changes: 1 addition & 3 deletions classes/cliTool/InstallTool.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public function readParams()
$this->printTitle('installer.localeSettings');
$this->readParamOptions('locale', 'locale.primary', $installForm->supportedLocales, 'en_US');
$this->readParamOptions('additionalLocales', 'installer.additionalLocales', $installForm->supportedLocales, '', true);
$this->readParamOptions('clientCharset', 'installer.clientCharset', $installForm->supportedClientCharsets, 'utf-8');
$this->readParamOptions('connectionCharset', 'installer.connectionCharset', $installForm->supportedConnectionCharsets, '');

// File Settings
$this->printTitle('installer.fileSettings');
Expand All @@ -108,7 +106,7 @@ public function readParams()

// Database Settings
$this->printTitle('installer.databaseSettings');
$this->readParamOptions('databaseDriver', 'installer.databaseDriver', $installForm->checkDBDrivers());
$this->readParamOptions('databaseDriver', 'installer.databaseDriver', $installForm->getDatabaseDriversOptions());
$this->readParam('databaseHost', 'installer.databaseHost', '');
$this->readParam('databaseUsername', 'installer.databaseUsername', '');
$this->readParam('databasePassword', 'installer.databasePassword', '');
Expand Down
8 changes: 2 additions & 6 deletions classes/cliTool/UpgradeTool.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

namespace PKP\cliTool;

define('RUNNING_UPGRADE', 1);

use APP\core\Application;

use APP\i18n\AppLocale;
use APP\install\Upgrade;
use PKP\site\VersionCheck;

Application::upgrade();

class UpgradeTool extends \PKP\cliTool\CommandLineTool
{
/** @var string command to execute (check|upgrade|download) */
Expand All @@ -37,7 +35,6 @@ class UpgradeTool extends \PKP\cliTool\CommandLineTool
*/
public function __construct($argv = [])
{
Application::get()->initializeLaravelContainer();
parent::__construct($argv);

if (!isset($this->argv[0]) || !in_array($this->argv[0], ['check', 'latest', 'upgrade', 'download'])) {
Expand All @@ -46,7 +43,6 @@ public function __construct($argv = [])
}

$this->command = $this->argv[0];
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_INSTALLER);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions classes/components/PKPStatsComponent.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class PKPStatsComponent
*/
public function __construct($apiUrl, $args = [])
{
\AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER);
\AppLocale::requireComponents(LOCALE_COMPONENT_APP_MANAGER);

$this->apiUrl = $apiUrl;
$this->init($args);
}
Expand Down
9 changes: 5 additions & 4 deletions classes/components/forms/FormComponent.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace PKP\components\forms;

use Exception;
use PKP\facades\Locale;

define('FIELD_POSITION_BEFORE', 'before');
define('FIELD_POSITION_AFTER', 'after');
Expand Down Expand Up @@ -278,9 +279,9 @@ public function getConfig()

$fieldsConfig = array_map([$this, 'getFieldConfig'], $this->fields);

$visibleLocales = [\AppLocale::getLocale()];
if (\AppLocale::getLocale() !== \AppLocale::getPrimaryLocale()) {
array_unshift($visibleLocales, \AppLocale::getPrimaryLocale());
$visibleLocales = [Locale::getLocale()];
if (Locale::getLocale() !== Locale::getPrimaryLocale()) {
array_unshift($visibleLocales, Locale::getPrimaryLocale());
}

$config = [
Expand All @@ -290,7 +291,7 @@ public function getConfig()
'fields' => $fieldsConfig,
'groups' => $this->groups,
'pages' => $this->pages,
'primaryLocale' => \AppLocale::getPrimaryLocale(),
'primaryLocale' => Locale::getPrimaryLocale(),
'visibleLocales' => $visibleLocales,
'supportedFormLocales' => array_values($this->locales), // See #5690
'errors' => (object) [],
Expand Down
6 changes: 2 additions & 4 deletions classes/components/forms/context/PKPContextForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use PKP\components\forms\FieldSelect;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;
use Sokil\IsoCodes\IsoCodesFactory;
use PKP\facades\Locale;

define('FORM_CONTEXT', 'context');

Expand All @@ -45,10 +45,8 @@ public function __construct($action, $locales, $baseUrl, $context)
$this->locales = $locales;
$this->method = $context ? 'PUT' : 'POST';

$isoCodes = app(IsoCodesFactory::class);

$countries = [];
foreach ($isoCodes->getCountries() as $country) {
foreach (Locale::getCountries() as $country) {
$countries[] = [
'value' => $country->getAlpha2(),
'label' => $country->getLocalName()
Expand Down
5 changes: 2 additions & 3 deletions classes/components/forms/context/PKPMastheadForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use PKP\components\forms\FieldSelect;
use PKP\components\forms\FieldText;
use PKP\components\forms\FormComponent;
use Sokil\IsoCodes\IsoCodesFactory;
use PKP\facades\Locale;

define('FORM_MASTHEAD', 'masthead');

Expand All @@ -43,9 +43,8 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
$this->action = $action;
$this->locales = $locales;

$isoCodes = app(IsoCodesFactory::class);
$countries = [];
foreach ($isoCodes->getCountries() as $country) {
foreach (Locale::getCountries() as $country) {
$countries[] = [
'value' => $country->getAlpha2(),
'label' => $country->getLocalName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use PKP\components\forms\FieldOptions;
use PKP\components\forms\FieldSelect;
use PKP\components\forms\FormComponent;

use Sokil\IsoCodes\IsoCodesFactory;
use PKP\facades\Locale;
use PKP\plugins\PluginRegistry;

define('FORM_PAYMENT_SETTINGS', 'paymentSettings');

Expand All @@ -43,16 +43,15 @@ public function __construct($action, $locales, $context)
$this->locales = $locales;

$currencies = [];
$isoCodes = app(IsoCodesFactory::class);
foreach ($isoCodes->getCurrencies() as $currency) {
foreach (Locale::getCurrencies() as $currency) {
$currencies[] = [
'value' => $currency->getLetterCode(),
'label' => $currency->getLocalName(),
];
}

// Ensure payment method plugins can hook in
$paymentPlugins = \PluginRegistry::loadCategory('paymethod', true);
$paymentPlugins = PluginRegistry::loadCategory('paymethod', true);
$pluginList = [];
foreach ($paymentPlugins as $plugin) {
$pluginList[] = [
Expand Down
Loading