Merge pull request #18620 from owncloud/add-public-interface-for-factory
Add a public interface for the language factory so apps can use it
This commit is contained in:
commit
723f8c8f1b
|
@ -81,14 +81,11 @@ class OC_L10N implements \OCP\IL10N {
|
|||
* get an L10N instance
|
||||
* @param string $app
|
||||
* @param string|null $lang
|
||||
* @return \OC_L10N
|
||||
* @return \OCP\IL10N
|
||||
* @deprecated Use \OC::$server->getL10NFactory()->get() instead
|
||||
*/
|
||||
public static function get($app, $lang=null) {
|
||||
if (is_null($lang)) {
|
||||
return OC::$server->getL10N($app);
|
||||
} else {
|
||||
return new \OC_L10N($app, $lang);
|
||||
}
|
||||
return \OC::$server->getL10NFactory()->get($app, $lang);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,29 +25,35 @@
|
|||
|
||||
namespace OC\L10N;
|
||||
|
||||
use OCP\L10N\IFactory;
|
||||
|
||||
/**
|
||||
* TODO: Description
|
||||
* A factory that generates language instances
|
||||
*/
|
||||
class Factory {
|
||||
class Factory implements IFactory {
|
||||
/**
|
||||
* cached instances
|
||||
*/
|
||||
protected $instances = array();
|
||||
|
||||
/**
|
||||
* get an L10N instance
|
||||
* Get a language instance
|
||||
*
|
||||
* @param string $app
|
||||
* @param string|null $lang
|
||||
* @return \OC_L10N
|
||||
* @return \OCP\IL10N
|
||||
*/
|
||||
public function get($app, $lang = null) {
|
||||
if (!is_null($lang)) {
|
||||
return new \OC_L10N($app, $lang);
|
||||
} else if (!isset($this->instances[$app])) {
|
||||
$this->instances[$app] = new \OC_L10N($app);
|
||||
$key = $lang;
|
||||
if ($key === null) {
|
||||
$key = 'null';
|
||||
}
|
||||
return $this->instances[$app];
|
||||
|
||||
if (!isset($this->instances[$key][$app])) {
|
||||
$this->instances[$key][$app] = new \OC_L10N($app, $lang);
|
||||
}
|
||||
|
||||
return $this->instances[$key][$app];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -673,6 +673,13 @@ class Server extends SimpleContainer implements IServerContainer {
|
|||
return $this->query('AppConfig');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \OCP\L10N\IFactory
|
||||
*/
|
||||
public function getL10NFactory() {
|
||||
return $this->query('L10NFactory');
|
||||
}
|
||||
|
||||
/**
|
||||
* get an L10N instance
|
||||
*
|
||||
|
@ -681,7 +688,7 @@ class Server extends SimpleContainer implements IServerContainer {
|
|||
* @return \OC_L10N
|
||||
*/
|
||||
public function getL10N($app, $lang = null) {
|
||||
return $this->query('L10NFactory')->get($app, $lang);
|
||||
return $this->getL10NFactory()->get($app, $lang);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -100,7 +100,7 @@ interface IL10N {
|
|||
|
||||
|
||||
/**
|
||||
* The code (en, de, ...) of the language that is used for this OC_L10N object
|
||||
* The code (en, de, ...) of the language that is used for this IL10N object
|
||||
*
|
||||
* @return string language
|
||||
* @since 7.0.0
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
namespace OCP\L10N;
|
||||
|
||||
/**
|
||||
* @since 8.2.0
|
||||
*/
|
||||
interface IFactory {
|
||||
/**
|
||||
* Get a language instance
|
||||
*
|
||||
* @param string $app
|
||||
* @param string|null $lang
|
||||
* @return \OCP\IL10N
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function get($app, $lang = null);
|
||||
}
|
|
@ -90,6 +90,7 @@ class Server extends \Test\TestCase {
|
|||
['JobList', '\OCP\BackgroundJob\IJobList'],
|
||||
|
||||
['L10NFactory', '\OC\L10N\Factory'],
|
||||
['L10NFactory', '\OCP\L10N\IFactory'],
|
||||
['LockingProvider', '\OCP\Lock\ILockingProvider'],
|
||||
['Logger', '\OC\Log'],
|
||||
['Logger', '\OCP\ILogger'],
|
||||
|
|
Loading…
Reference in New Issue