Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

nuDisplayError translation

Questions related to using nuBuilder Forte.
Locked
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

nuDisplayError translation

Unread post by marc »

Hi all,

How to use nuTranslate to translate texts that are shown with nuDisplayError in PHP?
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: nuDisplayError translation

Unread post by toms »

Hi,

Write your own PHP nuTranslate() function that looks like this:

Code: Select all

function nuTranslate($s) {

	$t = $_SESSION['translation'];
	foreach($t as $k => $v) {
		if ($v['english'] === $s) {
			return $v['translation'];
		}
	}
	return $e;
}
Then you can use it like this:

(Function taken from https://wiki.nubuilder.cloud/ ... d_Policies and added nuTranslate() )

Code: Select all

function nuCheckPasswordPolicy() {
 
    $oldpw    = '#old_password#';
    $newpw    = '#new_password#';
     
    $passwordErr = "";
     
    if ($newpw === $oldpw) {
        $passwordErr .= nuTranslate("The provided New Password cannot be the same as the Current Password!")."<br>";
    }    
    if (strlen($newpw) < 8) {
        $passwordErr .= nuTranslate("Your Password must contain at least 8 Characters!")."<br>";
    }
    if (!preg_match("#[0-9]+#",$newpw)) {
        $passwordErr .= nuTranslate("Your Password must contain at least 1 Number!")."<br>";
    }
    if (!preg_match("#[A-Z]+#",$newpw)) {
        $passwordErr .= nuTranslate("Your Password must contain at least 1 Capital Letter!")."<br>";
    }
    if(!preg_match("#[a-z]+#",$newpw)) {
        $passwordErr .= nuTranslate("Your Password must contain at least 1 Lowercase Letter!")."<br>";
    }
    if(!preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $newpw)) {
        $passwordErr .= nuTranslate("Your Password must contain at least 1 Special Character!")."<br>";
    }    
 
    if (strlen($passwordErr) > 0) {
        nuDisplayError ($passwordErr) ;
        return false;
    } else
    {
        return true;
    }
}
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Re: nuDisplayError translation

Unread post by marc »

Perfect! Thank you so much toms.
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: nuDisplayError translation

Unread post by admin »

.
Locked