diff --git a/org.adempiere.base/src/org/compiere/util/Msg.java b/org.adempiere.base/src/org/compiere/util/Msg.java index 1b679408a1..68cacc7f9b 100644 --- a/org.adempiere.base/src/org/compiere/util/Msg.java +++ b/org.adempiere.base/src/org/compiere/util/Msg.java @@ -74,7 +74,10 @@ public final class Msg private Map> m_languages = new HashMap>(); - private Map> m_elementCache + private Map> m_elementNameCache + = new HashMap>(); + + private Map> m_elementPrintNameCache = new HashMap>(); /** @@ -113,12 +116,32 @@ public final class Msg if (AD_Language == null || AD_Language.length() == 0) AD_Language = Language.getBaseAD_Language(); // Do we have the language ? - CCache retValue = (CCache)m_elementCache.get(AD_Language); + CCache retValue = (CCache)m_elementNameCache.get(AD_Language); if (retValue != null) return retValue; retValue = new CCache(I_AD_Element.Table_Name, I_AD_Element.Table_Name + "|" + AD_Language, 100, 0, false, 0); - m_elementCache.put(AD_Language, retValue); + m_elementNameCache.put(AD_Language, retValue); + return retValue; + } + + /** + * Get language specific translation map for AD_Element + * @param ad_language + * @return ad_element map + */ + public synchronized CCache getElementPrintNameMap (String ad_language) + { + String AD_Language = ad_language; + if (AD_Language == null || AD_Language.length() == 0) + AD_Language = Language.getBaseAD_Language(); + // Do we have the language ? + CCache retValue = (CCache)m_elementPrintNameCache.get(AD_Language); + if (retValue != null) + return retValue; + + retValue = new CCache(I_AD_Element.Table_Name, I_AD_Element.Table_Name + "|" + AD_Language, 100, 0, false, 0); + m_elementPrintNameCache.put(AD_Language, retValue); return retValue; } @@ -504,8 +527,7 @@ public final class Msg } return sb.toString(); } // getAmtInWords - - + /************************************************************************** * Get Translation for Element * @param ad_language language @@ -514,6 +536,20 @@ public final class Msg * @return Name of the Column or "" if not found */ public static String getElement (String ad_language, String ColumnName, boolean isSOTrx) + { + return getElement(ad_language, ColumnName, isSOTrx, false); + } + + + /************************************************************************** + * Get Translation for Element + * @param ad_language language + * @param ColumnName column name + * @param isSOTrx if false PO terminology is used (if exists) + * @param isPrintName if true, will be used the PrintName instead of Name column + * @return Name/PrintName of the Column or "" if not found + */ + public static String getElement (String ad_language, String ColumnName, boolean isSOTrx, boolean isPrintName) { if (ColumnName == null || ColumnName.equals("")) return ""; @@ -522,7 +558,7 @@ public final class Msg AD_Language = Language.getBaseAD_Language(); Msg msg = get(); - CCache cache = msg.getElementMap(AD_Language); + CCache cache = isPrintName ? msg.getElementPrintNameMap(AD_Language) : msg.getElementMap(AD_Language); String key = ColumnName+"|"+isSOTrx; String retStr = cache.get(key); if (retStr != null) @@ -533,13 +569,20 @@ public final class Msg ResultSet rs = null; try { - if (AD_Language == null || AD_Language.length() == 0 || Env.isBaseLanguage(AD_Language, "AD_Element")) - pstmt = DB.prepareStatement("SELECT Name, PO_Name FROM AD_Element WHERE UPPER(ColumnName)=?", null); + if (AD_Language == null || AD_Language.length() == 0 || Env.isBaseLanguage(AD_Language, "AD_Element")) { + StringBuilder sql = new StringBuilder("SELECT") + .append(isPrintName ? " PrintName, PO_PrintName" : " Name, PO_Name") + .append(" FROM AD_Element WHERE UPPER(ColumnName)=?"); + pstmt = DB.prepareStatement(sql.toString(), null); + } else { - pstmt = DB.prepareStatement("SELECT t.Name, t.PO_Name FROM AD_Element_Trl t, AD_Element e " - + "WHERE t.AD_Element_ID=e.AD_Element_ID AND UPPER(e.ColumnName)=? " - + "AND t.AD_Language=?", null); + StringBuilder sql = new StringBuilder("SELECT") + .append(isPrintName ? " t.PrintName, t.PO_PrintName" : " t.Name, t.PO_Name") + .append(" FROM AD_Element_Trl t, AD_Element e") + .append(" WHERE t.AD_Element_ID=e.AD_Element_ID AND UPPER(e.ColumnName)=?") + .append(" AND t.AD_Language=?"); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setString(2, AD_Language); } @@ -596,7 +639,6 @@ public final class Msg return getElement (Env.getAD_Language(ctx), ColumnName, isSOTrx); } // getElement - /************************************************************************** * "Translate" text. *
{@code
@@ -610,6 +652,24 @@ public final class Msg
 	 *  @return translated text or original text if not found
 	 */
 	public static String translate(String ad_language, boolean isSOTrx, String text)
+	{
+		return translate(ad_language, isSOTrx, text, false);
+	}
+
+	/**************************************************************************
+	 *	"Translate" text.
+	 *  
{@code
+	 *		- Check AD_Message.AD_Message 	->	MsgText
+	 *		- Check AD_Element.ColumnName	->	Name/PrintName
+	 *  }
+ * If checking AD_Element, the SO terminology is used. + * @param ad_language Language + * @param isSOTrx sales order context + * @param text Text - MsgText or Element Name + * @param isPrintName if true, will be used the PrintName instead of Name column + * @return translated text or original text if not found + */ + public static String translate(String ad_language, boolean isSOTrx, String text, boolean isPrintName) { if (text == null || text.equals("")) return ""; @@ -623,7 +683,7 @@ public final class Msg return retStr; // Check AD_Element - retStr = getElement(AD_Language, text, isSOTrx); + retStr = getElement(AD_Language, text, isSOTrx, isPrintName); if (!retStr.equals("")) return retStr.trim(); diff --git a/org.adempiere.report.jasper/src/org/adempiere/report/jasper/MsgResourceBundle.java b/org.adempiere.report.jasper/src/org/adempiere/report/jasper/MsgResourceBundle.java index bc9b5dfb64..3540ff5773 100644 --- a/org.adempiere.report.jasper/src/org/adempiere/report/jasper/MsgResourceBundle.java +++ b/org.adempiere.report.jasper/src/org/adempiere/report/jasper/MsgResourceBundle.java @@ -72,7 +72,7 @@ public class MsgResourceBundle extends ResourceBundle { if (overridingResourceBundle != null && overridingResourceBundle.containsKey(key)) { return overridingResourceBundle.getObject(key); } - return Msg.translate(adLanguage, isSOTrx, key); + return Msg.translate(adLanguage, isSOTrx, key, true); } @Override @@ -85,7 +85,7 @@ public class MsgResourceBundle extends ResourceBundle { set = Msg.get().getMsgMap(adLanguage).keySet(); else set.addAll(Msg.get().getMsgMap(adLanguage).keySet()); - set.addAll(Msg.get().getElementMap(adLanguage).keySet()); + set.addAll(Msg.get().getElementPrintNameMap(adLanguage).keySet()); return Collections.enumeration(set); }