TranslationHelper 

\nn\t3::TranslationHelper() 

Translation management via Deep-L.

In order to use this function, a Deep-L API key must be stored in the nnhelpers extension manager. The key is free of charge and allows the translation of 500,000 characters per month.

// Activate translator
$translationHelper = \nn\t3::injectClass( \Nng\Nnhelpers\Helpers\TranslationHelper::class );

// Allow translation via Deep-L
$translationHelper->setEnableApi( true );
// Set target language
$translationHelper->setTargetLanguage( 'EN' );

// Allow max. Allow max. number of translations (for debugging purposes)
$translationHelper->setMaxTranslations( 2 );

// Path in which the l18n files should be saved / cached
$translationHelper->setL18nFolderpath( 'EXT:nnhelpers/Resources/Private/Language/' );

// Start translation
$text = $translationHelper->translate('my.example.key', 'This is the text to be translated');
Copied!

Overview of Methods 

\nn\t3::TranslationHelper()->createKeyHash($param = ''); 

Generates a unique hash from the key that is required to identify a text. Each text has the same key in all languages.

$translationHelper->createKeyHash( '12345' );
$translationHelper->createKeyHash( ['my', 'key', 'array'] );
Copied!

| @return string

| ➜ Go to source code of TranslationHelper::createKeyHash()

\nn\t3::TranslationHelper()->createTextHash($text = ''); 

Generates a unique hash / checksum from the text. The transferred text is always the base language. If the text in the base language changes, the method returns a different checksum. This recognizes when a text needs to be retranslated. Pure changes to whitespaces and tags are ignored.

$translationHelper->createKeyHash( '12345' );
$translationHelper->createKeyHash( ['my', 'key', 'array'] );
Copied!

| @return string

| ➜ Go to source code of TranslationHelper::createTextHash()

\nn\t3::TranslationHelper()->getEnableApi(); 

Returns whether the API is enabled.

$translationHelper->getEnableApi(); // default: false
Copied!

| @return boolean

| ➜ Go to source code of TranslationHelper::getEnableApi()

\nn\t3::TranslationHelper()->getL18nFolderpath(); 

Returns the current folder in which the translation files are cached. Default is typo3conf/l10n/nnhelpers/

$translationHelper->getL18nFolderpath();
Copied!

| @return string

| ➜ Go to source code of TranslationHelper::getL18nFolderpath()

\nn\t3::TranslationHelper()->getL18nPath(); 

Return the absolute path to the l18n cache file. Default is typo3conf/l10n/nnhelpers/[LANG].autotranslated.json

$translationHelper->getL18nPath();
Copied!

| @return string

| ➜ Go to source code of TranslationHelper::getL18nPath()

\nn\t3::TranslationHelper()->getMaxTranslations(); 

Gets the maximum number of translations to be made per instance.

$translationHelper->getMaxTranslations(); // default: 0 = infinite
Copied!

| @return integer

| ➜ Go to source code of TranslationHelper::getMaxTranslations()

\nn\t3::TranslationHelper()->getTargetLanguage(); 

Gets the target language for the translation

$translationHelper->getTargetLanguage(); // Default: EN
Copied!

| @return string

| ➜ Go to source code of TranslationHelper::getTargetLanguage()

\nn\t3::TranslationHelper()->loadL18nData(); 

Load complete language file.

$translationHelper->loadL18nData();
Copied!

| @return array

| ➜ Go to source code of TranslationHelper::loadL18nData()

\nn\t3::TranslationHelper()->saveL18nData($data = []); 

Save complete language file

$translationHelper->saveL18nData( $data );
Copied!

| @return boolean

| ➜ Go to source code of TranslationHelper::saveL18nData()

\nn\t3::TranslationHelper()->setEnableApi($enableApi); 

Activates / deactivates the translation via Deep-L.

$translationHelper->setEnableApi( true ); // default: false
Copied!
@param boolean $enableApi
@return self

| ➜ Go to source code of TranslationHelper::setEnableApi()

\nn\t3::TranslationHelper()->setL18nFolderpath($l18nFolderpath); 

Sets the current folder in which the translation files are cached. The idea is to translate the translated texts for backend modules only once and then save them in the extension folder. From there they are then deployed to GIT.

Default is typo3conf/l10n/nnhelpers/

$translationHelper->setL18nFolderpath('EXT:myext/Resources/Private/Language/');
Copied!
@param string $l18nFolderpathPath to the folder with the translation files (JSON)
@return self

| ➜ Go to source code of TranslationHelper::setL18nFolderpath()

\nn\t3::TranslationHelper()->setMaxTranslations($maxTranslations); 

Sets the maximum number of translations to be made per instance. Helps with debugging (so that the Deep-L quota is not exhausted by testing) and with TimeOuts if many texts need to be translated.

$translationHelper->setMaxTranslations( 5 ); // Abort after 5 translations
Copied!
@param $maxTranslations
@return self

| ➜ Go to source code of TranslationHelper::setMaxTranslations()

\nn\t3::TranslationHelper()->setTargetLanguage($targetLanguage); 

Sets the target language for the translation

$translationHelper->setTargetLanguage( 'FR' );
Copied!
@param string $targetLanguage Target language of the translation
@return self

| ➜ Go to source code of TranslationHelper::setTargetLanguage()

\nn\t3::TranslationHelper()->translate($key, $text = ''); 

Translate a text.

$translationHelper = \nn\t3::injectClass( \Nng\Nnhelpers\Helpers\TranslationHelper::class );
$translationHelper->setEnableApi( true );
$translationHelper->setTargetLanguage( 'EN' );
$text = $translationHelper->translate('my.example.key', 'This is the text to be translated');
Copied!

| @return string

| ➜ Go to source code of TranslationHelper::translate()

Methods