This topic is locked
[SOLVED]

How to use multi language session message?

10/19/2021 10:17:16 AM
PHPRunner General questions
U
ustunsoz author

As explained in PhpRunner blog about Context Help Messages I like the idea and found very useful.

However my application is multilang and I need to add a column in database, let's say "message-en"

How can I customize below After App Initialized code to bring message according to session language.

$page = preg_replace('/(\/|\.php)/i', '', substr($_SERVER["PHP_SELF"],strripos($_SERVER["PHP_SELF"],"/")) );
$sym_pos = strripos($page,"_");
$selectData["pageName"] = $sym_pos?substr($page,0,$sym_pos):$page;
$selectData["pageType"] = $sym_pos?substr($page,$sym_pos+1):"";
if(isset($_GET["page"])){
$selectData["pageType"].=" ".$_GET["page"];
}
$selectData["project"] = 1;
$record = DB::Select("messages", $selectData )->fetchAssoc();
$_SESSION["messages"] = "";
if( $record ) $_SESSION["messages"] = $record["value"];

Thanks in advance for your replies

admin 10/19/2021

The last line of the code is the one that retrieves the message and stores it in the session variable:
if( $record ) $_SESSION["messages"] = $record["value"];

You can change it this way:

if( $record ) {
if ($_SESSION["language"] == "English") {
$_SESSION["messages"] = $record["message-en"];
} else if ($_SESSION["language"] == "Spanish") {
$_SESSION["messages"] = $record["message-es"];
}

}