public static EOFetchSpecification localizeFetchSpecification(EOEditingContext ec, EOFetchSpecification fetchSpecification) {
if(fetchSpecification != null && fetchSpecification.sortOrderings().count() > 0) {
fetchSpecification = (EOFetchSpecification) fetchSpecification.clone();
NSMutableArray sortOrderings = new NSMutableArray(fetchSpecification.sortOrderings().count());
for (Enumeration enumerator = fetchSpecification.sortOrderings().objectEnumerator(); enumerator.hasMoreElements();) {
EOSortOrdering item = (EOSortOrdering) enumerator.nextElement();
String key = item.key();
NSArray path = NSArray.componentsSeparatedByString(key, ".");
EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, fetchSpecification.entityName());
String attributeName = (String) path.lastObject();
String prefix = "";
if(path.count() > 1) {
for (int i = 0; i < path.count() - 1; i++) {
String part = (String) path.objectAtIndex(i);
EORelationship rel = entity.anyRelationshipNamed(part);
entity = rel.destinationEntity();
prefix += part + ".";
}
}
if(entity.attributeNamed(attributeName) == null) {
EOClassDescription cd = entity.classDescriptionForInstances();
if(cd instanceof ERXEntityClassDescription) {
String localizedKey = ((ERXEntityClassDescription)cd).localizedKey(attributeName);
if(localizedKey != null) {
item = new EOSortOrdering(prefix + localizedKey, item.selector());
}
}
}
sortOrderings.addObject(item);
}