Skip to content

Commit

Permalink
chore: Replace OC::$server->getL10N by OCP\Util::getL10N in lib and s…
Browse files Browse the repository at this point in the history
…ome apps

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Feb 1, 2024
1 parent 0a971c5 commit b600c70
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion apps/files/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/MountConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
2 changes: 1 addition & 1 deletion apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');

Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/ajax/clearMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/ajax/deleteConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]);
}
2 changes: 1 addition & 1 deletion apps/user_ldap/ajax/testConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/ajax/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]);
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Check notice

Code scanning / Psalm

RedundantCast Note

Redundant cast to int
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Share/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/lib/DateTimeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/L10N/L10nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}

Expand Down

0 comments on commit b600c70

Please sign in to comment.