Skip to content

Instantly share code, notes, and snippets.

View shalkam's full-sized avatar
🏠
Working from home

Mostafa Sholkamy shalkam

🏠
Working from home
View GitHub Profile
import React, { Component } from 'react';
import { injectIntl, defineMessages } from "react-intl";
import logo from './logo.svg';
import './App.css';
const messages = defineMessages({
title: {
id: 'app.title',
defaultMessage: 'Welcome to React'
import React, { Component } from 'react';
import { IntlProvider, addLocaleData } from "react-intl";
import arLocaleData from "react-intl/locale-data/ar";
import esLocaleData from "react-intl/locale-data/es";
import translations from "./i18n/locales"
import App from "./App";
addLocaleData(arLocaleData);
addLocaleData(esLocaleData);
import ar from "./ar.json";
import en from "./en.json";
import es from "./es.json";
export default { ar, en, es };
[
{
"id": "app.title",
"defaultMessage": "Welcome to React",
"filepath": "src/App.js"
},
{
"id": "app.content1",
"defaultMessage": "To get started, edit",
"filepath": "src/App.js"
{
"name": "react-intl-example",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-intl": "^2.4.0",
"react-scripts": "1.1.1"
},
const path = require("path");
const manageTranslations = require("react-intl-translations-manager").default;
manageTranslations({
messagesDirectory: path.join(__dirname, "src/i18n/messages"),
translationsDirectory: path.join(__dirname, "src/i18n/locales/"),
languages: ["en", "ar", "es"] // any language you need
});
import React, { Component } from 'react';
import { injectIntl, defineMessages } from "react-intl";
import arLocaleData from "react-intl/locale-data/ar";
import esLocaleData from "react-intl/locale-data/es";
import logo from './logo.svg';
import './App.css';
const messages = defineMessages({
title: {
@shalkam
shalkam / AppWrapper.js
Last active March 19, 2018 12:47
Setting up React Intl for create-react-app
import React, { Component } from 'react';
import { IntlProvider, addLocaleData, injectIntl } from "react-intl";
import arLocaleData from "react-intl/locale-data/ar";
import esLocaleData from "react-intl/locale-data/es";
import App from "./App";
addLocaleData(arLocaleData);
addLocaleData(esLocaleData);
class AppWrapper extends Component {
@shalkam
shalkam / .eslintignore
Last active November 1, 2018 06:55
Eslint setup for React
node_modules/
build
@shalkam
shalkam / react-prop-types.js
Created August 8, 2017 18:24
React prop types for component props validation taken from react documentation
import PropTypes from 'prop-types';
MyComponent.propTypes = {
// You can declare that a prop is a specific JS primitive. By default, these
// are all optional.
optionalArray: PropTypes.array,
optionalBool: PropTypes.bool,
optionalFunc: PropTypes.func,
optionalNumber: PropTypes.number,
optionalObject: PropTypes.object,