Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
Make react-message-source public
  • Loading branch information
oliverlaz committed Feb 11, 2019
0 parents commit c4c6af5
Show file tree
Hide file tree
Showing 23 changed files with 21,032 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
"plugins": [
"@babel/plugin-proposal-class-properties"
],
"presets": [
["@babel/preset-react"],
[
"@babel/preset-env", {
"targets": {
"ie": "11"
}
}
]
]
};

3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

/dist
rollup.config.js
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"jest": true,
"browser": true
},
"extends": [
"airbnb",
"prettier"
],
"plugins": [
"prettier"
],
"parser": "babel-eslint",
"rules": {
"import/prefer-default-export": "off",
"prettier/prettier": "error",
"react/destructuring-assignment": "off",
"react/jsx-filename-extension": "off",
"react/jsx-one-expression-per-line": "off",
"react/jsx-wrap-multilines": "off",
"react/require-default-props": "off"
}
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

.idea
.vscode
node_modules

dist
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"parser": "flow",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"printWidth": 120,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# react-message-source

> A library which aids with I18n of React applications
[![NPM](https://img.shields.io/npm/v/react-message-source.svg)](https://www.npmjs.com/package/react-message-source) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save react-message-source
or
yarn add react-message-source
```

## Usage

```jsx
// in MyComponent.jsx
import React from 'react'
import { withMessages } from 'react-message-source'

function MyComponent(props) {
const { getMessage } = props;
return <span>{getMessage('hello.world')}</span>
}

export default withMessages(MyComponent)
```

```jsx
// in App.jsx
import React, { Component } from 'react'

import * as MessageSource from 'react-message-source'
import translations from './translations.json'

import MyComponent from './MyComponent'

class App extends Component {
render () {
return (
<MessageSource.Provider value={translations}>
<MyComponent />
</MessageSource.Provider>
)
}
}
```

## License

MIT © [](https://github.com/)
1 change: 1 addition & 0 deletions example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=9009
26 changes: 26 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "react-message-source-example",
"homepage": "https://.github.io/react-message-source",
"version": "0.0.0",
"license": "MIT",
"private": true,
"dependencies": {
"prop-types": "^15.7.1",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-message-source": "link:..",
"react-scripts": "2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
20 changes: 20 additions & 0 deletions example/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">

<link rel="manifest" href="%PUBLIC_URL%/manifest.json">

<title>react-message-source</title>
</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>

<div id="root"></div>
</body>
</html>
8 changes: 8 additions & 0 deletions example/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"short_name": "react-message-source",
"name": "react-message-source",
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
24 changes: 24 additions & 0 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import * as MessageSource from 'react-message-source';

import { LocalizedLabel, LocalizedLabelCurried, PrefixedLocalizedLabel } from './Greeting';

const translations = {
'hello.world': 'Hello world',
};

export default function App() {
return (
<React.Fragment>
<p>The content below is localized, see Greeting.js for more information.</p>

<MessageSource.Provider value={translations}>
<LocalizedLabel />

<LocalizedLabelCurried />

<PrefixedLocalizedLabel />
</MessageSource.Provider>
</React.Fragment>
);
}
24 changes: 24 additions & 0 deletions example/src/Greeting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withMessages } from 'react-message-source';

const propTypes = {
getMessage: PropTypes.func,
};

function LocalizedLabelComponent(props) {
const { getMessage } = props;
return <p>{getMessage('hello.world')}</p>;
}

function PrefixedLocalizedLabelComponent(props) {
const { getMessage } = props;
return <p>{getMessage('world')}</p>;
}

LocalizedLabelComponent.propTypes = propTypes;
PrefixedLocalizedLabelComponent.propTypes = propTypes;

export const LocalizedLabel = withMessages(LocalizedLabelComponent);
export const LocalizedLabelCurried = withMessages()(LocalizedLabelComponent);
export const PrefixedLocalizedLabel = withMessages('hello')(PrefixedLocalizedLabelComponent);
6 changes: 6 additions & 0 deletions example/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
Loading

0 comments on commit c4c6af5

Please sign in to comment.