All Projects → hyogman → react-translations-provider

hyogman / react-translations-provider

Licence: MIT license
React render props component for setting translations

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to react-translations-provider

React Composer
Compose render prop components
Stars: ✭ 610 (+1642.86%)
Mutual labels:  render, props
safemd
Safety first markdown rendering
Stars: ✭ 77 (+120%)
Mutual labels:  render
Fastai V3
Starter app for fastai v3 model deployment on Render
Stars: ✭ 206 (+488.57%)
Mutual labels:  render
yii2-render-many
Trait for Yii Framework 2
Stars: ✭ 14 (-60%)
Mutual labels:  render
Renderer
Simple, lightweight and faster response (JSON, JSONP, XML, YAML, HTML, File) rendering package for Go
Stars: ✭ 220 (+528.57%)
Mutual labels:  render
ginadmin
基于Gin开发的后台管理系统,集成了、数据库操作、日志管理、权限分配管理、多模板页面、自动分页器、数据库迁移和填充、Docker集成部署等功能、静态资源打包
Stars: ✭ 149 (+325.71%)
Mutual labels:  render
Cgru
CGRU - AFANASY
Stars: ✭ 197 (+462.86%)
Mutual labels:  render
vue-on-rails
Easy way to mount/destroy Vue.js components with Ruby on Rails and Turbolinks 5
Stars: ✭ 17 (-51.43%)
Mutual labels:  props
waline
💬 A Simple, Safe Comment System
Stars: ✭ 1,145 (+3171.43%)
Mutual labels:  render
blade
🏃 A library for using Laravel Blade templates in WordPlate.
Stars: ✭ 28 (-20%)
Mutual labels:  render
ZPL-Printer-Emulator-SDK
Convert, Preview & Render raw ZPL commands to PNG, JPG & PDF from .NET
Stars: ✭ 29 (-17.14%)
Mutual labels:  render
Keyboard Layout Editor For Blender
Allows you to import keyboard layouts into blender and render them in 3d
Stars: ✭ 224 (+540%)
Mutual labels:  render
react-semantic-render
Semantic helper components for rendering content with React.
Stars: ✭ 13 (-62.86%)
Mutual labels:  render
Picasso
Picasso is a high quality 2D vector graphic rendering library. It support path , matrix , gradient , pattern , image and truetype font.
Stars: ✭ 205 (+485.71%)
Mutual labels:  render
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-57.14%)
Mutual labels:  props
Komponents Deprecated
📦 React-inspired UIKit Components - ⚠️ Deprecated
Stars: ✭ 202 (+477.14%)
Mutual labels:  render
VF-BlenderAutoSaveRender
Automatically saves a numbered or dated image after every render and can extend the Blender output path with dynamic variables
Stars: ✭ 34 (-2.86%)
Mutual labels:  render
react-fundamentals
React fundamentals
Stars: ✭ 15 (-57.14%)
Mutual labels:  props
ReactEd
An extension to assist with development of react and redux applications.
Stars: ✭ 48 (+37.14%)
Mutual labels:  props
react-cheat-sheet
📚 The perfect React Cheat Sheet for daily use with a lot of Javascript / JSX snippets !
Stars: ✭ 59 (+68.57%)
Mutual labels:  props

React Translations Provider

download

A React render prop component for setting translations

yarn add react-translations-provider

Example

import React from "react";
import TranslationProvider, {
  Translate,
  Text,
} from "react-translations-provider";
import moment from "moment";

require("moment/locale/de");
require("moment/locale/es");

const en = {
  locale: "en",
  hello: "Hello World!",
  working: "Is this working?",
  weather: {
    weather: "Weather",
    sunny: "sunny",
    cloudy: "cloudy",
  },
};

const de = {
  locale: "de",
  hello: "Hallo Welt!",
  working: "Funktioniert das?",
  weather: {
    weather: "Wetter",
    sunny: "sonnig",
    cloudy: "bewölkt",
  },
};

const es = {
  locale: "es",
  hello: "¡Hola Mundo!",
  working: "¿Esto funciona?",
  weather: {
    weather: "Clima",
    sunny: "soleado",
    cloudy: "nublado",
  },
};

const translations = {
  en,
  de,
  es,
};

function App() {
  // At root level of app set the language with the TranslationProvider
  return (
    <TranslationProvider translations={translations} default="en">
      {({ setLanguage, language }) => (
        <div>
          <select value={language} onChange={e => setLanguage(e.target.value)}>
            <option value="en">English</option>
            <option value="de">German</option>
            <option value="es">Spanish</option>
          </select>
          <DisplayStuff />
          <SimpleWeather />
        </div>
      )}
    </TranslationProvider>
  );
}

function DisplayStuff() {
  // For the rest of app simply wrap with the Translate component to get translations
  return (
    <Translate>
      {({ translations }) => (
        <div>
          <h1>{translations.hello}</h1>
          <h2>{translations.working}</h2>
          <h3>
            {moment()
              .locale(translations.locale)
              .format("L")}
          </h3>
        </div>
      )}
    </Translate>
  );
}

function SimpleWeather() {
  // Or use the Text component api and pass the key path in translateKey prop to return
  // translation from translations object
  return (
    <div>
      <h1>
        <Text translateKey="weather.weather" />
      </h1>
      <h3>
        <Text translateKey="weather.sunny" />
      </h3>
    </div>
  );
}

export default App;

demo3

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].