@@ -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'; | |||
} | |||
if (!isset($this->instances[$key][$app])) { | |||
$this->instances[$key][$app] = new \OC_L10N($app, $lang); | |||
} | |||
return $this->instances[$app]; | |||
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); | |||
} | |||
/** |
@@ -0,0 +1,32 @@ | |||
<?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; | |||
interface IFactory { | |||
/** | |||
* Get a language instance | |||
* | |||
* @param string $app | |||
* @param string|null $lang | |||
* @return \OCP\IL10N | |||
*/ | |||
public function get($app, $lang = null); | |||
} |