Compare commits

..

1 Commits

3 changed files with 38 additions and 35 deletions

View File

@ -3,9 +3,9 @@ class ClassTranslation extends ClassConfig implements InterfaceTranslation {
public function __construct(){} public function __construct(){}
public function __destruct(){} public function __destruct(){}
public function getTranslationV2($message_code, $lang_code, $set_data, $db_table="core_translation"){ public function getTranslationV2($message_code, $lang_code, $set_data = array(), $db_table="core_translation"){
$this->_code = $code; $this->_code = $message_code;
$this->_lang = $lang; $this->_lang = $lang_code;
$this->_setData = $set_data; $this->_setData = $set_data;
$this->_dbTable = $db_table; $this->_dbTable = $db_table;
$oPDOLink = ClassConfig::databaseConnect(); $oPDOLink = ClassConfig::databaseConnect();
@ -104,22 +104,26 @@ class ClassTranslation extends ClassConfig implements InterfaceTranslation {
} }
public function getTranslation($code, $lang, $set_data = array()){ public function getTranslation($code, $lang = null, $set_data = array()){
$this->_code = $code; $this->_code = $code;
$this->_lang = $lang; $this->_lang = $lang ?? $_SESSION['config']['default_lang_code'];
$this->_setData = $set_data; $this->_setData = $set_data;
//if translation not in SESSION, then go get it from DB
if(!isset($_SESSION['translations'][$this->_code]) or $_SESSION['translations'][$this->_code]['source']==''){ if(!isset($_SESSION['translations'][$this->_code]) or $_SESSION['translations'][$this->_code]['source']==''){
$row = $this->getTranslationInDatabase($this->_code, $this->_lang); $row = $this->getTranslationInDatabase($this->_code, $this->_lang);
$_SESSION['translations'][$this->_code][$this->_lang] = $row[$this->_lang]; $_SESSION['translations'][$this->_code][$this->_lang] = $row[$this->_lang];
$_SESSION['translations'][$this->_code]['source'] = $row['source']; $_SESSION['translations'][$this->_code]['source'] = $row['source'];
} }
//if translation in current language, display it. Else, display source
if($_SESSION['translations'][$this->_code][$this->_lang] != ''){ if($_SESSION['translations'][$this->_code][$this->_lang] != ''){
$translation = $_SESSION['translations'][$this->_code][$this->_lang]; $translation = $_SESSION['translations'][$this->_code][$this->_lang];
} else { } else {
$translation = $_SESSION['translations'][$this->_code]['source']; $translation = $_SESSION['translations'][$this->_code]['source'];
} }
//if [data] in content, get values set in array $set_data
$replacement_regex = '/\[data\]/'; $replacement_regex = '/\[data\]/';
foreach($this->_setData as $k=>$v){ foreach($this->_setData as $k=>$v){
$translation = preg_replace($replacement_regex, $this->_setData[$k], $translation, 1); $translation = preg_replace($replacement_regex, $this->_setData[$k], $translation, 1);

View File

@ -8,6 +8,7 @@ require_once './modules/ClassConfig.php';
$oConf = new ClassConfig(); $oConf = new ClassConfig();
$file_path = substr_replace($_SERVER['REQUEST_URI'], '/', 0, strlen($oConf->getURLRoot())); $file_path = substr_replace($_SERVER['REQUEST_URI'], '/', 0, strlen($oConf->getURLRoot()));
$file_path = explode('?', $file_path)[0];
$custom_file = $oConf->getPathCustom($file_path); $custom_file = $oConf->getPathCustom($file_path);
$native_file = $oConf->getPathRoot($file_path); $native_file = $oConf->getPathRoot($file_path);

View File

@ -1,20 +1,19 @@
<?php <?php
session_start(); session_start();
require_once('../modules/InterfaceTranslation.php'); require_once('modules/InterfaceTranslation.php');
require_once('../modules/InterfacePostgreSQL.php'); require_once('modules/InterfacePostgreSQL.php');
require_once('../modules/InterfaceEmail.php'); require_once('modules/InterfaceEmail.php');
require_once('../modules/ClassConfig.php'); require_once('modules/ClassConfig.php');
require_once('../modules/ClassContent.php'); // require_once('modules/ClassContent.php');
require_once('../modules/ClassFeature.php'); require_once('modules/ClassFeature.php');
require_once('../modules/ClassFeatureTranslation.php'); require_once('modules/ClassFeatureTranslation.php');
require_once('../modules/ClassUser.php'); require_once('modules/ClassUser.php');
require_once('../modules/ClassTranslation.php'); require_once('modules/ClassTranslation.php');
$oFeat = new ClassFeature(); $oFeat = new ClassFeature();
$oFeatTrans = new ClassFeatureTranslation(); $oFeatTrans = new ClassFeatureTranslation();
$oUser = new ClassUser(); $oUser = new ClassUser();
$oContent = new ClassContent();
$oTrans = new ClassTranslation(); $oTrans = new ClassTranslation();
$oldLang = $_SESSION['config']['default_lang_code']; $oldLang = $_SESSION['config']['default_lang_code'];
@ -31,7 +30,6 @@ if(isset($_SESSION['user'])){
} }
$_SESSION['config']['default_lang_code'] = $newLang; $_SESSION['config']['default_lang_code'] = $newLang;
$_SESSION['content'] = $oContent->listContent($newLang);
$_SESSION['translations'] = $oTrans->listTranslations($newLang); $_SESSION['translations'] = $oTrans->listTranslations($newLang);
$newPage = $oFeatTrans->getURLTranslation($oldLang, $newLang, $oldPage); $newPage = $oFeatTrans->getURLTranslation($oldLang, $newLang, $oldPage);