Welcome Guest, Not a member yet? Register   Sign In
Language string from a database
#1

[eluser]abmcr[/eluser]
Actually, in the view i get my field text in the language as
Code:
echo $data["field_$lang"];
where $lang is a variable with the "eng", "ita" or....

This system work fine, but a problem uncoutered if the field contains the text.... but if the field is empty (this occurs if only the default language is translate) a null string is displayed; i want to do this function

Code:
function check_language($string,$data,$lang,$language_default="ita"){
//this function check if a string of the field in a language($lang) is not null; if is null get in the $data variable the string in the main language  and return it

return ($string==""?$data["$string_$language_default"]:$data["$string_$lang"]);
}

but this is most complex.... I want to simplify.... but i am confused... Any tip? Thank you! Ciao
#2

[eluser]Pygon[/eluser]
absolutely:

1) set the "default"(default value) for that column in the table of your database -- for example, set it to "eng" or whatever using your database utility.
2) make sure you are storing this "lang" in the session instead of going to the database every page (just in case you weren't doing this already). You can also double-check that it is !empty() during this step -- therefore no further logic. function would probably return the lang.




Theme © iAndrew 2016 - Forum software by © MyBB