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::getL10NFactory #40141

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\Federation\ICloudFederationFactory;
use OCP\Files\IRootFolder;
use OCP\IServerContainer;
use OCP\L10N\IFactory;
use OCP\Security\IHasher;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
Expand Down Expand Up @@ -80,7 +81,7 @@ protected function defaultShareProvider() {
$this->serverContainer->get(IRootFolder::class),
$this->serverContainer->getMailer(),
$this->serverContainer->query(Defaults::class),
$this->serverContainer->getL10NFactory(),
$this->serverContainer->get(IFactory::class),
$this->serverContainer->getURLGenerator(),
$this->serverContainer->query(ITimeFactory::class),
);
Expand Down
7 changes: 4 additions & 3 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Support\Subscription\IRegistry;
use OCP\Util;

Expand Down Expand Up @@ -97,7 +98,7 @@ public function __construct($renderAs, $appId = '') {
// Set default app name
$defaultApp = \OC::$server->getAppManager()->getDefaultAppForUser();
$defaultAppInfo = \OC::$server->getAppManager()->getAppInfo($defaultApp);
$l10n = \OC::$server->getL10NFactory()->get($defaultApp);
$l10n = \OC::$server->get(IFactory::class)->get($defaultApp);
$this->assign('defaultAppName', $l10n->t($defaultAppInfo['name']));

// Add navigation entry
Expand Down Expand Up @@ -189,8 +190,8 @@ public function __construct($renderAs, $appId = '') {
parent::__construct('core', 'layout.base');
}
// Send the language and the locale to our layouts
$lang = \OC::$server->getL10NFactory()->findLanguage();
$locale = \OC::$server->getL10NFactory()->findLocale($lang);
$lang = \OC::$server->get(IFactory::class)->findLanguage();
$locale = \OC::$server->get(IFactory::class)->findLocale($lang);

$lang = str_replace('_', '-', $lang);
$this->assign('language', $lang);
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\L10N\IFactory;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -126,7 +127,7 @@ public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
$logger = \OC::$server->get(LoggerInterface::class);

$plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValueString('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
$userLang = \OC::$server->getL10NFactory()->findLanguage();
$userLang = \OC::$server->get(IFactory::class)->findLanguage();
$skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory);

if (!file_exists($skeletonDirectory)) {
Expand Down Expand Up @@ -346,7 +347,7 @@ public static function addVendorScript($application, $file = null, $prepend = fa
*/
public static function addTranslations($application, $languageCode = null, $prepend = false) {
if (is_null($languageCode)) {
$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
}
if (!empty($application)) {
$path = "$application/l10n/$languageCode";
Expand Down
5 changes: 3 additions & 2 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
use bantu\IniGetWrapper\IniGetWrapper;
use OC\AppScriptDependency;
use OC\AppScriptSort;
use OCP\L10N\IFactory;
use OCP\Share\IManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerInterface

/**
* This class provides different helper functions to make the life of a developer easier
*
* @since 4.0.0
*/
class Util {

Check failure on line 26 in lib/public/Util.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

ParseError

lib/public/Util.php:26:1: ParseError: Syntax error, unexpected T_CLASS, expecting ';' on line 26 (see https://psalm.dev/173)

Check failure on line 26 in lib/public/Util.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

lib/public/Util.php:26:1: ParseError: Syntax error, unexpected T_CLASS, expecting ';' on line 26 (see https://psalm.dev/173)
private static ?IManager $shareManager = null;

private static array $scriptsInit = [];
Expand Down Expand Up @@ -206,7 +207,7 @@
*/
public static function addTranslations($application, $languageCode = null, $init = false) {
if (is_null($languageCode)) {
$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
}
if (!empty($application)) {
$path = "$application/l10n/$languageCode";
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/L10N/L10nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use Test\TestCase;

/**
Expand Down Expand Up @@ -219,7 +220,7 @@ public function testWeekdayName() {
public function testFindLanguageFromLocale($locale, $language) {
$this->assertEquals(
$language,
\OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale)
\OC::$server->get(IFactory::class)->findLanguageFromLocale('lib', $locale)
);
}

Expand Down
Loading