Field Name Localization
Platform resolves field name localizations for data report views and allows you to customise the resolving algorithm.
Platform resolves localized field names for the displayKey property with values provided either in configuration (local.properties / project.properties) files or in language bundle files located in the resources/localization directory. Platform checks whether the displayKey definitions are provided in the configuration files first. If it cannot find them there, it checks whether they are available in the language bundle files.
The resolving algorithm uses the AuditReportItemNameResolvable and AuditReportItemNameResolver interfaces.
AuditReportItemNameResolvable is implemented by all audit report XML elements and handles passing necessary information about element definitions to AuditReportItemNameResolver.
AuditReportItemNameResolvable
public interface AuditReportItemNameResolvable
{
String getDisplayKey();
String getDisplayName();
String getDefaultName();
}
The AuditReportItemNameResolver interface has one method - getName. It takes as arguments a set of language ISO codes you choose for report generation, and a report XML element definition.
AuditReportItemNameResolver
/**
* Interface which provides methods to resolve name for audit report items for the given configuration and particular instance of
* Item.
*/
public interface AuditReportItemNameResolver
{
/**
* Resolves AuditReportItemNameResolvable item's name
*
* @param langIsoCodes languages defined in audit configuration
* @param item Item which name will be resolved based on provided details and the report configuration
* @return String representing name for the item
* @see AuditReportItemNameResolvable
*/
String getName(final Set<String> langIsoCodes, final AuditReportItemNameResolvable item);
}
Example
Configuration
This example report configuration is created for an auditReportLocalization extension:
auditReportLocalization-testLocalization-audit.xml
<audit-report-config name="testLocalization">
<given-root-type>User</given-root-type>
<types>
<type code="User" displayKey="type.user.name">
<atomic-attributes>
<atomic-attribute qualifier="name" displayName="Name comes first" displayKey="my.localized.user.name"/>
<atomic-attribute qualifier="uid" displayKey="my.localized.user.uid"/>
</atomic-attributes>
<relation-attributes>
<relation-attribute relation="PrincipalGroupRelation" type="UserGroup" many="true">
<resolves-by resolverBeanId="manyToManyReferencesResolver"/>
</relation-attribute>
</relation-attributes>
</type>
<type displayKey="my.localized.principal-group-relation" code="UserGroup">
<atomic-attributes>
<atomic-attribute qualifier="locName" displayKey="type.principalgroup.locname.name"/>
<atomic-attribute qualifier="description" />
<atomic-attribute qualifier="name" />
<atomic-attribute qualifier="uid" />
</atomic-attributes>
</type>
</types>
</audit-report-config>
The key value for the user ID (uid) field is provided in project.properties of the auditReportLocalization extension as my.localized.user.uid=Uid from Config.
These are example key values for the localized fields for the German language provided in resources/localization (appropriate localized values for English and Spanish are also provided and you can see some of them in the output below as DE group name, ES group name):
my.localized.principal-group-relation=DE group name my.localized.user.name=DE name my.localized.user.uid=DE uid
Platform resolves field names as follows:
-
a field name is resolved based on a provided displayName attribute; in the example, it is Name comes first; in the example, both displayName and displayKey are defined (for atomic-attribute qualifier=name for User) but displayName takes precedence before displayKey
-
when a displayKey is defined, Platform first checks config properties (local.properties / project.properties) for appropriate key values; if no values are provided there, Platform searches for them in language bundle files
-
if neither of the above is defined, field names are resolved based on their default names:
-
a type name is resolved to the type code; for example, a field name for the User type is User
-
a virtual attribute name is resolved to the virtual attribute expression value; for example, for a <virtual-attribute expression="owner"> expression, it is owner
-
an atomic attribute name is resolved to the atomic attribute qualifier value; for example, for <atomic-attribute qualifier="description" />, it is description
-
a reference attribute name is also resolved to the qualifier value
-
for a relation attribute, the default name is resolved based on the definition of the referenced type; for example, if a relation attribute is referenced by type="Address", then the default name is resolved by the definition of the Address type, with the same order for resolving names applying for the type (that is: displayName, or displayKey (with values provided in the config properties), then, if neither is defined, the name is resolved as the type code, which is Address
-