elgg_echo in REST calls only returns default language
|Reported by:||mikehedman||Owned by:|
Strings returned from REST calls don't seem to be respecting the user's preferred language, and instead are returned in the default language.
At the beginning of the startup process for handling the REST call, Elgg cycles through the init functions, and in users_init's call to elgg_register_widget_type, it calls elgg_echo for the first time. At this stage, there's no session, no cookies, and no user (yet), so ultimately get_language() just picks the default language, which elgg_echo then sets the static $CURRENT_LANGUAGE to.
Subsequent calls then use the default language.
I think the root issue is that we shouldn't be setting static variables during the init process.
Just removing the call to elgg_echo from users_init won't be sufficient, as we have internal plugins which also call elgg_register_widget_type with elgg_echo, so I think the solution will have to be a little deeper. Maybe wrap elgg_echo's setting of $CURRENT_LANGUAGE to only set once the boot process is complete.