From f80282a5ed1891224e3fa71c69ca2d60412c4c63 Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:25:03 -0500 Subject: [PATCH 1/2] Refactor `OC\Server::getL10NFactory` Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- lib/private/Share20/ProviderFactory.php | 3 ++- lib/private/TemplateLayout.php | 7 ++++--- lib/private/legacy/OC_Util.php | 5 +++-- lib/public/Util.php | 3 ++- tests/lib/L10N/L10nTest.php | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 8c01d6609155c..c1b77cd88a85e 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -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; @@ -102,7 +103,7 @@ protected function defaultShareProvider() { $this->serverContainer->getLazyRootFolder(), $this->serverContainer->getMailer(), $this->serverContainer->query(Defaults::class), - $this->serverContainer->getL10NFactory(), + $this->serverContainer->get(IFactory::class), $this->serverContainer->getURLGenerator(), $this->serverContainer->getConfig() ); diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 658a85152bf49..6c3f97e66ffe3 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -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; @@ -126,7 +127,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 @@ -200,8 +201,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); diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 9d62c46137e61..1d13f94e83644 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -71,6 +71,7 @@ use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUser; +use OCP\L10N\IFactory; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -184,7 +185,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)) { @@ -403,7 +404,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"; diff --git a/lib/public/Util.php b/lib/public/Util.php index bff8038b3dda5..d6642daf864f8 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -48,6 +48,7 @@ use OC\AppScriptDependency; use OC\AppScriptSort; +use OCP\L10N\IFactory; use bantu\IniGetWrapper\IniGetWrapper; use Psr\Container\ContainerExceptionInterface; @@ -235,7 +236,7 @@ public static function getScripts(): array { */ public static function addTranslations($application, $languageCode = null) { 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"; diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index bd1fce295472b..21be2bbf3959b 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -15,6 +15,7 @@ use OCP\IConfig; use OCP\IRequest; use OCP\IUserSession; +use OCP\L10N\IFactory; use Test\TestCase; /** @@ -218,7 +219,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) ); } From 0963336fb1565fe8b7c496fccda5c74c06f863a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 30 May 2024 14:44:20 +0200 Subject: [PATCH 2/2] chore: fix missing semi-colon in refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- lib/public/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/Util.php b/lib/public/Util.php index 7e9ddb6788b84..20b4fe9c20d33 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -16,7 +16,7 @@ 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