public NSArray branchChoicesForContext(D2WContext context) {
NSArray choices = (NSArray)context.valueForKey(BRANCH_CHOICES);
if (choices == null) {
choices = defaultBranchChoices(context);
} else {
NSMutableArray translatedChoices = new NSMutableArray();
for (Iterator iter = choices.iterator(); iter.hasNext();) {
Object o = iter.next();
String method = null;
String label = null;
NSMutableDictionary entry = new NSMutableDictionary();
if (o instanceof NSDictionary) {
entry.addEntriesFromDictionary((NSDictionary) o);
method = (String) entry.objectForKey(BRANCH_NAME);
label = (String) entry.objectForKey(BRANCH_LABEL);
} else if (o instanceof String) {
method = (String) o;
entry.setObjectForKey(method, BRANCH_NAME);
}
if (label == null) {
label = ERXLocalizer.currentLocalizer().localizedDisplayNameForKey(BRANCH_PREFIX, method);
} else if(label.startsWith(BRANCH_PREFIX + ".")){
String localizerKey = label;
String localized = ERXLocalizer.currentLocalizer().localizedStringForKey(label);
if(localized == null) {
label = ERXLocalizer.currentLocalizer().localizedDisplayNameForKey(BRANCH_PREFIX, method);
ERXLocalizer.currentLocalizer().takeValueForKey(label, localizerKey);
} else {
label = localized;
}
} else {
// assume it's a user-provided value. If we have an entry in the localizer, use it
// otherwise just return it.
label = ERXLocalizer.currentLocalizer().localizedStringForKeyWithDefault(label);
}
entry.setObjectForKey(label, BRANCH_LABEL);
entry.setObjectForKey(method + "Action", BRANCH_BUTTON_ID);
translatedChoices.addObject(entry);
}
choices = translatedChoices;
}
return choices;
}