IDEMPIERE-1025 Improve translation for custom tables
This commit is contained in:
parent
a14fd8642f
commit
83cfb7fdda
|
@ -39,6 +39,7 @@ import javax.xml.transform.stream.StreamResult;
|
|||
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.model.MLanguage;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
@ -46,6 +47,7 @@ import org.compiere.util.Env;
|
|||
import org.compiere.util.Language;
|
||||
import org.compiere.util.Login;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
@ -82,6 +84,8 @@ public class Translation
|
|||
public static final String XML_ROW_TAG = "row";
|
||||
/** XML Row Attribute ID */
|
||||
public static final String XML_ROW_ATTRIBUTE_ID = "id";
|
||||
/** XML Row Attribute UUID */
|
||||
public static final String XML_ROW_ATTRIBUTE_UUID = "uuid";
|
||||
/** XML Row Attribute Translated */
|
||||
public static final String XML_ROW_ATTRIBUTE_TRANSLATED = "trl";
|
||||
|
||||
|
@ -165,6 +169,7 @@ public class Translation
|
|||
if (isBaseLanguage)
|
||||
tableName = Base_Table;
|
||||
String keyColumn = Base_Table + "_ID";
|
||||
String uuidColumn = MTable.getUUIDColumnName(Base_Table);
|
||||
String[] trlColumns = getTrlColumns (Base_Table);
|
||||
//
|
||||
StringBuffer sql = null;
|
||||
|
@ -193,6 +198,7 @@ public class Translation
|
|||
else
|
||||
sql.append("t.IsTranslated,");
|
||||
sql.append("t.").append(keyColumn); // 2
|
||||
sql.append(", o.").append(uuidColumn); // 3
|
||||
//
|
||||
for (int i = 0; i < trlColumns.length; i++)
|
||||
sql.append(", t.").append(trlColumns[i])
|
||||
|
@ -224,7 +230,13 @@ public class Translation
|
|||
while (rs.next())
|
||||
{
|
||||
Element row = document.createElement (XML_ROW_TAG);
|
||||
row.setAttribute(XML_ROW_ATTRIBUTE_ID, String.valueOf(rs.getInt(2))); // KeyColumn
|
||||
int keyid = rs.getInt(2);
|
||||
String uuid = rs.getString(3);
|
||||
if (keyid <= MTable.MAX_OFFICIAL_ID || Util.isEmpty(uuid)) {
|
||||
row.setAttribute(XML_ROW_ATTRIBUTE_ID, String.valueOf(keyid)); // KeyColumn
|
||||
} else {
|
||||
row.setAttribute(XML_ROW_ATTRIBUTE_UUID, String.valueOf(uuid)); // UUIDColumn
|
||||
}
|
||||
row.setAttribute(XML_ROW_ATTRIBUTE_TRANSLATED, rs.getString(1)); // IsTranslated
|
||||
for (int i = 0; i < trlColumns.length; i++)
|
||||
{
|
||||
|
|
|
@ -55,6 +55,8 @@ public class TranslationHandler extends DefaultHandler
|
|||
private String m_updateSQL = null;
|
||||
/** Current ID */
|
||||
private String m_curID = null;
|
||||
/** Current UUID */
|
||||
private String m_curUUID = null;
|
||||
/** Translated Flag */
|
||||
private String m_trl = null;
|
||||
/** Current ColumnName */
|
||||
|
@ -97,6 +99,7 @@ public class TranslationHandler extends DefaultHandler
|
|||
else if (qName.equals(Translation.XML_ROW_TAG))
|
||||
{
|
||||
m_curID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_ID);
|
||||
m_curUUID = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_UUID);
|
||||
m_trl = attributes.getValue(Translation.XML_ROW_ATTRIBUTE_TRANSLATED);
|
||||
// log.finest( "ID=" + m_curID);
|
||||
m_sql = new StringBuffer();
|
||||
|
@ -154,8 +157,15 @@ public class TranslationHandler extends DefaultHandler
|
|||
m_sql.append(",IsTranslated='Y'");
|
||||
}
|
||||
// Where section
|
||||
m_sql.append(" WHERE ")
|
||||
.append(m_TableName).append("_ID=").append(m_curID);
|
||||
m_sql.append(" WHERE ");
|
||||
if (m_curUUID != null) {
|
||||
StringBuilder sql = new StringBuilder("SELECT ").append(m_TableName).append("_ID").append(" FROM ").append(m_TableName)
|
||||
.append(" WHERE ").append(m_TableName).append("_UU =?");
|
||||
int ID = DB.getSQLValueEx(null, sql.toString(), m_curUUID);
|
||||
m_sql.append(m_TableName).append("_ID=").append(ID);
|
||||
} else {
|
||||
m_sql.append(m_TableName).append("_ID=").append(m_curID);
|
||||
}
|
||||
if (!m_isBaseLanguage)
|
||||
m_sql.append(" AND AD_Language='").append(m_AD_Language).append("'");
|
||||
if (m_AD_Client_ID >= 0)
|
||||
|
|
Loading…
Reference in New Issue