Modify Craft locale inside Element API plugin? I’m using the Element API plugin to retrieve my entries as JSON. It is available under the /api route. For getting entries in a different locale I pass a locale query param and use it inside the ElementQuery.

All works fine so far, BUT when I want to use Craft::t inside of a transformer, I get the translations from the main locale, because this is where my /api namespace lives.

Is it possible to modify the locale that Craft is set to, from inside the Element API plugin?
Craft::t() has a whole bunch of parameters you can pass into it.

public static function t($message, $variables = array(), $source = null, $language = null, $category = 'craft')


It sounds like what you're looking for is the 4th one.

Craft::t('my string', null, null, 'es')


Where 'es' would be a target locale other than your main one.