下面列出了java.util.ResourceBundle.Control#getCandidateLocales ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public String getLocalizedProperty(String property, Locale locale)
{
Control control = Control.getControl(Control.FORMAT_PROPERTIES);
String value = null;
// we're not looking at the fallback locale to be consistent with JRResourcesUtil.loadResourceBundle
List<Locale> locales = control.getCandidateLocales(property, locale);
for (Locale candidate : locales)
{
String candidateString = candidate.toString();
String candidateProperty = candidateString.isEmpty() ? property : (property + "_" + candidateString);
String candidateValue = getProperty(candidateProperty);
if (candidateValue != null)// test for empty?
{
value = candidateValue;
break;
}
}
return value;
}
@Override
public NodeRef getLocalizedSibling(NodeRef nodeRef)
{
Locale userLocale = I18NUtil.getLocale();
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
// Work out the base name we are working with
Pair<String, String> split = getExtension(name, false);
String base = split.getFirst();
String ext = split.getSecond();
NodeRef resultNodeRef = nodeRef;
// Search for siblings with the same name
Control resourceHelper = Control.getControl(Control.FORMAT_DEFAULT);
List<Locale> candidateLocales = resourceHelper.getCandidateLocales(base, userLocale);
for (Locale candidateLocale : candidateLocales)
{
String filename = resourceHelper.toBundleName(base, candidateLocale) + "." + ext;
// Attempt to find the file
NodeRef foundNodeRef = searchSimple(parentNodeRef, filename);
if (foundNodeRef != null) // TODO: Check for read permissions
{
resultNodeRef = foundNodeRef;
break;
}
}
// Done
return resultNodeRef;
}