All Projects → zamarrowski → translate-components

zamarrowski / translate-components

Licence: MIT license
🌎🌍🌏 translate-components provides a super simple translation for React.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to translate-components

react-translator-component
React language translation module for developing a multilingual project.
Stars: ✭ 13 (-18.75%)
Mutual labels:  multilingual, translate, react-translate
sketch-crowdin
Connect your Sketch and Crowdin projects together
Stars: ✭ 35 (+118.75%)
Mutual labels:  multilingual, translate, multilanguage
LMPHP
Multi-language management and support on the site.
Stars: ✭ 19 (+18.75%)
Mutual labels:  translate, multilanguage
i18n-language.js
i18n-language.js is Simple i18n language with Vanilla Javascript
Stars: ✭ 21 (+31.25%)
Mutual labels:  multilingual, multilanguage
Translatr
💬 Translate to multiple languages at once
Stars: ✭ 145 (+806.25%)
Mutual labels:  multilingual, translate
grav-plugin-langswitcher
Grav LangSwitcher Plugin
Stars: ✭ 22 (+37.5%)
Mutual labels:  multilingual, multilanguage
Yii2 Translate Manager
Translation Manager
Stars: ✭ 221 (+1281.25%)
Mutual labels:  multilingual, translate
po-auto-translation
translate PO files automatically for FREE using google translate
Stars: ✭ 33 (+106.25%)
Mutual labels:  translate, multilanguage
JADA
JADA - Just Another Dictionary App
Stars: ✭ 20 (+25%)
Mutual labels:  multilanguage
pH7-Internationalization
🎌 pH7CMS Internationalization (I18N) package 🙊 Get new languages for your pH7CMS website!
Stars: ✭ 17 (+6.25%)
Mutual labels:  multilingual
translate english
Java程序员阅读源码必知英语单词
Stars: ✭ 24 (+50%)
Mutual labels:  translate
deepl-php-lib
🧠 DeepL API Client Library supporting PHP >= 7.3
Stars: ✭ 50 (+212.5%)
Mutual labels:  translate
WPGlobus
WPGlobus is a family of WordPress plugins assisting you in making bilingual / multilingual WordPress blogs and sites. This is a development repository. The stable version is on WordPress.org.
Stars: ✭ 40 (+150%)
Mutual labels:  multilanguage
DocumentTranslation
Command Line tool and Windows application for document translation, a local interface to the Azure Document Translation service for Windows, macOS and Linux.
Stars: ✭ 61 (+281.25%)
Mutual labels:  translate
geomm
Geometry-aware Multilingual Embeddings
Stars: ✭ 23 (+43.75%)
Mutual labels:  multilingual
TraduXio
A participative platform for cultural texts translators
Stars: ✭ 19 (+18.75%)
Mutual labels:  multilingual
translation-action
GitHub action that translates any text to any language supported by chosen provider.
Stars: ✭ 25 (+56.25%)
Mutual labels:  translate
the-subway-of-china
中国地铁图
Stars: ✭ 104 (+550%)
Mutual labels:  translate
mixed-language-training
Attention-Informed Mixed-Language Training for Zero-shot Cross-lingual Task-oriented Dialogue Systems (AAAI-2020)
Stars: ✭ 29 (+81.25%)
Mutual labels:  multilingual
next-multilingual
An opinionated end-to-end solution for Next.js applications that requires multiple languages.
Stars: ✭ 135 (+743.75%)
Mutual labels:  multilingual

translate-components 🌎🌍🌏

Build Status

translate-components provides a super simple translation for React. Write your application in your language and use translate-components to annotate which texts should be translated.

Demo

preview

Features

  • Write in your language.
  • Instant translations without having to refresh your browser.
  • Easy to use.
  • Support for create-react-app.

Install

npm install --save translate-components

How to use

//index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { TranslateProvider } from 'translate-components'
import './index.css';
import translations from './translations.json'

ReactDOM.render(
  <TranslateProvider translations={translations} defaultLanguage={'en'}>
    <App />
  </TranslateProvider>,
  document.getElementById('root')
);

Wrap your application with TranslateProvider, pass the translations and the default language of your application.

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Translate from 'translate-components'
import { reactTranslateChangeLanguage } from 'translate-components'

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2><Translate>Welcome to React</Translate></h2>
        </div>
        <p className="App-intro">
          <Translate>To get started, edit</Translate> <code>src/App.js</code> <Translate>and save to reload.</Translate>
        </p>
        <div>
          <button onClick={reactTranslateChangeLanguage.bind(this, 'en')}>
            English
          </button>
          <button onClick={reactTranslateChangeLanguage.bind(this, 'es')}>
            Spanish
          </button>
          <button onClick={reactTranslateChangeLanguage.bind(this, 'de')}>
            German
          </button>
        </div>
      </div>
    );
  }
}

export default App;

Use Translate component to wrap the text you want to translate. Use reactTranslateChangeLanguage to change the language of your application. Pass to reactTranslateChangeLanguage function, as first argument, the language. This translate instantly your application!

Of course, you need to have a translation JSON file to pass it to TranslateProvider like this:

{
  "Welcome to React": {
    "es": "Bienvenido a React",
    "de": "Willkommen in React"
  },
  "To get started, edit": {
    "es": "Para empezar, edita",
    "de": "Um loszulegen, bearbeiten"
  },
  "and save to reload.": {
    "es": "y guarda para refrescar la pagina",
    "de": "und speichern, um neu zu laden"
  }
}

By default the Translate component wraps the tranlated text into a <span> element. Additionally, you can use the prop useRawText from the Translate component to render the tranlated text with no wrapping. This will be useful to render the text in elements that don't support nested <span> as well as for other user cases like placeholders in <input> elements. E.g.

<select className="selectClass">
  <option value="phone"><Translate useRawText={true}>Phone</Translate></option>
  <option value="email"><Translate useRawText={true}>Email</Translate></option>
  <option value="textMessage"><Translate useRawText={true}>Text Message</Translate></option>
</select>

<input type="text" name="phone" className="form-control phone" placeholder={<Translate useRawText={true}>Número Telefónico</Translate>} />

The default language passed to TranslateProvider is the key of your translation objects.

Extracting strings

Once we have our app annotated with Translate component it's now time to extract these strings automatically. To extract these string we need to create a Javascript file that we will run with NodeJS. In this file we should import getTranslations:

let extractTranslations = require('./../translate-components/lib/getTranslations')
extractTranslations.extract('./src/*.js', './src/translations.json', ['es', 'de'])

extractTranslations.extract() needs three params:

  • Files RegExp
  • File translation output
  • Languages

If a translation file not exist, translate-components will create a file but if it already exist will add the new translations. Execute node pathToYourFile.js and that will generate a translations file!

Debug mode (Highlight texts)

Enable debug mode to higlight untranslated texts.

<TranslateProvider debugMode={true} translations={translations} defaultLanguage={'en'}>

When translate-components does not found a translate for a certain text this text will be higlighted with a background yellow. Demo:

highlight

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].