Page 1 of 1

i18n module

Posted: Mon Mar 18, 2013 4:49 pm
by staleks
Hi,

I've started with implementing internationalization support for BLC using `broadleaf-I18n` module.

Documentation is a bit different and not in line with current 1.0.0-SNAPSHOT.

e.g. following link http://docs.broadleafcommerce.org/2.2/I18N-Quick-Start.html states that web.xml has to have

Code: Select all

<context-param>
    <param-name>patchConfigLocation</param-name>
    <param-value>
    .
    classpath:/bl-I18n-admin-applicationContext.xml
    classpath:/bl-I18n-applicationContext.xml
    .
    .
    </param-value>
</context-param>


I've done that but now when I started the application (first I want to implement this in site) I am getting following error:

Code: Select all

Caused by: java.io.IOException: Unable to open an input stream on specified application context resource: classpath:/bl-I18n-admin-applicationContext.xml


I've "unzipped" i18n file and found that this i18n module really do not contain such file.

Only files that I see there are:
    -bl-i18n-applicationContext.xml
    -bl-i18n-applicationContext-entity.xml
    -bl-i18n-base-applicationContext.xml

Any ideas how to proceed?

Re: i18n module

Posted: Mon Mar 18, 2013 4:57 pm
by staleks
I am not sure that I am going in right direction, but I've changed web.xml in a following way:

Code: Select all

            ...
            classpath:/bl-i18n-base-applicationContext.xml
            classpath:/bl-i18n-applicationContext.xml
            ...


so i18n instead of capital I and bl-i18n-base-applicationContext.xml instead of bl-i18n-admin-applicationContext.xml

Now I am facing some other issue,

Code: Select all

INFO: Initializing Spring root WebApplicationContext
[ WARN] 22:38:57 RuntimeEnvironmentPropertiesConfigurer org.broadleafcommerce.common.config.RuntimeEnvironmentPropertiesConfigurer - Unable to determine runtime environment, using default environment 'development'
[ERROR] 22:38:59 ContextLoader org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in resource loaded from byte array: Cannot resolve reference to bean 'blPersistenceUnitManager' while setting bean property 'persistenceUnitManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blPersistenceUnitManager' defined in resource loaded from byte array: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
   at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
   at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
   at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
   at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
   at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
   at java.util.concurrent.FutureTask.run(FutureTask.java:166)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blPersistenceUnitManager' defined in resource loaded from byte array: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
   ... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
   at org.springframework.context.weaving.LoadTimeWeaverAwareProcessor.postProcessBeforeInitialization(LoadTimeWeaverAwareProcessor.java:95)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
   ... 31 more
Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
   at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:93)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1472)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
   ... 40 more


Any ideas what I am doing wrong?

Re: i18n module

Posted: Tue Mar 19, 2013 2:47 am
by staleks
Hi again,

now when I look into demo of i18n, on GitHub
https://github.com/BroadleafCommerce/DemoSite-I18n/blob/develop/site/src/main/webapp/WEB-INF/web.xml

I do not see that following application context is ever loaded:

Code: Select all

classpath:/bl-i18n-base-applicationContext.xml


Anyway, even I discard loading that file, same error appears:

Code: Select all

Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
   at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:93)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1472)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
   ... 40 more

Re: i18n module

Posted: Tue Mar 19, 2013 5:13 am
by staleks
Hi,

investigating more on this issue I found one possible answer to my problems:

see following link http://stackoverflow.com/questions/3487588/how-to-use-jpa-in-spring-sample-petclinic

Specially this answer http://stackoverflow.com/a/3487860

It states that I should copy: springframework.instrument to Tomcat lib folder, and change the context.xml of Tomcat

is it way to go?

Re: i18n module

Posted: Tue Mar 19, 2013 10:25 am
by phillipuniverse
Yes definitely. We will make sure to include this in that module documentation, but you should include the path to Spring's instrument jar. See http://docs.broadleafcommerce.org/curre ... Setup.html for more info.

Re: i18n module

Posted: Wed Mar 20, 2013 8:13 am
by jefffischer
I have updated the documentation for this module and it should be publicly available shortly. The key points for you are:

1) In your admin web.xml and your site web.xml, you only need to add

Code: Select all

classpath:/bl-I18n-applicationContext.xml


2) The spring instrument jar does not need to be in the Tomcat lib directory. You only need to add an additional VM argument to Tomcat startup

Code: Select all

-javaagent:/path/to/your/spring-instrument-3.1.3.RELEASE.jar


The jar can be anywhere on the filesystem, as long as it's accessible by Tomcat. If you need to download the spring instrument jar, you can get it here: http://mvnrepository.com/artifact/org.s ... instrument.

Re: i18n module

Posted: Wed Mar 20, 2013 12:08 pm
by staleks
OK,

I've made it work. Finally :)

Now final question.

To make it simple for me to understand how it should work.

I have a client that will "push" BLC for Dutch market, so my guess is that their default BLC_LOCALE would be nl. Very soon after going live, my guess is that they will want to push for other EU countries, like Belgium so BLC_LOCALE be, etc.

So I have a BLC_CATEGORY. e.g. `Bier` and it's counter-part in BLC_CATEGORY_TR would be `Beer`.
Also I've provided keys matching in table BLC_CATEGORY_TRXREF.

Now, I've managed to have new, translated values whenever I do change default BLC_LOCALE and do rebuild Solr index (e.g. restart application).

I am wondering is this correct?

What about if we are going to have multiple front-end applications hitting same DB? Then even we deploy `site` to e.g.
mycompany.nl and mycompany.be, having same DB won't help.

Am I missing some part of the framework?

Re: i18n module

Posted: Wed Mar 20, 2013 3:25 pm
by staleks
Hi,

I've checked documentation after your corrections and IMHO you still have some issues:

    - Maven error: snapshot repository (since i18n is still 1.0.0-SNAPSHOT) should have a different <id> and <name> since we already has public repository listed in main pom.xml

    - Typo: broadleaf-I18n, I should not be capital letter. It should be small letter i

    - Maven: no need to state <type>jar</type> and <scope>compile</scope> since these two are defaults with these kind of values

    - Typo: I've started to extend i18n for admin and module i18n has changed there so it should be

    Code: Select all

    <inherits name="org.broadleafcommerce.i18n.admin.i18nModule" />


    instead of documented one:

    Code: Select all

    <inherits name="org.broadleafcommerce.admin.I18nModule" />


Re: i18n module

Posted: Wed Mar 20, 2013 7:53 pm
by jefffischer
Just did another update of the docs for i18n.

Re: i18n module

Posted: Thu Mar 21, 2013 10:38 am
by phillipuniverse
Check out the BroadleafLocaleResolver (the blLocaleResolver bean). You can decide to resolve the Locale via any means that you like based on the request. The default version of this first checks for a request attribute, then a request parameter, then whatever the default locale is configured in the database.

With this solution, there are multiple ways that you could solve your problem; set up a ServletFilter that goes before the BroadleafRequestFilter that puts the locale as a request attribute (you could check the end of request.getServerName() to see which domain the request is on), you could extend locale to have some sort of new site qualifier, etc.

However, if you are changing more than just locale based on the domain, then you are probably more interested in our Multi-Tenant module which is nearing completion. WIth multi-tenant, you can change everything on a per-site basis; different product catalogs, different customers, different templates, all segregated to a particular 'Site'.