Java Code Examples for org.springframework.extensions.surf.util.I18NUtil#getContentLocale()

The following examples show how to use org.springframework.extensions.surf.util.I18NUtil#getContentLocale() . 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: ExporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
    exporterService = (ExporterService)applicationContext.getBean("exporterComponent");
    importerService = (ImporterService)applicationContext.getBean("importerComponent");
    fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
    categoryService = (CategoryService) applicationContext.getBean("categoryService");     
    transactionService = (TransactionService) applicationContext.getBean("transactionService");
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");

    this.authenticationService = (MutableAuthenticationService) applicationContext.getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    contentLocaleToRestore = I18NUtil.getContentLocale();
    localeToRestore = I18NUtil.getLocale();
}
 
Example 2
Source File: MLPropertyInterceptor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: MLPropertyInterceptor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: FullNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before()
{
    super.before();
    contentLocaleToRestore = I18NUtil.getContentLocale();
    localeToRestore = I18NUtil.getLocale();
    Locale.setDefault(Locale.ENGLISH);
    MLPropertyInterceptor.setMLAware(false);
}
 
Example 5
Source File: MessageServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Locale getContentLocale()
{
    return I18NUtil.getContentLocale();
}
 
Example 6
Source File: ExporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testMLText() throws Exception
{
 NodeRef rootNode = nodeService.getRootNode(storeRef);
 NodeRef folderNodeRef = nodeService.createNode(
         rootNode,
         ContentModel.ASSOC_CHILDREN,
         ContentModel.ASSOC_CHILDREN,
         ContentModel.TYPE_FOLDER).getChildRef();
 
 FileInfo exportFolder = fileFolderService.create(folderNodeRef, "export", ContentModel.TYPE_FOLDER);
 FileInfo content = fileFolderService.create(exportFolder.getNodeRef(), "file", ContentModel.TYPE_CONTENT);
 MLText title = new MLText();
 title.addValue(Locale.ENGLISH, null);
 title.addValue(Locale.FRENCH, "bonjour");
 nodeService.setProperty(content.getNodeRef(), ContentModel.PROP_TITLE, title);
 nodeService.setProperty(content.getNodeRef(), ContentModel.PROP_NAME, "file");
 
 FileInfo importFolder = fileFolderService.create(folderNodeRef, "import", ContentModel.TYPE_FOLDER);
	
 // export
 File acpFile = exportContent(exportFolder.getNodeRef());
	
 // import
 FileInfo importFolderFileInfo = importContent(acpFile, importFolder.getNodeRef());
 assertNotNull(importFolderFileInfo);
 NodeRef importedFileNode = fileFolderService.searchSimple(importFolderFileInfo.getNodeRef(), "file");
 assertNotNull("Couldn't find imported file: file", importedFileNode);
 
	Locale currentLocale = I18NUtil.getContentLocale();
	try
	{
    	I18NUtil.setContentLocale(Locale.ENGLISH);

  String importedTitle = (String)nodeService.getProperty(importedFileNode, ContentModel.PROP_TITLE);
  assertNull(importedTitle);
     
    	I18NUtil.setContentLocale(Locale.FRENCH);

  importedTitle = (String)nodeService.getProperty(importedFileNode, ContentModel.PROP_TITLE);
  assertNotNull(importedTitle);
     assertEquals("bonjour", importedTitle);
	}
	finally
	{
    	I18NUtil.setContentLocale(currentLocale);
	}
}