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

Refactor OC\Server::getL10N #40152

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 core/Command/Maintenance/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OC\Setup;
use OC\SystemConfig;
use OCP\Defaults;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
Expand Down Expand Up @@ -77,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$setupHelper = new Setup(
$this->config,
$this->iniGetWrapper,
$server->getL10N('lib'),
$server->get(IFactory::class)->get('lib'),
$server->query(Defaults::class),
$server->get(LoggerInterface::class),
$server->getSecureRandom(),
Expand Down
4 changes: 3 additions & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
Expand Down Expand Up @@ -209,7 +211,7 @@
$application->add(new OC\Core\Command\SystemTag\Add(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class)));
$application->add(new OC\Core\Command\SystemTag\Edit(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class)));

$application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(), \OC::$server->getL10N('core')));
$application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(), \OC::$server->get(IFactory::class)->get('core')));
$application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager()));
$application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager()));
$application->add(\OC::$server->get(\OC\Core\Command\Security\BruteforceAttempts::class));
Expand Down
5 changes: 4 additions & 1 deletion core/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCP\L10N\IFactory;

//some strings that are used in /lib but won't be translatable unless they are in /core too
$l = \OC::$server->getL10N('core');
$l = \OC::$server->get(IFactory::class)->get('core');
$l->t("Personal");
$l->t("Users");
$l->t("Apps");
Expand Down
5 changes: 3 additions & 2 deletions lib/private/AppFramework/DependencyInjection/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\L10N\IFactory;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -135,7 +136,7 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
});

$this->registerService(IL10N::class, function (ContainerInterface $c) {
return $this->getServer()->getL10N($c->get('AppName'));
return $this->getServer()->get(IFactory::class)->get($c->get('AppName'));
});

// Log wrappers
Expand Down Expand Up @@ -256,7 +257,7 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
$this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()),
$server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
$server->getAppManager(),
$server->getL10N('lib'),
$server->get(IFactory::class)->get('lib'),
$c->get(AuthorizedGroupMapper::class),
$server->get(IUserSession::class)
);
Expand Down
11 changes: 6 additions & 5 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use OCP\L10N\IFactory;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -1834,19 +1835,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 = \OC::$server->get(IFactory::class)->get('lib');
throw new InvalidPathException($l->t('File name is a reserved word'));
} catch (InvalidCharacterInPathException $ex) {
$l = \OC::$server->getL10N('lib');
$l = \OC::$server->get(IFactory::class)->get('lib');
throw new InvalidPathException($l->t('File name contains at least one invalid character'));
} catch (FileNameTooLongException $ex) {
$l = \OC::$server->getL10N('lib');
$l = \OC::$server->get(IFactory::class)->get('lib');
throw new InvalidPathException($l->t('File name is too long'));
} catch (InvalidDirectoryException $ex) {
$l = \OC::$server->getL10N('lib');
$l = \OC::$server->get(IFactory::class)->get('lib');
throw new InvalidPathException($l->t('Dot files are not allowed'));
} catch (EmptyFileNameException $ex) {
$l = \OC::$server->getL10N('lib');
$l = \OC::$server->get(IFactory::class)->get('lib');
throw new InvalidPathException($l->t('Empty filename is not allowed'));
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ITempManager;
use OCP\L10N\IFactory;
use phpseclib\File\X509;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -113,7 +114,7 @@ public function installApp(string $appId, bool $forceEnable = false): string {
throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
}

$l = \OC::$server->getL10N('core');
$l = \OC::$server->get(IFactory::class)->get('core');
$info = \OCP\Server::get(IAppManager::class)->getAppInfo($basedir . '/appinfo/info.xml', true, $l->getLanguageCode());

if (!is_array($info)) {
Expand Down
16 changes: 8 additions & 8 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function __construct($webRoot, \OC\Config $config) {
return new Encryption\Manager(
$c->get(\OCP\IConfig::class),
$c->get(LoggerInterface::class),
$c->getL10N('core'),
$c->get(IFactory::class)->get('core'),
new View(),
$util,
new ArrayCache()
Expand Down Expand Up @@ -719,7 +719,7 @@ public function __construct($webRoot, \OC\Config $config) {

$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
return new \OC\Activity\EventMerger(
$c->getL10N('lib')
$c->get(IFactory::class)->get('lib')
);
});
$this->registerAlias(IValidator::class, Validator::class);
Expand All @@ -729,7 +729,7 @@ public function __construct($webRoot, \OC\Config $config) {
$c->get(IUserSession::class),
$c->get(\OC\User\Manager::class),
$c->getAppDataDir('avatar'),
$c->getL10N('lib'),
$c->get(IFactory::class)->get('lib'),
$c->get(LoggerInterface::class),
$c->get(\OCP\IConfig::class),
$c->get(IAccountManager::class),
Expand Down Expand Up @@ -890,7 +890,7 @@ public function __construct($webRoot, \OC\Config $config) {

return new DateTimeFormatter(
$c->get(IDateTimeZone::class)->getTimeZone(),
$c->getL10N('lib', $language)
$c->get(IFactory::class)->get('lib', $language)
);
});
/** @deprecated 19.0.0 */
Expand Down Expand Up @@ -1033,7 +1033,7 @@ public function __construct($webRoot, \OC\Config $config) {
$c->get(LoggerInterface::class),
$c->get(Defaults::class),
$c->get(IURLGenerator::class),
$c->getL10N('lib'),
$c->get(IFactory::class)->get('lib'),
$c->get(IEventDispatcher::class),
$c->get(IFactory::class)
);
Expand Down Expand Up @@ -1108,7 +1108,7 @@ public function __construct($webRoot, \OC\Config $config) {
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
$this->registerService(BundleFetcher::class, function () {
return new BundleFetcher($this->getL10N('lib'));
return new BundleFetcher($this->get(IFactory::class)->get('lib'));
});
$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
/** @deprecated 19.0.0 */
Expand Down Expand Up @@ -1172,7 +1172,7 @@ public function __construct($webRoot, \OC\Config $config) {
);
return new ThemingDefaults(
$c->get(\OCP\IConfig::class),
$c->getL10N('theming'),
$c->get(IFactory::class)->get('theming'),
$c->get(IUserSession::class),
$c->get(IURLGenerator::class),
$c->get(ICacheFactory::class),
Expand Down Expand Up @@ -1242,7 +1242,7 @@ public function __construct($webRoot, \OC\Config $config) {
$c->get(IHasher::class),
$c->get(IMountManager::class),
$c->get(IGroupManager::class),
$c->getL10N('lib'),
$c->get(IFactory::class)->get('lib'),
$c->get(IFactory::class),
$factory,
$c->get(IUserManager::class),
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Defaults;
use OCP\IGroup;
use OCP\IL10N;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -507,7 +508,7 @@ public static function updateHtaccess() {
$setupHelper = new \OC\Setup(
$config,
\OC::$server->get(IniGetWrapper::class),
\OC::$server->getL10N('lib'),
\OC::$server->get(IFactory::class)->get('lib'),
\OCP\Server::get(Defaults::class),
\OC::$server->get(LoggerInterface::class),
\OC::$server->getSecureRandom(),
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Share\IShare;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -256,7 +257,7 @@ public static function getItemShared($itemType, $itemSource, $format = self::FOR
* @throws \Exception
*/
public static function getBackend($itemType) {
$l = \OC::$server->getL10N('lib');
$l = \OC::$server->get(IFactory::class)->get('lib');
$logger = \OC::$server->get(LoggerInterface::class);
if (isset(self::$backends[$itemType])) {
return self::$backends[$itemType];
Expand Down
7 changes: 4 additions & 3 deletions lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use OCP\L10N\IFactory;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
Expand Down Expand Up @@ -129,7 +130,7 @@ protected function federatedShareProvider() {
/*
* TODO: add factory to federated sharing app
*/
$l = $this->serverContainer->getL10N('federatedfilesharing');
$l = $this->serverContainer->get(IFactory::class)->get('federatedfilesharing');
$addressHandler = new AddressHandler(
$this->serverContainer->getURLGenerator(),
$l,
Expand Down Expand Up @@ -191,7 +192,7 @@ protected function getShareByMailProvider() {
$this->serverContainer->getSecureRandom(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getL10N('sharebymail'),
$this->serverContainer->get(IFactory::class)->get('sharebymail'),
$this->serverContainer->getLogger(),
$this->serverContainer->getMailer(),
$this->serverContainer->getURLGenerator(),
Expand Down Expand Up @@ -233,7 +234,7 @@ protected function getShareByCircleProvider() {
$this->serverContainer->getSecureRandom(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getL10N('circles'),
$this->serverContainer->get(IFactory::class)->get('circles'),
$this->serverContainer->getLogger(),
$this->serverContainer->getURLGenerator()
);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\ITags;
use OCP\L10N\IFactory;
use OCP\Share_Backend;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -235,7 +236,7 @@ public function getIdsForTag($tag) {
}

if ($tagId === false) {
$l10n = \OC::$server->getL10N('core');
$l10n = \OC::$server->get(IFactory::class)->get('core');
throw new \Exception(
$l10n->t('Could not find category "%s"', [$tag])
);
Expand Down
3 changes: 2 additions & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use OCP\IInitialStateService;
use OCP\INavigationManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Support\Subscription\IRegistry;
use OCP\Util;

Expand Down Expand Up @@ -225,7 +226,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'),
\OC::$server->get(IFactory::class)->get('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 @@ -415,7 +415,7 @@ public function createUser($uid, $password) {
* @throws \InvalidArgumentException
*/
public function createUserFromBackend($uid, $password, UserInterface $backend) {
$l = \OC::$server->getL10N('lib');
$l = \OC::$server->get(IFactory::class)->get('lib');

$this->validateUserId($uid, true);

Expand Down
5 changes: 3 additions & 2 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use OCP\ISession;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Lockdown\ILockdownManager;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -367,7 +368,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 = \OC::$server->get(IFactory::class)->get('lib')->t('User disabled');
throw new LoginException($message);
}

Expand Down Expand Up @@ -406,7 +407,7 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi
return true;
}

$message = \OC::$server->getL10N('lib')->t('Login canceled by app');
$message = \OC::$server->get(IFactory::class)->get('lib')->t('Login canceled by app');
throw new LoginException($message);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use OCP\Authentication\IAlternativeLogin;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\L10N\IFactory;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
Expand Down Expand Up @@ -560,7 +561,7 @@ public function listAllApps(): array {
//we don't want to show configuration for these
$blacklist = $appManager->getAlwaysEnabledApps();
$appList = [];
$langCode = \OC::$server->getL10N('core')->getLanguageCode();
$langCode = \OC::$server->get(IFactory::class)->get('core')->getLanguageCode();
$urlGenerator = \OC::$server->getURLGenerator();
$supportedApps = $this->getSupportedApps();

Expand Down Expand Up @@ -757,7 +758,7 @@ public static function updateApp(string $appId): bool {
}

\OC::$server->getAppManager()->clearAppsCache();
$l = \OC::$server->getL10N('core');
$l = \OC::$server->get(IFactory::class)->get('core');
$appData = \OCP\Server::get(\OCP\App\IAppManager::class)->getAppInfo($appId, false, $l->getLanguageCode());

$ignoreMaxApps = \OC::$server->getConfig()->getSystemValue('app_install_overwrite', []);
Expand Down
4 changes: 3 additions & 1 deletion lib/private/legacy/OC_Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*
*/

use OCP\L10N\IFactory;

class OC_Defaults {
private $theme;

Expand Down Expand Up @@ -237,7 +239,7 @@ public function getSlogan(?string $lang = null) {
return $this->theme->getSlogan($lang);
} else {
if ($this->defaultSlogan === null) {
$l10n = \OC::$server->getL10N('lib', $lang);
$l10n = \OC::$server->get(IFactory::class)->get('lib', $lang);
$this->defaultSlogan = $l10n->t('a safe home for all your data');
}
return $this->defaultSlogan;
Expand Down
Loading