Jump to content

How to translate admin dropdown menu's from a module?


Marc
 Share

Recommended Posts

I am developing a module called 'callcenter', which adds custom menu items to the admin panel. In ProcessCallcenter.info.php a have my navigation setup as follows:

	'nav' => array(
		array(
			'url' => 'enterorder/',
			'label' => __('Enter order'),
			'icon' => 'glass',
			'permission' => 'call-prepare',
		),array(
			'url' => 'enteruser/',
			'label' => __('Enter user'),
			'icon' => 'glass',
			'permission' => 'call-prepare',
		),
		array(
			'url' => 'entercall/',
			'label' => __('Enter call'),
			'icon' => 'glass',
			'permission' => 'call-prepare',
		),
		array(
			'url' => 'calloverview/',
			'label' => __('Call overview'),
			'icon' => 'glass',
		),
	)

The labels should be translated, but it does not work. I went to 'languages' in the admin, added ProcessCallcenter.info.php to my language, which found the four label strings, but after translating only the original English labels are displayed in the custom dropdown menu. Other files of my module are translated correctly using this method. Am I doing something wrong? I tried refreshing the modules a few times but it does not help.

I attached a screenshot to show what I mean. I have my profile language set to Dutch, so the admin is Dutch except for my module menu (called 'callcenter') which is in English for a reason I don't understand.

post-2762-0-66467200-1446626844_thumb.jp

Link to comment
Share on other sites

I'm assuming this is a Process module, since that's the only one that supports nav arrays. The arrays provided in your getModuleInfo (like the 'nav' array) are not called at runtime, instead they are stored in the DB. As a result, there's no reason to make those labels translatable–actually you should avoid it, otherwise the wrong language translation might end up stored in the DB. Instead, just make them regular strings like 'Enter Order' rather than __('Enter Order'). Then, somewhere else in your module, make them translatable. It can even be in a PHP comment. For instance, you could add this at the top of your module file:

/*
 * __('Enter Order');
 * __('Enter User'); 
 * and so on...
 *
 */

These should be in your 'default' language. Make sure the phrases are identical to those in your 'nav' array. Doing this just ensures that the language parser knows they are translatable phrases. After making that change, do a Modules > Refresh, then go back and translate the file (Setup > Languages > language > your file), and save.

Now it should work. If using AdminThemeReno, it won't work, unless you upgrade to the latest dev version. I just fixed that issue in AdminThemeReno yesterday actually. Since it looks like you are using Reno, you'll want to grab the latest dev branch. 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...