Skip to content

Commit

Permalink
#6328 Removed method getAllLocales
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Nov 15, 2021
1 parent 4e96c95 commit ab2c3b2
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 106 deletions.
12 changes: 3 additions & 9 deletions classes/context/Context.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@ public function getSupportedFormLocaleNames()

if (!isset($supportedLocales)) {
$supportedLocales = [];
$localeNames = Locale::getAllLocales();

$locales = $this->getSupportedFormLocales();
if (!isset($locales) || !is_array($locales)) {
$locales = [];
}

foreach ($locales as $localeKey) {
$supportedLocales[$localeKey] = $localeNames[$localeKey];
$supportedLocales[$localeKey] = Locale::getLocaleMetadata($localeKey)->name;
}
}

Expand Down Expand Up @@ -311,15 +309,13 @@ public function getSupportedSubmissionLocaleNames()

if (!isset($supportedLocales)) {
$supportedLocales = [];
$localeNames = Locale::getAllLocales();

$locales = $this->getSupportedSubmissionLocales();
if (!isset($locales) || !is_array($locales)) {
$locales = [];
}

foreach ($locales as $localeKey) {
$supportedLocales[$localeKey] = $localeNames[$localeKey];
$supportedLocales[$localeKey] = Locale::getLocaleMetadata($localeKey)->name;
}
}

Expand Down Expand Up @@ -348,15 +344,13 @@ public function getSupportedLocaleNames()

if (!isset($supportedLocales)) {
$supportedLocales = [];
$localeNames = Locale::getAllLocales();

$locales = $this->getSupportedLocales();
if (!isset($locales) || !is_array($locales)) {
$locales = [];
}

foreach ($locales as $localeKey) {
$supportedLocales[$localeKey] = $localeNames[$localeKey];
$supportedLocales[$localeKey] = Locale::getLocaleMetadata($localeKey)->name;
}
}

Expand Down
3 changes: 1 addition & 2 deletions classes/facades/Locale.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
* @method static void registerLoader(callable $fileLoader, int $priority = 0)
* @method static bool isLocaleValid(string $locale)
* @method static \PKP\i18n\LocaleMetadata getLocaleMetadata(string $locale)
* @method static array getLocales()
* @method static array getAllLocales()
* @method static \PKP\i18n\LocaleMetadata[] getLocales()
* @method static void installLocale(string $locale)
* @method static void uninstallLocale(string $locale)
* @method static array getSupportedFormLocales()
Expand Down
3 changes: 1 addition & 2 deletions classes/form/validation/FormValidatorLocale.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function __construct(&$form, $field, $type, $message, $requiredLocale = n
*/
public function getMessage()
{
$allLocales = Locale::getAllLocales();
return parent::getMessage() . ' (' . $allLocales[$this->_requiredLocale] . ')';
return parent::getMessage() . ' (' . Locale::getLocaleMetadata($this->_requiredLocale)->name . ')';
}

//
Expand Down
21 changes: 6 additions & 15 deletions classes/i18n/Locale.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,6 @@ public function getLocales(): array
return $cache['data'];
}

/**
* @copy LocaleInterface::getAllLocales()
*/
public function getAllLocales(): array
{
$localeMetadata = $this->getLocales();
$locales = [];
foreach ($localeMetadata as $locale) {
$locales[$locale->key] = $locale->name;
}
return $locales;
}

/**
* @copy LocaleInterface::installLocale()
*/
Expand Down Expand Up @@ -304,7 +291,9 @@ public function getSupportedFormLocales(): array
if (!$locales) {
$request = $this->_getRequest();
$locales = SessionManager::isDisabled()
? $this->getAllLocales()
? array_map(function (LocaleMetadata $locale): string {
return $locale->name;
}, Locale::getLocales())
: (($context = $request->getContext()) ? $context->getSupportedFormLocaleNames() : $request->getSite()->getSupportedLocaleNames());
}
return $locales;
Expand All @@ -319,7 +308,9 @@ public function getSupportedLocales(): array
if (!$locales) {
$request = $this->_getRequest();
$locales = SessionManager::isDisabled()
? $this->getAllLocales()
? array_map(function (LocaleMetadata $locale): string {
return $locale->name;
}, Locale::getLocales())
: ($request->getContext() ?? $request->getSite())->getSupportedLocaleNames();
}
return $locales;
Expand Down
8 changes: 0 additions & 8 deletions classes/i18n/interfaces/LocaleInterface.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ public function getLocaleMetadata(string $locale): ?LocaleMetadata;
*/
public function getLocales(): array;

/**
* Return a list of all available locales.
*
* @return string[]
*/
public function getAllLocales(): array;

/**
* Install support for a new locale.
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/install/Installer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function preInstall()
}

if (!isset($this->installedLocales)) {
$this->installedLocales = array_keys(Locale::getAllLocales());
$this->installedLocales = array_keys(Locale::getLocales());
}

if (!isset($this->dataXMLParser)) {
Expand Down
9 changes: 6 additions & 3 deletions classes/install/form/InstallForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use PKP\core\PKPString;
use PKP\facades\Locale;
use PKP\i18n\LocaleMetadata;
use PKP\install\Installer;
use PKP\xslt\XSLTransformer;

Expand Down Expand Up @@ -59,10 +60,12 @@ public function __construct($request)
parent::__construct($request, 'install/install.tpl');

// FIXME Move the below options to an external configuration file?
$this->supportedLocales = Locale::getAllLocales();
$this->supportedLocales = array_map(function (LocaleMetadata $locale): string {
return $locale->name;
}, Locale::getLocales());
$this->localesComplete = [];
foreach ($this->supportedLocales as $key => $name) {
$this->localesComplete[$key] = Locale::getLocaleMetadata($key)->isLocaleComplete ?? false;
foreach (array_keys($this->supportedLocales) as $key) {
$this->localesComplete[$key] = Locale::getLocaleMetadata($key)->isComplete;
}

foreach ($this->supportedDatabaseDrivers as $driver => [$module]) {
Expand Down
4 changes: 1 addition & 3 deletions classes/site/Site.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ public function &getSupportedLocaleNames()

if ($supportedLocales === null) {
$supportedLocales = [];
$localeNames = Locale::getAllLocales();

$locales = $this->getSupportedLocales();
foreach ($locales as $localeKey) {
$supportedLocales[$localeKey] = $localeNames[$localeKey];
$supportedLocales[$localeKey] = Locale::getLocaleMetadata($localeKey)->name;
}

asort($supportedLocales);
Expand Down
5 changes: 2 additions & 3 deletions classes/validation/ValidatorFactory.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,10 @@ public static function convertMessageSyntax($message)
public static function required($validator, $object, $requiredProps, $multilingualProps, $allowedLocales, $primaryLocale)
{
$validator->after(function ($validator) use ($object, $requiredProps, $multilingualProps, $allowedLocales, $primaryLocale) {
$allLocales = Locale::getAllLocales();
$primaryLocaleName = $primaryLocale;
foreach ($allLocales as $locale => $name) {
foreach (Locale::getLocales() as $locale => $metadata) {
if ($locale === $primaryLocale) {
$primaryLocaleName = $name;
$primaryLocaleName = $metadata->name;
}
}

Expand Down
5 changes: 2 additions & 3 deletions controllers/grid/admin/context/ContextGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ public function editContext($args, $request)
$supportedLocales = $request->getSite()->getSupportedLocales();
}

$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedLocales);

$contextForm = new \APP\components\forms\context\ContextForm($apiUrl, $locales, $request->getBaseUrl(), $context);
Expand Down
19 changes: 4 additions & 15 deletions controllers/grid/admin/languages/AdminLanguageGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,33 +138,22 @@ protected function loadData($request, $filter)
$site = $request->getSite();
$data = [];

$allLocales = Locale::getAllLocales();
$installedLocales = $site->getInstalledLocales();
$supportedLocales = $site->getSupportedLocales();
$primaryLocale = $site->getPrimaryLocale();

foreach ($installedLocales as $localeKey) {
$data[$localeKey] = [];
$data[$localeKey]['name'] = $allLocales[$localeKey];
$data[$localeKey]['incomplete'] = !(Locale::getLocaleMetadata($localeKey)->isLocaleComplete ?? false);
if (in_array($localeKey, $supportedLocales)) {
$supported = true;
} else {
$supported = false;
}
$data[$localeKey]['supported'] = $supported;
$data[$localeKey]['name'] = Locale::getLocaleMetadata($localeKey)->name;
$data[$localeKey]['incomplete'] = !Locale::getLocaleMetadata($localeKey)->isComplete;
$data[$localeKey]['supported'] = in_array($localeKey, $supportedLocales);

if ($this->_canManage($request)) {
$context = $request->getContext();
$primaryLocale = $context->getPrimaryLocale();
}

if ($localeKey == $primaryLocale) {
$primary = true;
} else {
$primary = false;
}
$data[$localeKey]['primary'] = $primary;
$data[$localeKey]['primary'] = $localeKey === $primaryLocale;
}

if ($this->_canManage($request)) {
Expand Down
5 changes: 2 additions & 3 deletions controllers/grid/languages/LanguageGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ public function saveLanguageSetting($args, $request)
['contents' => __('notification.localeSettingsSaved')]
);

$localeNames = Locale::getAllLocales();
$newFormLocales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$newFormLocales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $context->getData('supportedFormLocales'));

$json = \PKP\db\DAO::getDataChangedEvent($locale);
Expand Down
6 changes: 4 additions & 2 deletions controllers/grid/languages/form/InstallLanguageForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use APP\template\TemplateManager;
use PKP\facades\Locale;
use PKP\form\Form;
use PKP\i18n\LocaleMetadata;

class InstallLanguageForm extends Form
{
Expand Down Expand Up @@ -49,8 +50,9 @@ public function initData()
*/
public function fetch($request, $template = null, $display = false)
{
$site = $request->getSite();
$allLocales = Locale::getAllLocales();
$allLocales = array_map(function (LocaleMetadata $locale): string {
return $locale->name;
}, Locale::getLocales());
$installedLocales = $this->getData('installedLocales');
$notInstalledLocales = array_diff(array_keys($allLocales), $installedLocales);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ protected function loadData($request, $filter)
$site = $request->getSite();
$context = $request->getContext();

$allLocales = Locale::getAllLocales();
$supportedLocales = $site->getSupportedLocales();
$contextPrimaryLocale = $context->getPrimaryLocale();
$data = [];

foreach ($supportedLocales as $locale) {
$data[$locale] = [];
$data[$locale]['name'] = $allLocales[$locale];
$data[$locale]['name'] = Locale::getLocaleMetadata($locale)->name;
$data[$locale]['supported'] = true;
$data[$locale]['primary'] = ($locale == $contextPrimaryLocale);
}
Expand Down
10 changes: 4 additions & 6 deletions pages/admin/AdminHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ public function settings($args, $request)
$baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath();

$supportedLocales = $site->getSupportedLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedLocales);

$contexts = Services::get('context')->getManySummary();
Expand Down Expand Up @@ -278,9 +277,8 @@ public function wizard($args, $request)
$sitemapUrl = $router->url($request, $context->getPath(), 'sitemap');

$supportedFormLocales = $context->getSupportedFormLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedFormLocales);

$contextForm = new APP\components\forms\context\ContextForm($apiUrl, $locales, $request->getBaseUrl(), $context);
Expand Down
5 changes: 2 additions & 3 deletions pages/authorDashboard/PKPAuthorDashboardHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ public function setupTemplate($request)
}

$supportedSubmissionLocales = $submissionContext->getSupportedSubmissionLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedSubmissionLocales);

$latestPublication = $submission->getLatestPublication();
Expand Down
25 changes: 10 additions & 15 deletions pages/management/ManagementHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ public function context($args, $request)
$publicFileApiUrl = $dispatcher->url($request, PKPApplication::ROUTE_API, $context->getPath(), '_uploadPublicFile');

$supportedFormLocales = $context->getSupportedFormLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedFormLocales);

$contactForm = new PKP\components\forms\context\PKPContactForm($apiUrl, $locales, $context);
Expand Down Expand Up @@ -174,9 +173,8 @@ public function website($args, $request)
$baseUrl = $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId());

$supportedFormLocales = $context->getSupportedFormLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedFormLocales);

$announcementSettingsForm = new \PKP\components\forms\context\PKPAnnouncementSettingsForm($contextApiUrl, $locales, $context);
Expand Down Expand Up @@ -231,9 +229,8 @@ public function workflow($args, $request)
$emailTemplatesApiUrl = $dispatcher->url($request, PKPApplication::ROUTE_API, $context->getPath(), 'emailTemplates');

$supportedFormLocales = $context->getSupportedFormLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedFormLocales);

$authorGuidelinesForm = new \PKP\components\forms\context\PKPAuthorGuidelinesForm($contextApiUrl, $locales, $context);
Expand Down Expand Up @@ -291,9 +288,8 @@ public function distribution($args, $request)
$paymentsUrl = $dispatcher->url($request, PKPApplication::ROUTE_API, $context->getPath(), '_payments');

$supportedFormLocales = $context->getSupportedFormLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedFormLocales);

$licenseForm = new \APP\components\forms\context\LicenseForm($apiUrl, $locales, $context);
Expand Down Expand Up @@ -328,9 +324,8 @@ public function announcements($args, $request)
$apiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $request->getContext()->getPath(), 'announcements');

$supportedFormLocales = $request->getContext()->getSupportedFormLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedFormLocales);

$announcementForm = new \PKP\components\forms\announcement\PKPAnnouncementForm($apiUrl, $locales, $request->getContext());
Expand Down
5 changes: 2 additions & 3 deletions pages/workflow/PKPWorkflowHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ public function index($args, $request)
}

$supportedSubmissionLocales = $submissionContext->getSupportedSubmissionLocales();
$localeNames = Locale::getAllLocales();
$locales = array_map(function ($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
$locales = array_map(function ($localeKey) {
return ['key' => $localeKey, 'label' => Locale::getLocaleMetadata($localeKey)->name];
}, $supportedSubmissionLocales);

$latestPublication = $submission->getLatestPublication();
Expand Down
Loading

0 comments on commit ab2c3b2

Please sign in to comment.