npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

liferay-react-runtime-localization

v1.0.2

Published

A library for localization Liferay React Portlets in Runtime

Downloads

21

Readme

Localizate Your React Portlet in Runtime

React Portlets is a facility in new versions of Liferay Portal, it support localization like any other type of portlets in Liferay But localizing is done only in build time meaning if you have a language key that generated dynamicly , you can't localizate it or for example if you get a key from api fetch and need to localizate it, you can't beacuse Liferay localization method for react ( Liferay.Language.get("yourLanguageKey") ) its undefined in runtime and you can't use it.

$ npm install liferay-react-runtime-localization

Or by Yarn

$ yarn add liferay-react-runtime-localization

Step 1 : Changing localization path

This library use your Language.properties files that by default placed in features/localization path of your React portlet, Since this portlet fetch Language.properties file as http request, it can not access to your features directory, So you should move it to asset directory. Move all of Language_*.properties files from:

your_react_portlet/features/localization/

To

your_react_portlet/asset/localization/

Then you must change config .npmbundlerrc to specify new Language.properties files location

{
	"create-jar": {
		"output-dir": "dist",
		"features": {
			"js-extender": true,
			"web-context": "/health-supervisor",
		      - "localization": "features/localization/Language", // **** must change to ⮟ ****
		      + "localization": "assets/localization/Language",   // ****   this line   ****
			"configuration": "features/configuration.json"
		}
	},
	"dump-report": true
}

Step 2 : Add LanguageProvider

This library store your language keys in react context, and for accessing to this context every where of your portlet you must wrap all of your portlet by this Language Provider.

import React from 'react';
import MainApp from './MainApp';
import { LanguageProvider } from "liferay-react-runtime-localization";

export default (props)=>{
     return (
            <LanguageProvider
                contextPath={props.contextPath}
                portalUrl={Liferay.ThemeDisplay.getPortalURL()}
                languageId={Liferay.ThemeDisplay.getLanguageId()}>
                    <MainApp {...props}/>
            </LanguageProvider>
    )
}

Step 3 : Usage

Now you easily localizate your language key by <Language/> tag or getLanguage method:

import React, {Fragment} from 'react';
import Language, {getLanguage} from "liferay-react-runtime-localization";

const MainApp = (props)=>{
     return (
            <Fragment>
              <Header title={getLanguage("pagetitles.product.list")}>
              <Container>
                  <h1><Language langKey="our_product_list"/></h1>
                  <ul>
                      {products.map((product, key)=>{
                          return ( 
                              <li key={key}>
                                  <Language langKey={product}/>
                              </li>
                          ) 
                      })}
                  </ul>
              </Container>
              <Footer/>
            </Fragment>
    )
}

export default MainApp;

This is a simple example for using.

Tip : You can only use it in all of child component that wrapped by LanguageProvider