Forums Sign Up Reply Search Statistics
Fast Template GraFX Software Solutions - Forum / Fast Template /

multiple_assign( ) for lang files

 
Author rr1024
Forums Member
#1 Posted: 18 Dec 2007 01:28:57
Reply 
Hello again,

I didn't want to convert my lang file over from my $Lang["My_Lang"] ="Lang Selection";
to the template engine method of
multiple_assign("c_")

So I was looking at the fast template function and was thinking I could add a var $LANG_ARR_MULTI_ASS = FALSE; This would continue to use the current scheme of translation of "C_TEXT1" to $c_text1.

Then if $LANG_ARR_MULTI_ASS = TRUE then it could use $Lang passed to $pattern in your script i.e.
$ft->$this->LANG_ARR_MULTI_ASS= TRUE;

$ft->multiple_assign( $Lang );

With it being true it would use a foreach loop to assign all $Lang keys that end in _AA ( "_AA" for Auto Assign ).
There are langs elements that may not need to be assigned automatically for each page, so no need to do it I guess????

I'm not sure if foreach is the fastest way but it was the only way I could think of at this moment

I was thinking this or something like it maybe a good mod so those with Lang arrays could continue to use them as is. It is also easier to unset large lang arrays than it is large individual vars.

I was wondering what your thoughts were.

If you know a faster way other than foreach please let me know.

FUNCTION multiple_assign( $pattern )
{
IF ( !$this->LANG_ARR_MULTI_ASS ){
WHILE ( list( $key, $value ) = each( $GLOBALS ) ) {
IF ( substr($key,0,strlen($pattern))==$pattern) {
$this->assign(strtoupper($key),$value);
}
}

reset($GLOBALS);
}ELSE{
FOREACH( $pattern AS $Key => $Value) {
//echo "Key: $key; Value: $value<br />\n";
IF ( substr( $Key, -2) === '_AA' ){
$this->assign(strtoupper( $Key ), $Value );
}
}
}
} // multiple_assign
Author rr1024
Forums Member
#2 Posted: 18 Dec 2007 17:17:52
Reply 
I made some changes and it seem to work great

/**
* author GRAFX - www.grafxsoftware.com,since 1.1.3
* Pattern Assign
*
* Pattern Assign - when variables or constants are the same as the
* template keys, these functions may be used as they are. Using
* these functions, can help you reduce the number of
* the assign functions in the php files
*
* Useful for language files where all variables or constants have
* the same prefix.i.e. <i>$LANG_SOME_VAR</i> or <i>LANG_SOME_CONST</i><br>
* The $pattern is <i>LANG</i> in this case.
*
* MOD Dec 18, 2007 rr1024 at yahoo added foreach loop for auto assing r
* of Lang arrays it uses the last fou string elements per $LangKey so auto
* assign visitor pages key will end _AV admin auto assign will be _AA
* and Moderators will be _AM. Make sure you add VAR LANG_ARR_MULTI_ASS = FALSE; to fast template var list.
* Usage:
* $TE->LANG_ARR_MULTI_ASS = TRUE;
* $TE->multiple_assign( $Lang , '_AV' );
* Where $Lang['My_AutoAssign_AV']
*/
Note this also allows you in your script to have different groups of auto assign langs in one lang files. You may not want to have all the admin langs automatically assigned in a visitor page. waste of time

FUNCTION multiple_assign( $pattern, $LangKey )
{
IF ( !$this->LANG_ARR_MULTI_ASS ){
WHILE ( list( $key, $value ) = each( $GLOBALS ) ) {
IF ( substr($key,0,strlen($pattern))==$pattern) {
$this->assign(strtoupper($key),$value);
}
}

reset($GLOBALS);
}ELSE{
FOREACH( $pattern AS $Key => $Value) {
//echo "Key: $key; Value: $value<br />\n";
IF ( substr( $Key, -3 ) == $LangKey ){
$this->assign(strtoupper( $Key ), $Value );
}
//$sub .= "SubStr = " .substr( $Key, -3).'|||Key = '.$Key.'<br />';
}
//$this->error("<strong>[TE ERROR]</strong> langkey = $LangKey <br />$sub",0);
}
} // multiple_assign
 
Your Reply

» Username  » Password 
Only registered users are allowed to post here. Please enter your login/password details upon posting a message, or sign up first.