-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make react-message-source public
- Loading branch information
0 parents
commit c4c6af5
Showing
23 changed files
with
21,032 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
] | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
/dist | ||
rollup.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
.idea | ||
.vscode | ||
node_modules | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
[](https://www.npmjs.com/package/react-message-source) [](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/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT=9009 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
Oops, something went wrong.