MyBB Community Forums

Full Version: Switching language programatically multiple time not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If you want in a script to use first italian, after that english and after that italian again(always loading the same section) will not work.

The problem is in inc/class_language.php, line 147 require_once $lfile;
It should be only require, not require_once.

Real use case:
- admin approval registration
- default language Italian
- admin language English

Register using Italian language, the script will send and email to the admin(switch language once), after that will prepare a message for the user(switch language second time). Because of the require_once, the second switch will have no effect because that file was already required when the script started(member.php)
I don't understand why you need to switch languages 3 times in the same script. Why wouldn't you just load the Italian lang files, copy whatever Italian strings you need for step 1 and 3 in your example to a local variable, and then once that's done just switch to English?

require_once() shouldn't be a problem here. There's no reason to load the language files more than once, because once they're loaded they are just added to the $lang object's list of keys and stay there. Therefore requiring them only one time should not be an issue, unless I'm misunderstanding what you're saying.

The example you're giving here just doesn't make sense to me tbh. The board can automatically email admins using the board's default language on new user register; that's a core feature that you don't need to make a script for and therefore wouldn't need to be manually switching languages.
I think he mean he as admin using english, a new user register on his forum and he activate them in acp, then the new user who get activated recive the mail he get activated in english instead of italien, what he choosed on registration process.

thats how i understand his problem, but i have not checked it, so i can not comfirm if its a exist bug or not.
(2017-07-07, 03:18 PM)broatcast Wrote: [ -> ]I think he mean he as admin using english, a new user register on his forum and he activate them in acp, then the new user who get activated recive the mail he get activated in english instead of italien, what he choosed on registration process.

thats how i understand his problem, but i have not checked it, so i can not comfirm if its a exist bug or not.

I see what you mean. But is that a bug with MyBB or just the way it's intended to work? If the board is sending automated messages I would assume that it should send them in the board's default language, not the specific language that a certain user is using. Feel free to correct me on this though, I haven't looked into it enough to see for myself.