Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make $translation_adapter public so it can be used by custom modules to add their own translations #80

Closed
wants to merge 2 commits into from

Conversation

JustCarmen
Copy link
Contributor

Since Zend_Registry::get('Zend_Translate') is deprecated, a work around is to use parent::__construct() in the module constructor.

But if you make the WT_I18N variabele $translation_adapter public then this adapter can be used by custom modules to add their own translations and isn't it necessary to keep the deprecated function alive.

A custom translation then can be implemented in the module constructor in this way:

WT_I18N::$translation_adapter->addTranslation(
        new Zend_Translate('gettext', WT_MODULES_DIR.$this->getName().'/language/'.WT_LOCALE.'.mo', WT_LOCALE)
);

@JustCarmen
Copy link
Contributor Author

I just found out that the code is working in front without parent:: _ construct, but not in the backend. So to use this code in a custom module the module constructor must start wit parent:: _ construct(). After that the translation files can be called with WT_I18N::$translation_adapter->addTranslation();

@fisharebest
Copy link
Owner

Do you think it is right to remove Zend_Registry::set() ?

It is removed in ZF2, but are there other custom modules that use it? IIRC, there are some ZF1 functions that use it.

I have another suggestion. Add this to WT_I18N

public static function addTranslation(Zend_Translate $translation) {
    WT_I18N::$translation_adapter->addTranslation($translation);
}

We initialise WT_I18N before we initialise the modules, so any module should be able to call this at any time. e.g.

public function __construct() {
    parent::__construct();
    WT_I18N::addTranslation(
        new Zend_Translate('gettext', '/path/to/module/language/'.WT_LOCALE.'.mo', WT_LOCALE)
    );
}

@fisharebest
Copy link
Owner

I've just tested this in a module, and it seems to work fine for me, so I have commited the change.

Let me know if it works for you.

@JustCarmen
Copy link
Contributor Author

Yes this works just fine. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants