留言板

Translate menu items

Morad Ahmad,修改在8 年前。

Translate menu items

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Dear Liferay Users and Experts,

I search for a way to add translation of menu items for my sites. Normaly in Portlets etc I use keys and add translations to Langauge_xx.properties.

For menu items however I must translate every menu item in the control panel what take a huge time and has many other disadvanteges (Normaly I plan to send a file to different persons to translate...).

I have in my portal many sites and site templates. I takes about 4 Hours to translate all sites in 1 Language!!!

I also tried to write a job to update translation using keys. But this doesn't work.

Does any body has experience with that? How do you translate menus for new languages added to a site???

Thank you very much,
Morad.
thumbnail
Phu Michael,修改在8 年前。

RE: Translate menu items

New Member 帖子: 10 加入日期: 11-5-10 最近的帖子
Hi Morad,
Do you try with Google Translate API ? (https://cloud.google.com/translate/docs)
You can write a simple program that call this api for auto transalting your file. Google translattion have been improved a alot recently emoticon
thumbnail
Olaf Kock,修改在8 年前。

RE: Translate menu items

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Morad Ahmad:
I search for a way to add translation of menu items for my sites. Normally in Portlets etc I use keys and add translations to Langauge_xx.properties.


I'm not sure what you mean by "menu items" - are those pieces of content? Page names? How many of them are there?

If it's something on the content side, and if this is a repeated and tedious task it might be worth to write either a script or a plugin that utilizes Liferay's API to provide an alternative interface to bulk-translate a lot of page names (or articles or whatever makes up a menu item).
thumbnail
Anil Sunkari,修改在8 年前。

RE: Translate menu items

Expert 帖子: 427 加入日期: 09-8-12 最近的帖子
There is one way which will be helpful but not sure if that is correct.

Write a generic update script for Layout table based on friendly url check where column name holds data in form of xml like below for each menu as shown below.


Eg for two locales:
<?xml version='1.0' encoding='UTF-8'?>
<root available-locales="en_US,ar_SA," default-locale="en_US">
<Name language-id="en_US">XXXXXX</Name>
<Name language-id="ar_SA">XXXXXXX</Name>
</root>
thumbnail
Andrew Jardine,修改在8 年前。

RE: Translate menu items

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
If you mean update the table directly, that is BAD advice. You should never update the tables directly for several reasons -- the least of which include that your cache will be out of sync. You'll also bypass any possible hooks that have been deployed that do anything with Layout changes (for example model listeners).

You should ALWAYS use the API to make changes. The simplest way to do this without creating a new plugin to do the work for you is to use the script tab in the Server Administration section of the Control Panel.
thumbnail
Anil Sunkari,修改在8 年前。

RE: Translate menu items

Expert 帖子: 427 加入日期: 09-8-12 最近的帖子
Yes, I agree with you( Andrew). Seems using scirpt tab to enforce the API would be best solution.
Morad Ahmad,修改在8 年前。

RE: Translate menu items

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Hi all,

yes i have many sites and templates (global, country site template, city site template, user public and private site templates... )...

I wrote a job which updates titles daily (only sample for one layout "portangosites". I read the translation map for the key I used i
portal init for creating the site. And use " _layout.setTitleMap(titleMap);" then update. But it doesn't update the title?
Maybe I should use setTitle(title, locale) for each new translated locale??? An exec a script once?

Thanks,
Morad.
----



package de.kanaaneh.portango.jobs;

import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.messaging.BaseMessageListener;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.util.LocalizationUtil;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Layout;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;

/**
* TODO: Funktioniert so nicht. Ich finde keinen Weg die Überschriften der
* Menüpunkte zu aktualisieren (ausser manuell)
*
* Setzt die neuen Übersetzungen für Layouts aus den Language_*.properties
*
* @author mahmad
*
*/
public class UpdateLayoutTitles extends BaseMessageListener {

private static Log _log = LogFactoryUtil.getLog(UpdateLayoutTitles.class);

@Override
protected void doReceive(Message message) throws Exception {
_log.info("start");
doUpdateLayoutTitles(message);
_log.info("end");
}

private void doUpdateLayoutTitles(Message message) {
updateGuestLayoutTitles();
}

private void updateGuestLayoutTitles() {
Group guestGroup = null;
try {
guestGroup = getGuestGroup();
} catch (PortalException | SystemException e) {
_log.error(e);
}
if (guestGroup != null) {
updateLayoutTitle(guestGroup.getGroupId(), "/portangosites", "menu.cities");
}
}

private void updateLayoutTitle(long groupId, String friendlyURL, String key) {
if (_log.isDebugEnabled()) {
_log.debug("updateLayoutTitle: friendlyURL= " + friendlyURL + ", key= " + key);
}
if (StringUtils.isBlank(friendlyURL) || StringUtils.isBlank(key)) {
_log.error("friendlyURL or key is empty. ");
return;
}
Layout _layout = null;
try {
_layout = LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, false, friendlyURL);
} catch (PortalException | SystemException e) {
_log.error(e);
}
System.out.println("layout= " + _layout);
if (_layout != null) {
Map<Locale, String> titleMap = getLocalizationMap(key);
if (_log.isDebugEnabled()) {
printMap(titleMap);
}
if (titleMap != null) {

_layout.setTitleMap(titleMap);
try {
LayoutLocalServiceUtil.updateLayout(_layout);
} catch (SystemException e) {
_log.error(e);
}
}
// localeTitle = getTitle(locale); // get current translation for locale
// _layout.setTitle(localeTitle, locale); // set only for this locale

}
}

private void printMap(Map<Locale, String> titleMap) {
for (Locale locale : titleMap.keySet()) {
System.out.println(locale.getDisplayLanguage() + "= " + titleMap.get(locale));
}
}

public Map<Locale, String> getLocalizationMap(String key) {
return LocalizationUtil.getLocalizationMap("portal-content.Language", this.getClass().getClassLoader(), key, false);
}

private Group getGuestGroup() throws PortalException, SystemException {
return GroupLocalServiceUtil.getGroup(PortalUtil.getDefaultCompanyId(), "Guest");
}

}
thumbnail
Andrew Jardine,修改在8 年前。

RE: Translate menu items

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Maybe I should use setTitle(title, locale) for each new translated locale??? An exec a script once?


You could try that -- if it is not too much effort. I have had occasions in the past where using one method seemed to work when others didn't. Alternatively, set a breakpoint in the LayoutLocalServiceImpl#update(Layout) method and step through there and see what is causing it not to save.