当前位置: 首页>>代码示例>>Java>>正文


Java I18NUtil.getNearestLocale方法代码示例

本文整理汇总了Java中org.springframework.extensions.surf.util.I18NUtil.getNearestLocale方法的典型用法代码示例。如果您正苦于以下问题:Java I18NUtil.getNearestLocale方法的具体用法?Java I18NUtil.getNearestLocale怎么用?Java I18NUtil.getNearestLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.extensions.surf.util.I18NUtil的用法示例。


在下文中一共展示了I18NUtil.getNearestLocale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getParameterDefintion

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
 * @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getParameterDefintion(java.lang.String)
 */
public ParameterDefinition getParameterDefintion(String name)
{
    ParameterDefinition result = null;

    if (null != paramDefinitionsByName)
    {
        Set<Locale> locales = paramDefinitionsByName.keySet();
        Locale match = I18NUtil.getNearestLocale(I18NUtil.getLocale(), locales);
        Map<String, ParameterDefinition> localizedDefinitionsByName = paramDefinitionsByName.get(match);

        if (null == localizedDefinitionsByName)
        {
            localizedDefinitionsByName = paramDefinitionsByName.get(Locale.ROOT);
        }

        result = (null == localizedDefinitionsByName) ? (null) : (localizedDefinitionsByName.get(name));
    }

    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:ParameterizedItemDefinitionImpl.java

示例2: getTranslationForLocale

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/** {@inheritDoc} */
public NodeRef getTranslationForLocale(NodeRef translationNodeRef, Locale locale)
{
    // Get all the translations
    Map<Locale, NodeRef> nodeRefsByLocale = getTranslations(translationNodeRef);
    // Get the closest matching locale
    Set<Locale> locales = nodeRefsByLocale.keySet();
    Locale nearestLocale = I18NUtil.getNearestLocale(locale, locales);
    NodeRef nearestNodeRef = nodeRefsByLocale.get(nearestLocale);
    if (nearestNodeRef == null)
    {
        // There is no translation for the locale, so get the pivot translation
        nearestNodeRef = getPivotTranslation(translationNodeRef);
        if (nearestNodeRef == null)
        {
            // There is no pivot translation, so just use the given node
            nearestNodeRef = translationNodeRef;
        }
    }
    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug("Found nearest locale: \n" +
                "   Given node:   " + translationNodeRef + "\n" +
                "   Given locale: " + locale + "\n" +
                "   Found node:   " + nearestNodeRef + "\n" +
                "   Found locale: " + nearestLocale);
    }
    return nearestNodeRef;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:31,代码来源:MultilingualContentServiceImpl.java

示例3: getClosestValue

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
private Serializable getClosestValue(MLText mlText)
{
    Set<Locale> locales = mlText.getLocales();
    Locale contentLocale = I18NUtil.getContentLocale();
    Locale locale = I18NUtil.getNearestLocale(contentLocale, locales);
    if (locale != null)
    {
        return mlText.getValue(locale);
    }

    // If the content locale is too specific, try relaxing it to just language
    Locale contentLocaleLang = I18NUtil.getContentLocaleLang();
    // We do not expect contentLocaleLang to be null
    if (contentLocaleLang != null)
    {
        locale = I18NUtil.getNearestLocale(contentLocaleLang, locales);
        if (locale != null)
        {
            return mlText.getValue(locale);
        }
    }
    else
    {
        logger.warn("contentLocaleLang is null in getClosestValue. This is not expected.");
    }
    
    // Just return the default translation
    return mlText.getDefaultValue();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:MLPropertyInterceptor.java

示例4: getClosestLocale

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public Locale getClosestLocale(Collection<?> collection)
{
    if (collection.size() == 0)
    {
        return null;
    }
    // Use the available keys as options
    HashSet<Locale> locales = new HashSet<Locale>();
    for(Object o : collection)
    {
        MLText mlText = (MLText)o;
        locales.addAll(mlText.keySet());
    }
    // Try the content locale
    Locale locale = I18NUtil.getContentLocale();
    Locale match = I18NUtil.getNearestLocale(locale, locales);
    if (match == null)
    {
        // Try just the content locale language
        locale = I18NUtil.getContentLocaleLang();
        match = I18NUtil.getNearestLocale(locale, locales);
        if (match == null)
        {
            // No close matches for the locale - go for the default locale
            locale = I18NUtil.getLocale();
            match = I18NUtil.getNearestLocale(locale, locales);
            if (match == null)
            {
                // just get any locale
                match = I18NUtil.getNearestLocale(null, locales);
            }
        }
    }
    return match;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:MLPropertyInterceptor.java

示例5: getParameterDefinitions

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
 * @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getParameterDefinitions()
 */
public List<ParameterDefinition> getParameterDefinitions()
{
    Set<Locale> locales = parameterDefinitions.keySet();
    Locale match = I18NUtil.getNearestLocale(I18NUtil.getLocale(), locales);
    List<ParameterDefinition> result = parameterDefinitions.get(match);

    if (null == result)
    {
        result = parameterDefinitions.get(Locale.ROOT);
    }

    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:ParameterizedItemDefinitionImpl.java

示例6: getClosestValue

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
 * The given locale is used to search for a matching value according to:
 * <ul>
 *   <li>An exact locale match</li>
 *   <li>A match of locale ISO language codes</li>
 *   <li>The value for the locale provided in the {@link MLText#MLText(Locale, String) constructor}</li>
 *   <li>An arbitrary value</li>
 *   <li><tt>null</tt></li>
 * </ul>
 * 
 * @param locale the locale to use as the starting point of the value search
 * @return Returns a default <tt>String</tt> value or null if one isn't available.
 *      <tt>null</tt> will only be returned if there are no values associated with
 *      this instance.  With or without a match, the return value may be <tt>null</tt>,
 *      depending on the values associated with the locales.
 */
public String getClosestValue(Locale locale)
{
    if (this.size() == 0)
    {
        return null;
    }
    // Use the available keys as options
    Set<Locale> options = keySet();
    // Get a match
    Locale match = I18NUtil.getNearestLocale(locale, options);
    if (match == null)
    {
        // No close matches for the locale - go for the default locale
        locale = I18NUtil.getLocale();
        match = I18NUtil.getNearestLocale(locale, options);
        if (match == null)
        {
            // just get any locale
            match = I18NUtil.getNearestLocale(null, options);
        }
    }
    // Did we get a match
    if (match == null)
    {
        // We could find no locale matches
        return null;
    }
    else
    {
        return get(match);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:49,代码来源:MLText.java

示例7: getNearestLocale

import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public Locale getNearestLocale(Locale templateLocale, Set<Locale> options)
{
    return I18NUtil.getNearestLocale(templateLocale, options);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:5,代码来源:MessageServiceImpl.java


注:本文中的org.springframework.extensions.surf.util.I18NUtil.getNearestLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。