FR [ 2042844 ] PO.get_Translation improvements
This commit is contained in:
parent
fc486133a5
commit
13e407caff
|
@ -204,7 +204,7 @@ public final class MCountry extends X_C_Country
|
||||||
{
|
{
|
||||||
if (m_trlName != null && s_AD_Language != null)
|
if (m_trlName != null && s_AD_Language != null)
|
||||||
{
|
{
|
||||||
m_trlName = get_Translation("Name", s_AD_Language);
|
m_trlName = get_Translation(COLUMNNAME_Name, s_AD_Language);
|
||||||
if (m_trlName == null)
|
if (m_trlName == null)
|
||||||
s_AD_Language = null; // assume that there is no translation
|
s_AD_Language = null; // assume that there is no translation
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,10 +219,7 @@ public class MDocType extends X_C_DocType
|
||||||
{
|
{
|
||||||
if (AD_Language == null || AD_Language.length() == 0)
|
if (AD_Language == null || AD_Language.length() == 0)
|
||||||
return super.getPrintName();
|
return super.getPrintName();
|
||||||
String retValue = get_Translation ("PrintName", AD_Language);
|
return get_Translation (COLUMNNAME_PrintName, AD_Language);
|
||||||
if (retValue != null)
|
|
||||||
return retValue;
|
|
||||||
return super.getPrintName();
|
|
||||||
} // getPrintName
|
} // getPrintName
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,6 +70,7 @@ import org.w3c.dom.Element;
|
||||||
* <li>BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
|
* <li>BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
|
||||||
* <li>FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods
|
* <li>FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods
|
||||||
* <li>BF [ 1990856 ] PO.set_Value* : truncate string more than needed
|
* <li>BF [ 1990856 ] PO.set_Value* : truncate string more than needed
|
||||||
|
* <li>FR [ 2042844 ] PO.get_Translation improvements
|
||||||
*/
|
*/
|
||||||
public abstract class PO
|
public abstract class PO
|
||||||
implements Serializable, Comparator, Evaluatee
|
implements Serializable, Comparator, Evaluatee
|
||||||
|
@ -1760,50 +1761,64 @@ public abstract class PO
|
||||||
} // setAD_User_ID
|
} // setAD_User_ID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Translation of column
|
* Get Translation of column (if needed).
|
||||||
|
* It checks if the base language is used or the column is not translated.
|
||||||
|
* If there is no translation then it fallback to original value.
|
||||||
* @param columnName
|
* @param columnName
|
||||||
* @param AD_Language
|
* @param AD_Language
|
||||||
* @return translation or null if not found
|
* @return translated string
|
||||||
|
* @throws IllegalArgumentException if columnName or AD_Language is null or model has multiple PK
|
||||||
*/
|
*/
|
||||||
protected String get_Translation (String columnName, String AD_Language)
|
public String get_Translation (String columnName, String AD_Language)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Check if columnName, AD_Language is valid or table support translation (has 1 PK) => error
|
||||||
if (columnName == null || AD_Language == null
|
if (columnName == null || AD_Language == null
|
||||||
|| m_IDs.length > 1 || m_IDs[0].equals(I_ZERO)
|
|| m_IDs.length > 1 || m_IDs[0].equals(I_ZERO)
|
||||||
|| !(m_IDs[0] instanceof Integer))
|
|| !(m_IDs[0] instanceof Integer))
|
||||||
{
|
{
|
||||||
log.severe ("Invalid Argument: ColumnName" + columnName
|
throw new IllegalArgumentException("ColumnName=" + columnName
|
||||||
+ ", AD_Language=" + AD_Language
|
+ ", AD_Language=" + AD_Language
|
||||||
+ ", ID.length=" + m_IDs.length + ", ID=" + m_IDs[0]);
|
+ ", ID.length=" + m_IDs.length
|
||||||
return null;
|
+ ", ID=" + m_IDs[0]);
|
||||||
}
|
}
|
||||||
int ID = ((Integer)m_IDs[0]).intValue();
|
|
||||||
String retValue = null;
|
String retValue = null;
|
||||||
|
//
|
||||||
|
// Check if NOT base language and column is translated => load trl from db
|
||||||
|
if (!Env.isBaseLanguage(AD_Language, get_TableName())
|
||||||
|
&& p_info.isColumnTranslated(p_info.getColumnIndex(columnName))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Load translation from database
|
||||||
|
int ID = ((Integer)m_IDs[0]).intValue();
|
||||||
StringBuffer sql = new StringBuffer ("SELECT ").append(columnName)
|
StringBuffer sql = new StringBuffer ("SELECT ").append(columnName)
|
||||||
.append(" FROM ").append(p_info.getTableName()).append("_Trl WHERE ")
|
.append(" FROM ").append(p_info.getTableName()).append("_Trl WHERE ")
|
||||||
.append(m_KeyColumns[0]).append("=?")
|
.append(m_KeyColumns[0]).append("=?")
|
||||||
.append(" AND AD_Language=?");
|
.append(" AND AD_Language=?");
|
||||||
PreparedStatement pstmt = null;
|
retValue = DB.getSQLValueString(get_TrxName(), sql.toString(), ID, AD_Language);
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
|
|
||||||
pstmt.setInt (1, ID);
|
|
||||||
pstmt.setString (2, AD_Language);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
if (rs.next ())
|
|
||||||
retValue = rs.getString(1);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
//
|
||||||
{
|
// If no translation found or not translated, fallback to original:
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
if (retValue == null) {
|
||||||
}
|
Object val = get_Value(columnName);
|
||||||
finally {
|
retValue = (val != null ? val.toString() : null);
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
return retValue;
|
return retValue;
|
||||||
} // get_Translation
|
} // get_Translation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Translation of column
|
||||||
|
* @param ctx context
|
||||||
|
* @param columnName
|
||||||
|
* @return translation
|
||||||
|
*/
|
||||||
|
public String get_Translation (String columnName)
|
||||||
|
{
|
||||||
|
return get_Translation(columnName, Env.getAD_Language(getCtx()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is new record
|
* Is new record
|
||||||
* @return true if new
|
* @return true if new
|
||||||
|
|
Loading…
Reference in New Issue