An old portlet with a new face!
- Javascript framework used: React framework
- Tool to build our javascript application: Yarn
- UI library used: Material UI
- i18n support: react-i8next
- i18next
Yarn does not have to be installed locally on your system to build the application. Yarn and node will be downloaded and installed via the maven build process. This is all handled by the frontend maven plugin.
- maven 3+
- jdk 7+ (preferably 8)
mvn clean package
cd $UPORTAL_SOURCE
ant deployPortletApp -DportletApp=/path/to/portlet.war
The starting point of adding in i18n support in react is in this file i18n.js.
backend: {
loadPath: "/reactportlet/js/locales/{{lng}}/{{ns}}.json"
},
This tells the program where to load the i18n text from. If you had tomcat running on port 8080, you could see the 'en' language with the view namespace will be viewable on http://localhost:8080/reactportlet/js/locales/en/view.json. You can change the location of where the json is to serve up translations.
The react index.js file needs to be updated too. You have to wrap the main component with the component I18nextProvider
.
In all components that will have translations, you have to change how they are exported. It should look something like: export default translate("view", { wait: true })(App)
The translations live in the js folder based on locale. Since we only have one namespace, we just have a view.json file in each folder.
You do not need to build the react side of the project by its self. The maven process will build and copy the generated artifacts to the correct location for you. But if you wish to build the react project by hand, go to the src/main/react/ directory and do either a npm run build
or a yarn run build
.