|
|
|
Do you have any suggestions on how to solve this? Maybe we should provide a big if statement in the following file that switches locales and outputs different messages (and adds to the appropriate ApplicationResources.properties file).
ApplicationResources.ftl -------------------- # -- ${pojo.shortName}-START <#assign pojoNameLower = pojo.shortName.substring(0,1).toLowerCase()+pojo.shortName.substring(1)> <#foreach field in pojo.getAllPropertiesIterator()> <#if !c2h.isCollection(field) && !c2h.isManyToOne(field) && !c2j.isComponent(field)> <#lt/>${pojoNameLower}.${field.name}=${data.getFieldDescription(field.name)} </#if> </#foreach> ${pojoNameLower}.added=${pojo.shortName} has been added successfully. ${pojoNameLower}.updated=${pojo.shortName} has been updated successfully. ${pojoNameLower}.deleted=${pojo.shortName} has been deleted successfully. # -- ${pojoNameLower} list page -- ${pojoNameLower}List.title=${pojo.shortName} List ${pojoNameLower}List.heading=${util.getPluralForWord(pojo.shortName)} ${pojoNameLower}List.${pojoNameLower}=${pojoNameLower} ${pojoNameLower}List.${util.getPluralForWord(pojoNameLower)}=${util.getPluralForWord(pojoNameLower)} # -- ${pojoNameLower} detail page -- ${pojoNameLower}Detail.title=${pojo.shortName} Detail ${pojoNameLower}Detail.heading=${pojo.shortName} Information # -- ${pojo.shortName}-END |
|||||||||||||||||||||||||||||||||||||||||||||
The FreeMarker template (ApplicationResources.ftl) can be viewed at http://tinyurl.com/2x9r66. The getFieldDescription() method in DataHelper handles creating the field labels:
/**
* Parse a field name and convert it to a titled set of words.
* @param fieldName the pojo.property
* @return A string suitable for i18n
*/
public String getFieldDescription(String fieldName) {
StringBuffer buffer = new StringBuffer();
boolean nextUpper = false;
for (int i = 0; i < fieldName.length(); i++) {
char c = fieldName.charAt(i);
if (i == 0) {
buffer.append(Character.toUpperCase(c));
continue;
}
if (Character.isUpperCase(c)) {
buffer.append(' ');
buffer.append(c);
continue;
}
if (c == '.') {
buffer.delete(0, buffer.length());
nextUpper = true;
continue;
}
char x = nextUpper ? Character.toUpperCase(c) : c;
buffer.append(x);
nextUpper = false;
}
return buffer.toString();
}