Using localization strings within PHP

Dear,

I would like to access translation keys from .php files. Is that possible? I know in templates (.tpl) I can use

translate key=“some.translation.key”

Any idea how to access those keys from the PHP code as well?

Regards, Primož

Hi @primozs,

In the PHP code, you can use…

$translation = __('some.translation.key');

You’ll need to make sure that the appropriate locale file has been loaded first. You can do that with e.g…

AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION);

There are examples of this in plugins/reports/articles/ArticleReportPlugin.inc.php.

Regards,
Alec Smecher
Public Knowledge Project Team