2015-01-18 07:36:00 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Get the text for the correct translation
|
2015-01-18 10:25:50 +01:00
|
|
|
*
|
2015-01-18 07:36:00 +01:00
|
|
|
* @method array get
|
|
|
|
|
*/
|
|
|
|
|
class text {
|
|
|
|
|
/**
|
|
|
|
|
* Called when the object is created
|
|
|
|
|
*/
|
|
|
|
|
public function __construct() {
|
2015-01-18 08:52:28 +01:00
|
|
|
//place holder
|
2015-01-18 07:36:00 +01:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Called when there are no references to a particular object
|
|
|
|
|
* unset the variables used in the class
|
|
|
|
|
*/
|
|
|
|
|
public function __destruct() {
|
|
|
|
|
foreach ($this as $key => $value) {
|
|
|
|
|
unset($this->$key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get a specific item from the cache
|
2015-01-18 08:42:17 +01:00
|
|
|
* @var string $language_code examples: en-us, es-cl, fr-fr, pt-pt
|
|
|
|
|
* @var string $app_path examples: app/exec or core/domains
|
2015-01-18 07:36:00 +01:00
|
|
|
*/
|
2015-01-18 08:42:17 +01:00
|
|
|
public function get($language_code = null, $app_path = null) {
|
2015-11-16 10:41:34 +01:00
|
|
|
//get the global app_languages.php
|
2015-12-10 10:57:08 +01:00
|
|
|
include $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/app_languages.php";
|
2015-01-18 07:36:00 +01:00
|
|
|
//get the app_languages.php
|
2015-01-18 11:40:41 +01:00
|
|
|
if ($app_path != null) {
|
2015-12-10 10:57:08 +01:00
|
|
|
$lang_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/".$app_path."/app_languages.php";
|
2015-01-18 07:36:00 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2015-12-10 10:57:08 +01:00
|
|
|
$lang_path = getcwd().'/app_languages.php';
|
2015-01-18 07:36:00 +01:00
|
|
|
}
|
2015-12-10 10:57:08 +01:00
|
|
|
if(file_exists($lang_path)){
|
|
|
|
|
require $lang_path;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 08:52:28 +01:00
|
|
|
//get the available languages
|
|
|
|
|
krsort($text);
|
|
|
|
|
foreach ($text as $lang_label => $lang_codes) {
|
|
|
|
|
foreach ($lang_codes as $lang_code => $lang_text) {
|
|
|
|
|
if ($lang_text != '') {
|
|
|
|
|
$app_languages[] = $lang_code;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$_SESSION['app']['languages'] = array_unique($app_languages);
|
2015-11-16 10:41:34 +01:00
|
|
|
//check the session language
|
2015-12-10 10:57:08 +01:00
|
|
|
if(isset($_SESSION['domain']) and $language_code == null){
|
2015-11-16 10:41:34 +01:00
|
|
|
$language_code = $_SESSION['domain']['language']['code'];
|
|
|
|
|
}elseif($language_code == null){
|
|
|
|
|
$language_code = 'en-us';
|
|
|
|
|
}
|
2015-01-18 10:25:50 +01:00
|
|
|
//reduce to specific language
|
2015-01-18 08:42:17 +01:00
|
|
|
if ($language_code != 'all') {
|
|
|
|
|
foreach($text as $key => $value) {
|
2015-12-10 10:57:54 +01:00
|
|
|
if(strlen($value[$language_code]) > 0) {
|
|
|
|
|
$text[$key] = $value[$language_code];
|
|
|
|
|
}else{
|
|
|
|
|
//fallback to en-us
|
|
|
|
|
$text[$key] = $value['en-us'];
|
|
|
|
|
}
|
2015-01-18 08:42:17 +01:00
|
|
|
}
|
2015-01-18 07:36:00 +01:00
|
|
|
}
|
2015-11-17 17:01:03 +01:00
|
|
|
if ($language_code != 'all') {
|
|
|
|
|
foreach($language_name as $code => $value) {
|
|
|
|
|
$text["language-$code"] = $value;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
foreach($language_name as $code => $value) {
|
|
|
|
|
foreach($language_name as $c_code => $value) {
|
|
|
|
|
$text["language-$code"][$c_code] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 07:36:00 +01:00
|
|
|
//return the array of translations
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|