Wrong file - Sorry!
This commit is contained in:
parent
4235ce0b63
commit
5223724809
73
lib/l10n.php
73
lib/l10n.php
|
@ -3,7 +3,7 @@
|
||||||
* ownCloud
|
* ownCloud
|
||||||
*
|
*
|
||||||
* @author Jakob Sack
|
* @author Jakob Sack
|
||||||
* @copyright 2012 Frank Karlitschek frank@owncloud.org
|
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
@ -39,16 +39,6 @@ class OC_L10N{
|
||||||
*/
|
*/
|
||||||
protected static $language = '';
|
protected static $language = '';
|
||||||
|
|
||||||
/**
|
|
||||||
* App of this object
|
|
||||||
*/
|
|
||||||
protected $app;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Language of this object
|
|
||||||
*/
|
|
||||||
protected $lang;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translations
|
* Translations
|
||||||
*/
|
*/
|
||||||
|
@ -87,17 +77,6 @@ class OC_L10N{
|
||||||
* language.
|
* language.
|
||||||
*/
|
*/
|
||||||
public function __construct($app, $lang = null){
|
public function __construct($app, $lang = null){
|
||||||
$this->app = $app;
|
|
||||||
$this->lang = $lang;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function init(){
|
|
||||||
if ($this->app === true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$app = $this->app;
|
|
||||||
$lang = $this->lang;
|
|
||||||
$this->app = true;
|
|
||||||
// Find the right language
|
// Find the right language
|
||||||
if(is_null($lang)){
|
if(is_null($lang)){
|
||||||
$lang = self::findLanguage($app);
|
$lang = self::findLanguage($app);
|
||||||
|
@ -113,9 +92,9 @@ class OC_L10N{
|
||||||
$i18ndir = self::findI18nDir($app);
|
$i18ndir = self::findI18nDir($app);
|
||||||
// Localization is in /l10n, Texts are in $i18ndir
|
// Localization is in /l10n, Texts are in $i18ndir
|
||||||
// (Just no need to define date/time format etc. twice)
|
// (Just no need to define date/time format etc. twice)
|
||||||
if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings')) && file_exists($i18ndir.$lang.'.php')) {
|
if(file_exists($i18ndir.$lang.'.php')){
|
||||||
// Include the file, save the data from $CONFIG
|
// Include the file, save the data from $CONFIG
|
||||||
include(strip_tags($i18ndir).strip_tags($lang).'.php');
|
include($i18ndir.$lang.'.php');
|
||||||
if(isset($TRANSLATIONS) && is_array($TRANSLATIONS)){
|
if(isset($TRANSLATIONS) && is_array($TRANSLATIONS)){
|
||||||
$this->translations = $TRANSLATIONS;
|
$this->translations = $TRANSLATIONS;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +123,10 @@ class OC_L10N{
|
||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
public function t($text, $parameters = array()){
|
public function t($text, $parameters = array()){
|
||||||
return new OC_L10N_String($this, $text, $parameters);
|
if(array_key_exists($text, $this->translations)){
|
||||||
|
return vsprintf($this->translations[$text], $parameters);
|
||||||
|
}
|
||||||
|
return vsprintf($text, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,7 +140,7 @@ class OC_L10N{
|
||||||
public function tA($textArray){
|
public function tA($textArray){
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach($textArray as $key => $text){
|
foreach($textArray as $key => $text){
|
||||||
$result[$key] = (string)$this->t($text);
|
$result[$key] = $this->t($text);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +152,6 @@ class OC_L10N{
|
||||||
* Returns an associative array with all translations
|
* Returns an associative array with all translations
|
||||||
*/
|
*/
|
||||||
public function getTranslations(){
|
public function getTranslations(){
|
||||||
$this->init();
|
|
||||||
return $this->translations;
|
return $this->translations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +178,6 @@ class OC_L10N{
|
||||||
* - params: timestamp (int/string)
|
* - params: timestamp (int/string)
|
||||||
*/
|
*/
|
||||||
public function l($type, $data){
|
public function l($type, $data){
|
||||||
$this->init();
|
|
||||||
switch($type){
|
switch($type){
|
||||||
// If you add something don't forget to add it to $localizations
|
// If you add something don't forget to add it to $localizations
|
||||||
// at the top of the page
|
// at the top of the page
|
||||||
|
@ -244,29 +224,23 @@ class OC_L10N{
|
||||||
return self::$language;
|
return self::$language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$available = array();
|
||||||
|
if(is_array($app)){
|
||||||
|
$available = $app;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$available=self::findAvailableLanguages($app);
|
||||||
|
}
|
||||||
if(OC_User::getUser() && OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang')){
|
if(OC_User::getUser() && OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang')){
|
||||||
$lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang');
|
$lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang');
|
||||||
self::$language = $lang;
|
self::$language = $lang;
|
||||||
if(is_array($app)){
|
if(array_search($lang, $available) !== false){
|
||||||
$available = $app;
|
|
||||||
$lang_exists = array_search($lang, $available) !== false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$lang_exists = self::languageExists($app, $lang);
|
|
||||||
}
|
|
||||||
if($lang_exists){
|
|
||||||
return $lang;
|
return $lang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
||||||
$accepted_languages = preg_split('/,\s*/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$accepted_languages = preg_split('/,\s*/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
if(is_array($app)){
|
|
||||||
$available = $app;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$available = self::findAvailableLanguages($app);
|
|
||||||
}
|
|
||||||
foreach($accepted_languages as $i){
|
foreach($accepted_languages as $i){
|
||||||
$temp = explode(';', $i);
|
$temp = explode(';', $i);
|
||||||
if(array_search($temp[0], $available) !== false){
|
if(array_search($temp[0], $available) !== false){
|
||||||
|
@ -289,8 +263,8 @@ class OC_L10N{
|
||||||
$i18ndir = OC::$SERVERROOT.'/core/l10n/';
|
$i18ndir = OC::$SERVERROOT.'/core/l10n/';
|
||||||
if($app != ''){
|
if($app != ''){
|
||||||
// Check if the app is in the app folder
|
// Check if the app is in the app folder
|
||||||
if(file_exists(OC_App::getAppPath($app).'/l10n/')){
|
if(file_exists(OC::$APPSROOT.'/apps/'.$app.'/l10n/')){
|
||||||
$i18ndir = OC_App::getAppPath($app).'/l10n/';
|
$i18ndir = OC::$APPSROOT.'/apps/'.$app.'/l10n/';
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/';
|
$i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/';
|
||||||
|
@ -318,15 +292,4 @@ class OC_L10N{
|
||||||
}
|
}
|
||||||
return $available;
|
return $available;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function languageExists($app, $lang){
|
|
||||||
if ($lang == 'en'){//english is always available
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
$dir = self::findI18nDir($app);
|
|
||||||
if(is_dir($dir)){
|
|
||||||
return file_exists($dir.'/'.$lang.'.php');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue