php-i18n
php-i18n copied to clipboard
Switch Language
Is there a solution, how I can switch language during script execution?
I have the case where I send Emails/Notifications to the users by a cron script, depending on the defined user Language every User should got the Email/Notification in the correct language.
No, that's not possible. However, I'm open to accepting pull requests that add this feature while keeping API stability.
I have implemented this functionality, but I did not found a way to keep the API in full, concretely I lost calls like L::HELLO which must be called by one of: L::{lang}_HELLO, L::HELLO(), L('HELLO') ...
and instead to have one cached file per Language I generate one file for all languages where I set {lang} as prefix to the constants. I'm not sure if this is a problem as the file got cached in Memory anyway.
If you have some idea how I could do it better please let me know and I will go this way and make a pull request.
The language compiler could compile each language class with a separate class name (which includes the language code) and then the main L
class could use magic methods to delegate into the currently selected language class... but I fear that this will break api compat.
Yep it's not possible, without either (a) changing the api or (b) using runkit.