<@doc hierarchy="GMLDOM" also="@Text,@Scenario"> The Translation holds all Text entries and holds all information needed for Scenario elements translation. (c) SAP AG 2003-2006. All rights reserved. // Written By Mickey Hoter ////////////////////////////////////////////////////////////////////// // CLASS HEADER Class Translation inherit Resource; //The complete list of SAP translation types metadata translationTypes = { 'XBLI':true, // Bullet list item text 'XBUT':true, // Button text 'XCKL':true, // Label for checkbox 'XCOL':true, // Column heading 'XFLD':true, // Field label 'XGRP':true, // Group title 'XLG':true, // Log entry 'XLNK':true, // Hyperlink text 'XLST':true, // Enumerated list item 'XTIT':true, // Title 'XTND':true, // Tree node text 'XMEN':true, // Menu header 'XMIT':true, // Menu item 'XRBL':true, // Label for radio button 'XMSG':true, // Short message ( ? 50 characters) 'XTOL':true, // Short tooltip ( ? 50 characters) 'YMSG':true, // Long message ( > 50 characters) 'YINF':true, // Information (> 120 characters) 'YINS':true // Instruction (> 120 characters) }; metadata XTYPE_LIMIT = 255; metadata YTYPE_LIMIT = 16384; // The above list should in the future come from a back end system. /////////////////////////////////////////////////////////////////////// // PROPERTIES <@doc>The list of translation Text objects strong property items = ^core.gml:Text[id]; /////////////////////////////////////////////////////////////////////// // METHODS override method onCreate() //donothing end <@doc> Used for creating a new Text instance and an entry in the translation table Paramters expected:text, type, objOID Optional. Needed when inserting text for updates Optional. Needed when the type is to be replaced The newly genenrated key method insertText(values, key, type) var textItem = null; if(!key) { // Validate translation type: if(!this.Class.metadata.translationTypes[values.type]) { throw new Error(-1, '#TEXT[XMSG_ERROR_TRANS_TYPE]'); } // Force the 255/16384 chars limitation on X-type translations: if((values.type.charAt(0) == 'X') && (values.text.length > this.Class.metadata.XTYPE_LIMIT ) || (values.type.charAt(0) == 'Y') && (values.text.length > this.Class.metadata.YTYPE_LIMIT )) { throw new Error(-1, '#TEXT[XMSG_ERROR_TRANS_TYPE_EXCEED]'); } // No key - need to craete an entry in the table: textItem = this.createElement('Text', 'items', values); } else { // Key already found, replace the value: textItem = this.getTextItem(key); if(textItem) { if(type) { // Validate translation type: if(!this.Class.metadata.translationTypes[type]) { throw new Error(-1, '#TEXT[XMSG_ERROR_TRANS_TYPE]'); } textItem.setType(type); } else { type = textItem.type; } // Force the 255/16384 chars limitation on X-type translations: if((type.charAt(0) == 'X') && (values.length > this.Class.metadata.XTYPE_LIMIT ) || (type.charAt(0) == 'Y') && (values.length > this.Class.metadata.YTYPE_LIMIT )) { // Remove redundent translation: throw new Error(-1, '#TEXT[XMSG_ERROR_TRANS_TYPE_EXCEED]'); } textItem.setText(values); } } if(textItem) { return textItem.getUID(); } return null; end <@doc> Used for removing non relevant Text instance from the translation table The key is the ID of the Text object method removeText(key) if(key) { for(var i in this.items) { var item = this.items[i]; if(item.id == key) { this.removeElement(item, 'items'); } } } end <@doc> Used for retrieving a value (translated) for a key from the table. The key we need to find in the table Whether called from DE engine or not The translated text (and type in case of DE) method getTranslationVal(key, isDE) for(var i in this.items) { var item = this.items[i]; if(item.id == key) { if(isDE) { return [item.getText(), item.type]; } return item.getText(); } } // Not found: return null; end // Internal: getting the Text text from the table: method getTextItem(key) for(var i in this.items) { var item = this.items[i]; if(item.id == key) { return item; } } return null; end