I use Craft to return some JSON data. The content however is available in different languages and I would like to get all those translations in a single API call.

I tried something like

'endpoints' => [
    'products.json' => [
        'elementType' => 'Entry',
        'criteria' => ['section' => 'products', 'order' => ['default' => 'lft asc']],
        'transformer' => function(EntryModel $entry) {
            $translate = [];
            foreach(array_keys($entry->getLocales()) as $locale) {
                //$entry->setLanguage($locale); Doesn't work with EntryModel
                $translate[$locale] = [
                    'title' => $entry->title,
                    'slug' => $entry->slug
                    // ...
            return $translate;

Unfortunately, there doesn't seem to be a method call setLanguage() like with fields. I'm out of ideas.

1 Answer 1


Here are some other similar questions and answers to this, but the short of it is that you could probably do it with something like using QueryBuilder to query the database directly (and bypassing Craft's APIs) or grabbing all site locales and looping through and re-querying for the entries on a per locale basis.

Both of them are pretty ugly and probably not that efficient in the context of the ElementAPI plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.