Browse Source

Refactor `OC\Server::getL10NFactory`

Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
pull/40141/head
Andrew Summers 2 years ago
parent
commit
f80282a5ed
No known key found for this signature in database GPG Key ID: 1E0B639A223E3E2D
  1. 3
      lib/private/Share20/ProviderFactory.php
  2. 7
      lib/private/TemplateLayout.php
  3. 5
      lib/private/legacy/OC_Util.php
  4. 3
      lib/public/Util.php
  5. 3
      tests/lib/L10N/L10nTest.php

3
lib/private/Share20/ProviderFactory.php

@ -44,6 +44,7 @@ use OCA\Talk\Share\RoomShareProvider;
use OCP\Defaults; use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\L10N\IFactory;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Share\IProviderFactory; use OCP\Share\IProviderFactory;
use OCP\Share\IShare; use OCP\Share\IShare;
@ -102,7 +103,7 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getLazyRootFolder(), $this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getMailer(), $this->serverContainer->getMailer(),
$this->serverContainer->query(Defaults::class), $this->serverContainer->query(Defaults::class),
$this->serverContainer->getL10NFactory(),
$this->serverContainer->get(IFactory::class),
$this->serverContainer->getURLGenerator(), $this->serverContainer->getURLGenerator(),
$this->serverContainer->getConfig() $this->serverContainer->getConfig()
); );

7
lib/private/TemplateLayout.php

@ -53,6 +53,7 @@ use OCP\IConfig;
use OCP\IInitialStateService; use OCP\IInitialStateService;
use OCP\INavigationManager; use OCP\INavigationManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Support\Subscription\IRegistry; use OCP\Support\Subscription\IRegistry;
use OCP\Util; use OCP\Util;
@ -126,7 +127,7 @@ class TemplateLayout extends \OC_Template {
// Set default app name // Set default app name
$defaultApp = \OC::$server->getAppManager()->getDefaultAppForUser(); $defaultApp = \OC::$server->getAppManager()->getDefaultAppForUser();
$defaultAppInfo = \OC::$server->getAppManager()->getAppInfo($defaultApp); $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'])); $this->assign('defaultAppName', $l10n->t($defaultAppInfo['name']));
// Add navigation entry // Add navigation entry
@ -200,8 +201,8 @@ class TemplateLayout extends \OC_Template {
parent::__construct('core', 'layout.base'); parent::__construct('core', 'layout.base');
} }
// Send the language and the locale to our layouts // 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); $lang = str_replace('_', '-', $lang);
$this->assign('language', $lang); $this->assign('language', $lang);

5
lib/private/legacy/OC_Util.php

@ -71,6 +71,7 @@ use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory;
use OCP\Share\IManager; use OCP\Share\IManager;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -184,7 +185,7 @@ class OC_Util {
$logger = \OC::$server->get(LoggerInterface::class); $logger = \OC::$server->get(LoggerInterface::class);
$plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValueString('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); $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); $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory);
if (!file_exists($skeletonDirectory)) { if (!file_exists($skeletonDirectory)) {
@ -403,7 +404,7 @@ class OC_Util {
*/ */
public static function addTranslations($application, $languageCode = null, $prepend = false) { public static function addTranslations($application, $languageCode = null, $prepend = false) {
if (is_null($languageCode)) { if (is_null($languageCode)) {
$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
} }
if (!empty($application)) { if (!empty($application)) {
$path = "$application/l10n/$languageCode"; $path = "$application/l10n/$languageCode";

3
lib/public/Util.php

@ -48,6 +48,7 @@ namespace OCP;
use OC\AppScriptDependency; use OC\AppScriptDependency;
use OC\AppScriptSort; use OC\AppScriptSort;
use OCP\L10N\IFactory;
use bantu\IniGetWrapper\IniGetWrapper; use bantu\IniGetWrapper\IniGetWrapper;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
@ -235,7 +236,7 @@ class Util {
*/ */
public static function addTranslations($application, $languageCode = null) { public static function addTranslations($application, $languageCode = null) {
if (is_null($languageCode)) { if (is_null($languageCode)) {
$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application);
} }
if (!empty($application)) { if (!empty($application)) {
$path = "$application/l10n/$languageCode"; $path = "$application/l10n/$languageCode";

3
tests/lib/L10N/L10nTest.php

@ -15,6 +15,7 @@ use OCP\ICacheFactory;
use OCP\IConfig; use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory;
use Test\TestCase; use Test\TestCase;
/** /**
@ -218,7 +219,7 @@ class L10nTest extends TestCase {
public function testFindLanguageFromLocale($locale, $language) { public function testFindLanguageFromLocale($locale, $language) {
$this->assertEquals( $this->assertEquals(
$language, $language,
\OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale)
\OC::$server->get(IFactory::class)->findLanguageFromLocale('lib', $locale)
); );
} }

Loading…
Cancel
Save