Skip to content

Translate options in additional fields and text added with customizations

Additional-field titles, descriptions, placeholders, and option labels are passed through aMember's translation system when they are displayed. Text from custom PHP code must be passed to the ___() function before aMember can translate it:

echo ___('My custom text');

In each translation, the key must exactly match the original text, including capitalization and punctuation.

Create the site directory if it does not exist, then create a language file for your installation. For Russian, the file is:

/var/www/html/amember/application/default/language/user/site/ru.php

Replace ru with the language filename used by aMember, such as en, es, it, or zh. Add the original strings and their translations to the file:

<?php
return [
'one' => 'Один',
'two' => 'Два',
];

Files in the language/user/site directory are installation-specific and are not replaced during an aMember upgrade.

You can register the same translations from the site.php file. The custom language file is simpler, but this approach can be useful when the translations are already part of a PHP customization:

$translationsRu = [
'one' => 'Один',
'two' => 'Два',
];
$translate = Zend_Registry::get('Zend_Translate');
$previousLocale = $translate->getLocale();
$translate->addTranslation([
'content' => $translationsRu,
'locale' => Am_Locale::guessLocaleByLang('ru'),
]);
$translate->setLocale($previousLocale);

Replace ru with the required language code. Restoring the previous locale is important because addTranslation() switches the translator to the locale being added.