Skip to content

Commit b2b6d3c

Browse files
committed
Refactor OC\Server::getL10NFactory
Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
1 parent 613cd16 commit b2b6d3c

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

lib/private/Share20/ProviderFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Defaults;
4545
use OCP\EventDispatcher\IEventDispatcher;
4646
use OCP\IServerContainer;
47+
use OCP\L10N\IFactory;
4748
use OCP\Share\IManager;
4849
use OCP\Share\IProviderFactory;
4950
use OCP\Share\IShare;
@@ -102,7 +103,7 @@ protected function defaultShareProvider() {
102103
$this->serverContainer->getLazyRootFolder(),
103104
$this->serverContainer->getMailer(),
104105
$this->serverContainer->query(Defaults::class),
105-
$this->serverContainer->getL10NFactory(),
106+
$this->serverContainer->get(IFactory::class),
106107
$this->serverContainer->getURLGenerator(),
107108
$this->serverContainer->getConfig()
108109
);

lib/private/TemplateLayout.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use OCP\IInitialStateService;
5454
use OCP\INavigationManager;
5555
use OCP\IUserSession;
56+
use OCP\L10N\IFactory;
5657
use OCP\Support\Subscription\IRegistry;
5758
use OCP\Util;
5859

@@ -126,7 +127,7 @@ public function __construct($renderAs, $appId = '') {
126127
// Set default app name
127128
$defaultApp = \OC::$server->getAppManager()->getDefaultAppForUser();
128129
$defaultAppInfo = \OC::$server->getAppManager()->getAppInfo($defaultApp);
129-
$l10n = \OC::$server->getL10NFactory()->get($defaultApp);
130+
$l10n = \OC::$server->get(IFactory::class)->get($defaultApp);
130131
$this->assign('defaultAppName', $l10n->t($defaultAppInfo['name']));
131132

132133
// Add navigation entry
@@ -200,8 +201,8 @@ public function __construct($renderAs, $appId = '') {
200201
parent::__construct('core', 'layout.base');
201202
}
202203
// Send the language and the locale to our layouts
203-
$lang = \OC::$server->getL10NFactory()->findLanguage();
204-
$locale = \OC::$server->getL10NFactory()->findLocale($lang);
204+
$lang = \OC::$server->get(IFactory::class)->findLanguage();
205+
$locale = \OC::$server->get(IFactory::class)->findLocale($lang);
205206

206207
$lang = str_replace('_', '-', $lang);
207208
$this->assign('language', $lang);

lib/private/legacy/OC_Util.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
use OCP\IGroupManager;
7272
use OCP\IURLGenerator;
7373
use OCP\IUser;
74+
use OCP\L10N\IFactory;
7475
use OCP\Share\IManager;
7576
use Psr\Log\LoggerInterface;
7677

@@ -184,7 +185,7 @@ public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
184185
$logger = \OC::$server->get(LoggerInterface::class);
185186

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

190191
if (!file_exists($skeletonDirectory)) {
@@ -403,7 +404,7 @@ public static function addVendorScript($application, $file = null, $prepend = fa
403404
*/
404405
public static function addTranslations($application, $languageCode = null, $prepend = false) {
405406
if (is_null($languageCode)) {
406-
$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
407+
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
407408
}
408409
if (!empty($application)) {
409410
$path = "$application/l10n/$languageCode";

lib/public/Util.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
use OC\AppScriptDependency;
5050
use OC\AppScriptSort;
51+
use OCP\L10N\IFactory;
5152
use bantu\IniGetWrapper\IniGetWrapper;
5253
use Psr\Container\ContainerExceptionInterface;
5354

@@ -235,7 +236,7 @@ public static function getScripts(): array {
235236
*/
236237
public static function addTranslations($application, $languageCode = null) {
237238
if (is_null($languageCode)) {
238-
$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
239+
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
239240
}
240241
if (!empty($application)) {
241242
$path = "$application/l10n/$languageCode";

tests/lib/L10N/L10nTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\IConfig;
1616
use OCP\IRequest;
1717
use OCP\IUserSession;
18+
use OCP\L10N\IFactory;
1819
use Test\TestCase;
1920

2021
/**
@@ -218,7 +219,7 @@ public function testWeekdayName() {
218219
public function testFindLanguageFromLocale($locale, $language) {
219220
$this->assertEquals(
220221
$language,
221-
\OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale)
222+
\OC::$server->get(IFactory::class)->findLanguageFromLocale('lib', $locale)
222223
);
223224
}
224225

0 commit comments

Comments
 (0)