<p>You could <a href="http://php.net/manual/en/function.include.php" rel="nofollow"><code>include</code></a> the translations file into your controller:</p>

<pre><code>$translationsFile = craft()-&gt;path-&gt;getPluginsPath().'myplugin/translations/de.php';
$translationsArray = include $translationsFile;

$this-&gt;returnJson(array_keys($translationsArray));
</code></pre>

CC BY-SA 3.0
2016-01-19T16:21:11.797Z
2016-01-19T16:31:11.607Z
2016-01-19T16:31:11.607Z
carlcs
<p>I need to output a JSON object containing all of the key/value pairs in either <code>/translations/{myLocale}.php</code> or <code>/craft/plugins/myplugin/translations/{myLocale}.php</code>.</p>

<p>I can't see any way of doing that?</p>

<p>I can see that I can call <code>craft()-&gt;getComponent('messages')</code> but that will retrieve all of Craft's internal translations - I only want the messages I have defined in one of the files above.</p>

<plugin-development><localization>
How can I output ALL strings from a lang file?
# How can I output ALL strings from a lang file?

(Asked by: username_0 on 2016-01-19)

I need to output a JSON object containing all of the key/value pairs in either `/translations/{myLocale}.php` or `/craft/plugins/myplugin/translations/{myLocale}.php`.

I can't see any way of doing that?

I can see that I can call `craft()->getComponent('messages')` but that will retrieve all of Craft's internal translations - I only want the messages I have defined in one of the files above.

**Tags:** plugin-development, localization


---

## 1 answers

### Answer by username_1 on 2016-01-19. Score: 3 | Accepted answer

You could include the translations file into your controller:
$translationsFile = craft()->path->getPluginsPath().'myplugin/translations/de.php';
$translationsArray = include $translationsFile;

$this->returnJson(array_keys($translationsArray));


---

