From 1332078be1643e51caf2aa8104d92d2fdd773e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 26 Sep 2023 10:42:38 +0200 Subject: [PATCH 1/4] Use OCP\Util::getL10N instead of OC::$server->getL10N MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Server.php | 2 +- .../Federation/Exceptions/ActionNotSupportedException.php | 2 +- .../Exceptions/AuthenticationFailedException.php | 2 +- lib/public/Federation/Exceptions/BadRequestException.php | 2 +- .../Exceptions/ProviderAlreadyExistsException.php | 2 +- .../Exceptions/ProviderDoesNotExistsException.php | 2 +- lib/public/Files/LockNotAcquiredException.php | 2 +- lib/public/Files/StorageAuthException.php | 2 +- lib/public/Files/StorageBadConfigException.php | 2 +- lib/public/Files/StorageConnectionException.php | 2 +- lib/public/Files/StorageNotAvailableException.php | 2 +- lib/public/Files/StorageTimeoutException.php | 2 +- lib/public/Util.php | 7 ++----- 13 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index d8fa900c0afba..2e36d67716469 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1724,7 +1724,7 @@ public function getL10NFactory() { * @param string $app appid * @param string $lang * @return IL10N - * @deprecated 20.0.0 + * @deprecated 20.0.0 use \OCP\Util::getL10N instead */ public function getL10N($app, $lang = null) { return $this->get(IFactory::class)->get($app, $lang); diff --git a/lib/public/Federation/Exceptions/ActionNotSupportedException.php b/lib/public/Federation/Exceptions/ActionNotSupportedException.php index e5f8d50fd997b..a7dcda15fe5c4 100644 --- a/lib/public/Federation/Exceptions/ActionNotSupportedException.php +++ b/lib/public/Federation/Exceptions/ActionNotSupportedException.php @@ -38,7 +38,7 @@ class ActionNotSupportedException extends HintException { * */ public function __construct($action) { - $l = \OC::$server->getL10N('federation'); + $l = \OCP\Util::getL10N('federation'); $message = 'Action "' . $action . '" not supported or implemented.'; $hint = $l->t('Action "%s" not supported or implemented.', [$action]); parent::__construct($message, $hint); diff --git a/lib/public/Federation/Exceptions/AuthenticationFailedException.php b/lib/public/Federation/Exceptions/AuthenticationFailedException.php index 2bd3e361edd01..63c8f63ab8505 100644 --- a/lib/public/Federation/Exceptions/AuthenticationFailedException.php +++ b/lib/public/Federation/Exceptions/AuthenticationFailedException.php @@ -38,7 +38,7 @@ class AuthenticationFailedException extends HintException { * */ public function __construct() { - $l = \OC::$server->getL10N('federation'); + $l = \OCP\Util::getL10N('federation'); $message = 'Authentication failed, wrong token or provider ID given'; $hint = $l->t('Authentication failed, wrong token or provider ID given'); parent::__construct($message, $hint); diff --git a/lib/public/Federation/Exceptions/BadRequestException.php b/lib/public/Federation/Exceptions/BadRequestException.php index bc8b5c7b72473..fbd781aee43b0 100644 --- a/lib/public/Federation/Exceptions/BadRequestException.php +++ b/lib/public/Federation/Exceptions/BadRequestException.php @@ -45,7 +45,7 @@ class BadRequestException extends HintException { * @param array $missingParameters */ public function __construct(array $missingParameters) { - $l = \OC::$server->getL10N('federation'); + $l = \OCP\Util::getL10N('federation'); $this->parameterList = $missingParameters; $parameterList = implode(',', $missingParameters); $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; diff --git a/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php b/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php index d30d81eca2783..cb0a8e8d51f7b 100644 --- a/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php +++ b/lib/public/Federation/Exceptions/ProviderAlreadyExistsException.php @@ -42,7 +42,7 @@ class ProviderAlreadyExistsException extends HintException { * @param string $existingProviderName name of cloud federation provider which already use the same ID */ public function __construct($newProviderId, $existingProviderName) { - $l = \OC::$server->getL10N('federation'); + $l = \OCP\Util::getL10N('federation'); $message = 'ID "' . $newProviderId . '" already used by cloud federation provider "' . $existingProviderName . '"'; $hint = $l->t('ID "%1$s" already used by cloud federation provider "%2$s"', [$newProviderId, $existingProviderName]); parent::__construct($message, $hint); diff --git a/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php b/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php index 849209da22d44..0594bb6875b23 100644 --- a/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php +++ b/lib/public/Federation/Exceptions/ProviderDoesNotExistsException.php @@ -39,7 +39,7 @@ class ProviderDoesNotExistsException extends HintException { * @param string $providerId cloud federation provider ID */ public function __construct($providerId) { - $l = \OC::$server->getL10N('federation'); + $l = \OCP\Util::getL10N('federation'); $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.'; $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); parent::__construct($message, $hint); diff --git a/lib/public/Files/LockNotAcquiredException.php b/lib/public/Files/LockNotAcquiredException.php index 4a26878cedf05..2cf8ea20acf63 100644 --- a/lib/public/Files/LockNotAcquiredException.php +++ b/lib/public/Files/LockNotAcquiredException.php @@ -43,7 +43,7 @@ class LockNotAcquiredException extends \Exception { * @since 7.0.0 */ public function __construct($path, $lockType, $code = 0, \Exception $previous = null) { - $message = \OC::$server->getL10N('core')->t('Could not obtain lock type %d on "%s".', [$lockType, $path]); + $message = \OCP\Util::getL10N('core')->t('Could not obtain lock type %d on "%s".', [$lockType, $path]); parent::__construct($message, $code, $previous); } diff --git a/lib/public/Files/StorageAuthException.php b/lib/public/Files/StorageAuthException.php index 5fce191b57eba..bc39f8e27f5f6 100644 --- a/lib/public/Files/StorageAuthException.php +++ b/lib/public/Files/StorageAuthException.php @@ -36,7 +36,7 @@ class StorageAuthException extends StorageNotAvailableException { * @since 9.0.0 */ public function __construct($message = '', \Exception $previous = null) { - $l = \OC::$server->getL10N('core'); + $l = \OCP\Util::getL10N('core'); parent::__construct($l->t('Storage unauthorized. %s', [$message]), self::STATUS_UNAUTHORIZED, $previous); } } diff --git a/lib/public/Files/StorageBadConfigException.php b/lib/public/Files/StorageBadConfigException.php index 0e16a24daa88b..36d7329d4b507 100644 --- a/lib/public/Files/StorageBadConfigException.php +++ b/lib/public/Files/StorageBadConfigException.php @@ -36,7 +36,7 @@ class StorageBadConfigException extends StorageNotAvailableException { * @since 9.0.0 */ public function __construct($message = '', \Exception $previous = null) { - $l = \OC::$server->getL10N('core'); + $l = \OCP\Util::getL10N('core'); parent::__construct($l->t('Storage incomplete configuration. %s', [$message]), self::STATUS_INCOMPLETE_CONF, $previous); } } diff --git a/lib/public/Files/StorageConnectionException.php b/lib/public/Files/StorageConnectionException.php index 9113faf72a1eb..d29398172e6f7 100644 --- a/lib/public/Files/StorageConnectionException.php +++ b/lib/public/Files/StorageConnectionException.php @@ -36,7 +36,7 @@ class StorageConnectionException extends StorageNotAvailableException { * @since 9.0.0 */ public function __construct($message = '', \Exception $previous = null) { - $l = \OC::$server->getL10N('core'); + $l = \OCP\Util::getL10N('core'); parent::__construct($l->t('Storage connection error. %s', [$message]), self::STATUS_NETWORK_ERROR, $previous); } } diff --git a/lib/public/Files/StorageNotAvailableException.php b/lib/public/Files/StorageNotAvailableException.php index f600ef808084d..c205d6b9c4423 100644 --- a/lib/public/Files/StorageNotAvailableException.php +++ b/lib/public/Files/StorageNotAvailableException.php @@ -56,7 +56,7 @@ class StorageNotAvailableException extends HintException { * @since 6.0.0 */ public function __construct($message = '', $code = self::STATUS_ERROR, \Exception $previous = null) { - $l = \OC::$server->getL10N('core'); + $l = \OCP\Util::getL10N('core'); parent::__construct($message, $l->t('Storage is temporarily not available'), $code, $previous); } diff --git a/lib/public/Files/StorageTimeoutException.php b/lib/public/Files/StorageTimeoutException.php index bad88ad35e0ae..c20711d418161 100644 --- a/lib/public/Files/StorageTimeoutException.php +++ b/lib/public/Files/StorageTimeoutException.php @@ -36,7 +36,7 @@ class StorageTimeoutException extends StorageNotAvailableException { * @since 9.0.0 */ public function __construct($message = '', \Exception $previous = null) { - $l = \OC::$server->getL10N('core'); + $l = \OCP\Util::getL10N('core'); parent::__construct($l->t('Storage connection timeout. %s', [$message]), self::STATUS_TIMEOUT, $previous); } } diff --git a/lib/public/Util.php b/lib/public/Util.php index 6322ab56a8878..4009237db5dc7 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -126,13 +126,10 @@ public static function isSharingDisabledForUser() { /** * get l10n object - * @param string $application - * @param string|null $language - * @return \OCP\IL10N * @since 6.0.0 - parameter $language was added in 8.0.0 */ - public static function getL10N($application, $language = null) { - return \OC::$server->getL10N($application, $language); + public static function getL10N(string $application, ?string $language = null): IL10N { + return Server::get(\OCP\L10N\IFactory::class)->get($application, $language); } /** From 961ccee5f6cd08d8e06aea7f2e4e432cdb7d88e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 26 Sep 2023 11:42:37 +0200 Subject: [PATCH 2/4] Make it clear in the deprecation comment that DI is preferred MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 2e36d67716469..20b0e8f17c1d2 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1724,7 +1724,7 @@ public function getL10NFactory() { * @param string $app appid * @param string $lang * @return IL10N - * @deprecated 20.0.0 use \OCP\Util::getL10N instead + * @deprecated 20.0.0 use DI of IL10N instead, or \OCP\Util::getL10N as a last resort */ public function getL10N($app, $lang = null) { return $this->get(IFactory::class)->get($app, $lang); From b2e9e0fa0d6c50892e94b4ad325ef59fe41dfad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 1 Feb 2024 16:13:27 +0100 Subject: [PATCH 3/4] chore: Replace OC::$server->getL10N by OCP\Util::getL10N in lib and some apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/files/lib/Helper.php | 2 +- apps/files_external/lib/MountConfig.php | 2 +- apps/files_trashbin/lib/Trashbin.php | 2 +- apps/user_ldap/ajax/clearMappings.php | 2 +- apps/user_ldap/ajax/deleteConfiguration.php | 2 +- apps/user_ldap/ajax/testConfiguration.php | 2 +- apps/user_ldap/ajax/wizard.php | 2 +- apps/user_ldap/lib/Access.php | 2 +- core/strings.php | 2 +- lib/private/Files/View.php | 10 +++++----- lib/private/Share/Share.php | 4 ++-- lib/private/Tags.php | 2 +- lib/private/TemplateLayout.php | 2 +- lib/private/User/Manager.php | 2 +- lib/private/User/Session.php | 4 ++-- tests/lib/DateTimeFormatterTest.php | 6 +++--- tests/lib/L10N/L10nTest.php | 4 ++-- 17 files changed, 26 insertions(+), 26 deletions(-) diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index 1d9591cafe056..680df4f16c769 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -48,7 +48,7 @@ class Helper { public static function buildFileStorageStatistics($dir) { // information about storage capacities $storageInfo = \OC_Helper::getStorageInfo($dir); - $l = \OC::$server->getL10N('files'); + $l = \OCP\Util::getL10N('files'); $maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); $maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize); $maxHumanFileSize = $l->t('Upload (max. %s)', [$maxHumanFileSize]); diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php index 98b34b0c9f253..5ddff0f57fc0a 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/apps/files_external/lib/MountConfig.php @@ -152,7 +152,7 @@ public static function getBackendStatus($class, $options, $isPersonal, $testOnly * @param Backend[] $backends */ public static function dependencyMessage(array $backends): string { - $l = \OC::$server->getL10N('files_external'); + $l = \OCP\Util::getL10N('files_external'); $message = ''; $dependencyGroups = []; diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 442abc13670c6..ced40313d621a 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -1069,7 +1069,7 @@ private static function getVersionsFromTrash($filename, $timestamp, string $user private static function getUniqueFilename($location, $filename, View $view) { $ext = pathinfo($filename, PATHINFO_EXTENSION); $name = pathinfo($filename, PATHINFO_FILENAME); - $l = \OC::$server->getL10N('files_trashbin'); + $l = \OCP\Util::getL10N('files_trashbin'); $location = '/' . trim($location, '/'); diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php index 395e3ec3016a3..ecc45a60de7e1 100644 --- a/apps/user_ldap/ajax/clearMappings.php +++ b/apps/user_ldap/ajax/clearMappings.php @@ -50,7 +50,7 @@ function ($uid) { } if ($mapping === null || !$result) { - $l = \OC::$server->getL10N('user_ldap'); + $l = \OCP\Util::getL10N('user_ldap'); throw new \Exception($l->t('Failed to clear the mappings.')); } \OC_JSON::success(); diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php index 82bfb6de82ada..2f1ca3d724fa8 100644 --- a/apps/user_ldap/ajax/deleteConfiguration.php +++ b/apps/user_ldap/ajax/deleteConfiguration.php @@ -35,6 +35,6 @@ if ($helper->deleteServerConfiguration($prefix)) { \OC_JSON::success(); } else { - $l = \OC::$server->getL10N('user_ldap'); + $l = \OCP\Util::getL10N('user_ldap'); \OC_JSON::error(['message' => $l->t('Failed to delete the server configuration')]); } diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php index 9d89b641d667f..187eeb4295bae 100644 --- a/apps/user_ldap/ajax/testConfiguration.php +++ b/apps/user_ldap/ajax/testConfiguration.php @@ -30,7 +30,7 @@ \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$l = \OC::$server->getL10N('user_ldap'); +$l = \OCP\Util::getL10N('user_ldap'); $ldapWrapper = new OCA\User_LDAP\LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $_POST['ldap_serverconfig_chooser']); diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index 8692251c7c047..63241667825a8 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -31,7 +31,7 @@ \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$l = \OC::$server->getL10N('user_ldap'); +$l = \OCP\Util::getL10N('user_ldap'); if (!isset($_POST['action'])) { \OC_JSON::error(['message' => $l->t('No action specified')]); diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index e608d5f80f029..70f9e1411b1dc 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -354,7 +354,7 @@ public function setPassword($userDN, $password) { return @$this->invokeLDAPMethod('exopPasswd', $userDN, '', $password) || @$this->invokeLDAPMethod('modReplace', $userDN, $password); } catch (ConstraintViolationException $e) { - throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), (int)$e->getCode()); + throw new HintException('Password change rejected.', \OCP\Util::getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), (int)$e->getCode()); } } diff --git a/core/strings.php b/core/strings.php index fa23fb1ac654c..50051936eb05a 100644 --- a/core/strings.php +++ b/core/strings.php @@ -25,7 +25,7 @@ * */ //some strings that are used in /lib but won't be translatable unless they are in /core too -$l = \OC::$server->getL10N('core'); +$l = \OCP\Util::getL10N('core'); $l->t("Personal"); $l->t("Users"); $l->t("Apps"); diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index df8990790bb50..2f8f3c08a80db 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1846,19 +1846,19 @@ public function verifyPath($path, $fileName): void { [$storage, $internalPath] = $this->resolvePath($path); $storage->verifyPath($internalPath, $fileName); } catch (ReservedWordException $ex) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Util::getL10N('lib'); throw new InvalidPathException($l->t('File name is a reserved word')); } catch (InvalidCharacterInPathException $ex) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Util::getL10N('lib'); throw new InvalidPathException($l->t('File name contains at least one invalid character')); } catch (FileNameTooLongException $ex) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Util::getL10N('lib'); throw new InvalidPathException($l->t('File name is too long')); } catch (InvalidDirectoryException $ex) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Util::getL10N('lib'); throw new InvalidPathException($l->t('Dot files are not allowed')); } catch (EmptyFileNameException $ex) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Util::getL10N('lib'); throw new InvalidPathException($l->t('Empty filename is not allowed')); } } diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 3aa01b3cf299f..8322c141b1f53 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -256,8 +256,8 @@ public static function getItemShared($itemType, $itemSource, $format = self::FOR * @throws \Exception */ public static function getBackend($itemType) { - $l = \OC::$server->getL10N('lib'); - $logger = \OC::$server->get(LoggerInterface::class); + $l = \OCP\Util::getL10N('lib'); + $logger = \OCP\Server::get(LoggerInterface::class); if (isset(self::$backends[$itemType])) { return self::$backends[$itemType]; } elseif (isset(self::$backendTypes[$itemType]['class'])) { diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 766166beadd36..7b0c509324570 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -235,7 +235,7 @@ public function getIdsForTag($tag) { } if ($tagId === false) { - $l10n = \OC::$server->getL10N('core'); + $l10n = \OCP\Util::getL10N('core'); throw new \Exception( $l10n->t('Could not find category "%s"', [$tag]) ); diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 96d0ae3e5174d..b4490dfe101d0 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -249,7 +249,7 @@ public function __construct($renderAs, $appId = '') { // this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call) // see https://github.com/nextcloud/server/pull/22636 for details $jsConfigHelper = new JSConfigHelper( - \OC::$server->getL10N('lib'), + \OCP\Util::getL10N('lib'), \OCP\Server::get(Defaults::class), \OC::$server->getAppManager(), \OC::$server->getSession(), diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 5013c9bed7af0..705f5fbe66bd6 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -445,7 +445,7 @@ public function createUser($uid, $password) { * @throws \InvalidArgumentException */ public function createUserFromBackend($uid, $password, UserInterface $backend) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Util::getL10N('lib'); $this->validateUserId($uid, true); diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index a411326c93f31..b7f291343798f 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -367,7 +367,7 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi if (!$user->isEnabled()) { // disabled users can not log in // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory - $message = \OC::$server->getL10N('lib')->t('User disabled'); + $message = \OCP\Util::getL10N('lib')->t('User disabled'); throw new LoginException($message); } @@ -406,7 +406,7 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi return true; } - $message = \OC::$server->getL10N('lib')->t('Login canceled by app'); + $message = \OCP\Util::getL10N('lib')->t('Login canceled by app'); throw new LoginException($message); } diff --git a/tests/lib/DateTimeFormatterTest.php b/tests/lib/DateTimeFormatterTest.php index 71d98ba758133..3409c0d92078f 100644 --- a/tests/lib/DateTimeFormatterTest.php +++ b/tests/lib/DateTimeFormatterTest.php @@ -34,7 +34,7 @@ public static function tearDownAfterClass(): void { protected function setUp(): void { parent::setUp(); - $this->formatter = new \OC\DateTimeFormatter(new \DateTimeZone('UTC'), \OC::$server->getL10N('lib', 'en')); + $this->formatter = new \OC\DateTimeFormatter(new \DateTimeZone('UTC'), \OCP\Util::getL10N('lib', 'en')); } protected function getTimestampAgo($time, $seconds = 0, $minutes = 0, $hours = 0, $days = 0, $years = 0) { @@ -43,7 +43,7 @@ protected function getTimestampAgo($time, $seconds = 0, $minutes = 0, $hours = 0 public function formatTimeSpanData() { $time = 1416916800; // Use a fixed timestamp so we don't switch days/years with the getTimestampAgo - $deL10N = \OC::$server->getL10N('lib', 'de'); + $deL10N = \OCP\Util::getL10N('lib', 'de'); return [ ['seconds ago', $time, $time], ['in a few seconds', $time + 5 , $time], @@ -84,7 +84,7 @@ public function testFormatTimeSpan($expected, $timestamp, $compare, $locale = nu public function formatDateSpanData() { $time = 1416916800; // Use a fixed timestamp so we don't switch days/years with the getTimestampAgo - $deL10N = \OC::$server->getL10N('lib', 'de'); + $deL10N = \OCP\Util::getL10N('lib', 'de'); return [ // Normal testing ['today', $this->getTimestampAgo($time, 30, 15), $time], diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index bd1fce295472b..9817f8b0141e9 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -201,12 +201,12 @@ public function testFactoryGetLanguageCode() { } public function testServiceGetLanguageCode() { - $l = \OC::$server->getL10N('lib', 'de'); + $l = \OCP\Util::getL10N('lib', 'de'); $this->assertEquals('de', $l->getLanguageCode()); } public function testWeekdayName() { - $l = \OC::$server->getL10N('lib', 'de'); + $l = \OCP\Util::getL10N('lib', 'de'); $this->assertEquals('Mo.', $l->l('weekdayName', new \DateTime('2017-11-6'), ['width' => 'abbreviated'])); } From d97567a7fdbae3ecf8debc2c43017204f06b193d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <91878298+come-nc@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:18:16 +0100 Subject: [PATCH 4/4] chore: Add references to phpdoc deprecation notice for IL10N MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> --- lib/private/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 20b0e8f17c1d2..b31fb9cd55c65 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1724,7 +1724,7 @@ public function getL10NFactory() { * @param string $app appid * @param string $lang * @return IL10N - * @deprecated 20.0.0 use DI of IL10N instead, or \OCP\Util::getL10N as a last resort + * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort */ public function getL10N($app, $lang = null) { return $this->get(IFactory::class)->get($app, $lang);