react-translate-component alternatives and similar libraries
Based on the "Utilities" category.
Alternatively, view react-translate-component alternatives based on common mentions on social networks and blogs.
-
react-intl
The monorepo home to all of the FormatJS related libraries, most notably react-intl. -
react-i18next
Internationalization for react done right. Using the i18next i18n ecosystem. -
react-on-rails
Integration of React + Webpack + Rails + rails/webpacker including server-side rendering of React, enabling a better developer experience and faster client performance. -
reactfire
Hooks, Context Providers, and Components that make it easy to interact with Firebase. -
js-lingui
🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript -
qrcode.react
A <QRCode/> component for use with React. -
react-firebase-hooks
React Hooks for Firebase. -
react-three-renderer
Render into a three.js canvas using React. -
react-unity-webgl
React Unity WebGL provides a modern solution for embedding Unity WebGL builds in your React Application while providing advanced APIs for two way communication and interaction between Unity and React. -
react-faux-dom
DOM like structure that renders to React. -
react-intl-universal
Internationalize React apps. Not only for Component but also for Vanilla JS. -
react-d3-library
Open source library for using D3 in React -
react-stripe-checkout
Load stripe's checkout.js as a react component. Easiest way to use checkout with React. -
backbone-react-component
A bit of nifty glue that automatically plugs your Backbone models and collections into your React components, on the browser and server -
react-elm-components
Write React components in Elm -
react-recaptcha
A react.js reCAPTCHA for Google -
reactive-elements
Allows to use React.js component as HTML element (web component) -
react-fetching-library
Simple and powerful API client for react 👍 Use hooks or FACCs to fetch data in easy way. No dependencies! Just react under the hood. -
redux-segment
Segment.io analytics integration for redux. -
react-google-autocomplete
React components for google places API. -
react-lottie-player
Fully declarative React Lottie player -
<qr-code>
A no-framework, no-dependencies, customizable, animate-able, SVG-based <qr-code> HTML element. -
gl-react
OpenGL / WebGL bindings for React to implement complex effects over images and content, in the descriptive VDOM paradigm. -
react-localstorage
Simple componentized localstorage implementation for Facebook's React. -
react-children-utilities
Extended utils for ⚛️ React.Children data structure that adds recursive filter, map and more methods to iterate nested children. -
react-google-analytics
Google analytics component -
gl-react-dom
WebGL bindings for React to implement complex effects over images and content, in the descriptive VDOM paradigm -
react-globalize
Bringing the i18n functionality of Globalize, backed by CLDR, to React -
react-backbone
backbone-aware mixins for react and a whole lot more -
react-threejs
WIP: Simplest bindings between React & Three.js -
elm-react-component
A React component which wraps an Elm module to be used in a React application. -
react-middle-ellipsis
Truncate a long string in the middle, instead of the end. -
react-screen-wake-lock
🌓 React implementation of the Screen Wake Lock API. It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running -
react-translate-maker
Universal internationalization (i18n) open source library for React -
Redux Slim Async
:alien: A Redux middleware to ease the pain of tracking the status of an async action -
react-slack-notification
React Slack Notification is a lightweight package, Send messages to a Slack channel directly from your react app. -
react-localized
Internationalization for React and Preact components based on gettext format -
thehashlink
Working with hash URL quick and in easy way
AWS Cloud-aware infrastructure-from-code toolbox [NEW]
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of react-translate-component or a related project?
README
React Translate Component
Translate is a component for React that utilizes the Counterpart module and the Interpolate component to provide multi-lingual/localized text content. It allows switching locales without a page reload.
Installation
Install via npm:
% npm install react-translate-component
Usage
Here is a quick-start tutorial to get you up and running with Translate. It's a step-by-step guide on how to build a simple app that uses the Translate component from scratch. We assume you have recent versions of Node.js and npm installed.
First, let's create a new project:
$ mkdir translate-example
$ cd translate-example
$ touch client.js
$ npm init # accept all defaults here
Next, add the dependencies our little project requires:
$ npm install react counterpart react-interpolate-component react-translate-component --save
The react
, counterpart
and react-interpolate-component
packages are peer dependencies of react-translate-component
and need to be installed along-side of it.
We will put our application logic into client.js
. Open the file in your favorite editor and add the following lines:
'use strict';
var counterpart = require('counterpart');
var React = require('react');
var ReactDOM = require('react-dom');
var Translate = require('react-translate-component');
This loads the localization library, React and our Translate component.
Let's write our entry-point React component. Add the following code to the file:
class MyApp extends React.Component {
render() {
return (
<html>
<head>
<meta charSet="utf-8" />
<title>React Translate Quick-Start</title>
<script src="/bundle.js" />
</head>
<body>
--> body content will be added soon <--
</body>
</html>
);
}
}
if (typeof window !== 'undefined') {
window.onload = function() {
ReactDOM.render(<MyApp />, document);
};
}
module.exports = MyApp;
Now we have the basic HTML chrome for our tiny little app.
Next, we will create a LocaleSwitcher component which will be used to, well, switch locales. Here is the code to append to client.js
:
class LocaleSwitcher extends React.Component {
handleChange(e) {
counterpart.setLocale(e.target.value);
}
render() {
return (
<p>
<span>Switch Locale:</span>
<select defaultValue={counterpart.getLocale()} onChange={this.handleChange}>
<option>en</option>
<option>de</option>
</select>
</p>
);
}
}
For demonstration purposes, we don't bother and hard-code the available locales.
Whenever the user selects a different locale from the drop-down, we correspondingly set the new drop-down's value as locale in the Counterpart library, which in turn triggers an event that our (soon to be integrated) Translate component listens to. As initially active value for the select element we specify Counterpart's current locale ("en" by default).
Now add LocaleSwitcher as child of the empty body element of our MyApp component:
<body>
<LocaleSwitcher />
</body>
Next, we create a Greeter component that is going to display a localized message which will greet you:
class Greeter extends React.Component {
render() {
return <Translate {...this.props} content="example.greeting" />;
}
}
In the component's render function, we simply transfer all incoming props to Translate (the component this repo is all about). As content
property we specify the string "example.greeting" which acts as the key into the translations dictionary of Counterpart.
Now add the new Greeter component to the body element, provide a with
prop holding the interpolations (your first name in this case) and a component
prop which is set to "h1":
<body>
<LocaleSwitcher />
<Greeter with={{ name: "Martin" }} component="h1" />
</body>
The value of the name
key will be interpolated into the translation result. The component
prop tells Translate which HTML tag to render as container element (a <span>
by default).
All that's left to do is to add the actual translations. You do so by calling the registerTranslations
function of Counterpart. Add this to client.js
:
counterpart.registerTranslations('en', {
example: {
greeting: 'Hello %(name)s! How are you today?'
}
});
counterpart.registerTranslations('de', {
example: {
greeting: 'Hallo, %(name)s! Wie geht\'s dir heute so?'
}
});
In the translations above we defined placeholders (in sprintf's named arguments syntax) which will be interpolated with the value of the name
key we gave to the Greeter component via the with
prop.
That's it for the application logic. To eventually see this working in a browser, we need to create the server-side code that will be executed by Node.js.
First, let's install some required dependencies and create a server.js
file:
$ npm install express connect-browserify reactify node-jsx --save
$ touch server.js
Now open up server.js
and add the following lines:
'use strict';
var express = require('express');
var browserify = require('connect-browserify');
var reactify = require('reactify');
var React = require('react');
require('node-jsx').install();
var App = React.createFactory(require('./client'));
express()
.use('/bundle.js', browserify.serve({
entry: __dirname + '/client',
debug: true, watch: true,
transforms: [reactify]
}))
.get('/', function(req, res, next) {
res.send(React.renderToString(App()));
})
.listen(3000, function() {
console.log('Point your browser to http://localhost:3000');
});
Note that you shouldn't use this code in production as the bundle.js
file will be compiled on every request.
Last but not least, start the application:
$ node server.js
It should tell you to point your browser to http://localhost:3000. There you will find the page greeting you. Observe that when switching locales the greeting message adjusts its text to the new locale without ever reloading the page or doing any ajax magic.
Please take a look at this repo's spec.js
file to see some more nice tricks like translating HTML element attributes (title, placeholder etc.). To become a master craftsman we encourage you to also read Counterpart's README.
Asynchronous Rendering on the Server-side
The above example for server.js
will not work when you're calling ReactDOMServer.renderToString(...)
within the callback of an async function and calling counterpart.setLocale(...)
synchronously outside of that callback. This is because the Counterpart module is used as a singleton instance inside of the Translate component. See PR [#6] for details.
To fix this, create a wrapper component (or extend your root component) and pass an instance of Counterpart as React context. Here's an example:
var http = require('http');
var Translator = require('counterpart').Instance;
var React = require('react');
var ReactDOMServer = require('react-dom/server');
var Translate = require('react-translate-component');
var MyApp = require('./my/components/App');
var en = require('./my/locales/en');
var de = require('./my/locales/de');
class Wrapper extends React.Component {
getChildContext() {
return {
translator: this.props.translator
};
}
render() {
return <MyApp data={this.props.data} />;
}
}
Wrapper.childContextTypes = {
translator: Translate.translatorType
};
http.createServer(function(req, res) {
var queryData = url.parse(req.url, true).query;
var translator = new Translator();
translator.registerTranslations('en', en);
translator.registerTranslations('de', de);
translator.setLocale(req.locale || 'en');
doAsyncStuffHere(function(err, data) {
if (err) { return err; }
var html = ReactDOMServer.renderToString(
<Wrapper data={data} translator={translator} />
);
res.write(html);
});
}).listen(3000);
An Advanced Example
The code for a more sophisticated example can be found in the repo's example
directory. You can clone this repository and run make install example
and point your web browser to http://localhost:3000
. In case you are too lazy for that, we also have a live demo of the example app.
Contributing
Here's a quick guide:
Fork the repo and
make install
.Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate:
make test
.Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or are fixing a bug, we need a test!
Make the test pass.
Push to your fork and submit a pull request.
Licence
Released under The MIT License.
*Note that all licence references and agreements mentioned in the react-translate-component README section above
are relevant to that project's source code only.