reuse OC_L10N objects

This commit is contained in:
Robin Appelman 2012-04-14 16:44:15 +02:00
parent 721311c909
commit b1bcc60d83
33 changed files with 52 additions and 38 deletions

View File

@ -1,5 +1,5 @@
<?php
$l=new OC_L10N('admin_dependencies_chk');
$l=OC_L10N::get('admin_dependencies_chk');
OC_App::register( array(
'order' => 14,

View File

@ -20,7 +20,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
$l=new OC_L10N('admin_dependencies_chk');
$l=OC_L10N::get('admin_dependencies_chk');
$tmpl = new OC_Template( 'admin_dependencies_chk', 'settings');
$modules = array();

View File

@ -94,7 +94,7 @@ function addBookmark($url, $title, $tags='') {
}
if(empty($title)) {
$l = new OC_L10N('bookmarks');
$l = OC_L10N::get('bookmarks');
$title = $l->t('unnamed');
}

View File

@ -1,7 +1,7 @@
<?php
function createBookmarklet() {
$l = new OC_L10N('bookmarks');
$l = OC_L10N::get('bookmarks');
echo '<small>' . $l->t('Drag this to your browser bookmarks and click it, when you want to bookmark a webpage quickly:') . '</small>'
. '<a class="bookmarklet" href="javascript:(function(){var a=window,b=document,c=encodeURIComponent,d=a.open(\'' . OC_Helper::linkToAbsolute('bookmarks', 'addBm.php') . '?output=popup&url=\'+c(b.location),\'bkmk_popup\',\'left=\'+((a.screenX||a.screenLeft)+10)+\',top=\'+((a.screenY||a.screenTop)+10)+\',height=230px,width=230px,resizable=1,alwaysRaised=1\');a.setTimeout(function(){d.focus()},300);})();">'
. $l->t('Read later') . '</a>';

View File

@ -7,7 +7,6 @@
*/
require_once('../../../../lib/base.php');
$l10n = new OC_L10N('calendar');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');
$calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions();

View File

@ -7,7 +7,7 @@
*/
require_once('../../../../lib/base.php');
$l10n = new OC_L10N('calendar');
$l10n = OC_L10N::get('calendar');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');
$output = new OC_TEMPLATE("calendar", "part.choosecalendar");

View File

@ -7,8 +7,6 @@
*/
require_once('../../../../lib/base.php');
$l10n = new OC_L10N('calendar');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');

View File

@ -8,8 +8,6 @@
require_once('../../../../lib/base.php');
$l10n = new OC_L10N('calendar');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');

View File

@ -8,7 +8,7 @@
require_once ('../../../lib/base.php');
require_once('when/When.php');
$l = new OC_L10N('calendar');
$l = OC_L10N::get('calendar');
$unnamed = $l->t('unnamed');
function create_return_event($event, $vevent){
$return_event = array();

View File

@ -9,7 +9,6 @@
require_once('../../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_Util::checkAppEnabled('calendar');
$l10n = new OC_L10N('calendar');
$tmpl = new OC_Template('calendar', 'part.import');
$tmpl->assign('path', $_POST['path']);
$tmpl->assign('filename', $_POST['filename']);

View File

@ -10,7 +10,7 @@ require_once('../../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');
$l = new OC_L10N('calendar');
$l = OC_L10N::get('calendar');
$lat = $_GET['lat'];
$lng = $_GET['long'];

View File

@ -9,7 +9,7 @@
// Init owncloud
require_once('../../../../lib/base.php');
$l=new OC_L10N('calendar');
$l=OC_L10N::get('calendar');
// Check if we are a user
OC_JSON::checkLoggedIn();

View File

@ -1,5 +1,5 @@
<?php
$l=new OC_L10N('calendar');
$l=OC_L10N::get('calendar');
OC::$CLASSPATH['OC_Calendar_App'] = 'apps/calendar/lib/app.php';
OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php';
OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php';

View File

@ -9,7 +9,7 @@
/**
* This class manages our app actions
*/
OC_Calendar_App::$l10n = new OC_L10N('calendar');
OC_Calendar_App::$l10n = OC_L10N::get('calendar');
class OC_Calendar_App{
public static $l10n;
protected static $categories = null;

View File

@ -9,7 +9,7 @@
/**
* This class manages our app actions
*/
OC_Contacts_App::$l10n = new OC_L10N('contacts');
OC_Contacts_App::$l10n = OC_L10N::get('contacts');
OC_Contacts_App::$categories = new OC_VCategories('contacts');
class OC_Contacts_App {
public static $l10n;

View File

@ -27,7 +27,7 @@ OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php';
OC::$CLASSPATH['OC_Gallery_Sharing'] = 'apps/gallery/lib/sharing.php';
OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'apps/gallery/lib/hooks_handlers.php';
$l = new OC_L10N('gallery');
$l = OC_L10N::get('gallery');
OC_App::register(array(
'order' => 20,

View File

@ -7,7 +7,7 @@ OC_Util::addStyle('files', 'files');
OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
$l = new OC_L10N('gallery');
$l = OC_L10N::get('gallery');
?>
<script type="text/javascript">var gallery_scanning_root='<? echo OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/'); ?>'; var gallery_default_order = '<? echo OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'order', 'ASC'); ?>';</script>
<div id="controls">

View File

@ -5,7 +5,7 @@ OC_Util::addScript('gallery', 'album_cover');
OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
$l = new OC_L10N('gallery');
$l = OC_L10N::get('gallery');
?>
<script type="text/javascript">
$(document).ready(function() {

View File

@ -20,7 +20,7 @@
*
*/
$l=new OC_L10N('media');
$l=OC_L10N::get('media');
require_once('apps/media/lib_media.php');

View File

@ -26,7 +26,7 @@ require_once('../../lib/base.php');
$app = $_POST["app"];
$l = new OC_L10N( $app );
$l = OC_L10N::get( $app );
OC_JSON::success(array('data' => $l->getTranslations()));
?>

View File

@ -20,7 +20,7 @@ if (isset($_POST['user'])) {
$tmpl = new OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link);
$msg = $tmpl->fetchPage();
$l = new OC_L10N('core');
$l = OC_L10N::get('core');
$from = 'lostpassword-noreply@' . $_SERVER['HTTP_HOST'];
mail($email, $l->t('Owncloud password reset'), $msg, 'From:' . $from);
}

View File

@ -1,7 +1,7 @@
<?php
//some strings that are used in /lib but wont be translatable unless they are in /core too
$l=new OC_L10N('core');
$l=OC_L10N::get('core');
$l->t("Personal");
$l->t("Users");
$l->t("Apps");

View File

@ -14,7 +14,7 @@ if (!isset($_FILES['files'])) {
}
foreach ($_FILES['files']['error'] as $error) {
if ($error != 0) {
$l=new OC_L10N('files');
$l=OC_L10N::get('files');
$errors = array(
UPLOAD_ERR_OK=>$l->t("There is no error, the file uploaded with success"),
UPLOAD_ERR_INI_SIZE=>$l->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),

View File

@ -1,7 +1,7 @@
<?php
$l=new OC_L10N('files');
$l=OC_L10N::get('files');
OC_App::register( array( "order" => 2, "id" => "files", "name" => "Files" ));

View File

@ -254,7 +254,7 @@ class OC_App{
* entries are sorted by the key 'order' ascending.
*/
public static function getSettingsNavigation(){
$l=new OC_L10N('core');
$l=OC_L10N::get('core');
$settings = array();
// by default, settings only contain the help menu

View File

@ -225,7 +225,7 @@ class OC_Files {
*/
static function validateZipDownload($dir, $files) {
if(!OC_Config::getValue('allowZipDownload', true)) {
$l = new OC_L10N('files');
$l = OC_L10N::get('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template( '', 'error', 'user' );
$errors = array(
@ -250,7 +250,7 @@ class OC_Files {
$totalsize += OC_Filesystem::filesize($dir.'/'.$files);
}
if($totalsize > $zipLimit) {
$l = new OC_L10N('files');
$l = OC_L10N::get('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template( '', 'error', 'user' );
$errors = array(

View File

@ -24,7 +24,7 @@ class OC_JSON{
*/
public static function checkAppEnabled($app){
if( !OC_App::isEnabled($app)){
$l = new OC_L10N('core');
$l = OC_L10N::get('core');
self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled') )));
exit();
}
@ -35,7 +35,7 @@ class OC_JSON{
*/
public static function checkLoggedIn(){
if( !OC_User::isLoggedIn()){
$l = new OC_L10N('core');
$l = OC_L10N::get('core');
self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
exit();
}
@ -47,7 +47,7 @@ class OC_JSON{
public static function checkAdminUser(){
self::checkLoggedIn();
if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
$l = new OC_L10N('core');
$l = OC_L10N::get('core');
self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
exit();
}

View File

@ -24,6 +24,11 @@
* This class is for i18n and l10n
*/
class OC_L10N{
/**
* cached instances
*/
protected static $instances=array();
/**
* cache
*/
@ -46,6 +51,21 @@ class OC_L10N{
'date' => 'd.m.Y',
'datetime' => 'd.m.Y H:i:s',
'time' => 'H:i:s');
/**
* get an L10N instance
* @return OC_L10N
*/
public static function get($app,$lang=null){
if(is_null($lang)){
if(!isset(self::$instances[$app])){
self::$instances[$app]=new OC_L10N($app);
}
return self::$instances[$app];
}else{
return new OC_L10N($app,$lang);
}
}
/**
* @brief The constructor

View File

@ -76,7 +76,7 @@ function simple_file_size($bytes) {
}
function relative_modified_date($timestamp) {
$l=new OC_L10N('template');
$l=OC_L10N::get('template');
$timediff = time() - $timestamp;
$diffminutes = round($timediff/60);
$diffhours = round($diffminutes/60);
@ -155,7 +155,7 @@ class OC_Template{
$this->renderas = $renderas;
$this->application = $app;
$this->vars = array();
$this->l10n = new OC_L10N($app);
$this->l10n = OC_L10N::get($app);
$this->findTemplate($name);
}

View File

@ -5,7 +5,7 @@ require_once('../../lib/base.php');
OC_JSON::checkLoggedIn();
$l=new OC_L10N('core');
$l=OC_L10N::get('core');
// Get data
if( isset( $_POST['email'] ) ){

View File

@ -3,7 +3,7 @@
// Init owncloud
require_once('../../lib/base.php');
$l=new OC_L10N('settings');
$l=OC_L10N::get('settings');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('user_openid');

View File

@ -3,7 +3,7 @@
// Init owncloud
require_once('../../lib/base.php');
$l=new OC_L10N('settings');
$l=OC_L10N::get('settings');
OC_JSON::checkLoggedIn();

View File

@ -35,7 +35,7 @@ array_unshift($languageCodes,$lang);
$languageNames=include 'languageCodes.php';
$languages=array();
foreach($languageCodes as $lang){
$l=new OC_L10N('settings',$lang);
$l=OC_L10N::get('settings',$lang);
if(substr($l->t('__language_name__'),0,1)!='_'){//first check if the language name is in the translation file
$languages[]=array('code'=>$lang,'name'=>$l->t('__language_name__'));
}elseif(isset($languageNames[$lang])){