Java Code Examples for java.util.ResourceBundle.Control#getCandidateLocales()

The following examples show how to use java.util.ResourceBundle.Control#getCandidateLocales() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JRPropertiesUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: FileFolderServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}