掲示板

Translate menu items

8年前 に Morad Ahmad によって更新されました。

Translate menu items

Junior Member 投稿: 71 参加年月日: 10/06/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
8年前 に Phu Michael によって更新されました。

RE: Translate menu items

New Member 投稿: 10 参加年月日: 11/05/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
8年前 に Olaf Kock によって更新されました。

RE: Translate menu items

Liferay Legend 投稿: 6403 参加年月日: 08/09/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
8年前 に Anil Sunkari によって更新されました。

RE: Translate menu items

Expert 投稿: 427 参加年月日: 09/08/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
8年前 に Andrew Jardine によって更新されました。

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
8年前 に Anil Sunkari によって更新されました。

RE: Translate menu items

Expert 投稿: 427 参加年月日: 09/08/12 最新の投稿
Yes, I agree with you( Andrew). Seems using scirpt tab to enforce the API would be best solution.
8年前 に Morad Ahmad によって更新されました。

RE: Translate menu items

Junior Member 投稿: 71 参加年月日: 10/06/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
8年前 に Andrew Jardine によって更新されました。

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.