Skip to content

Commit 349aae9

Browse files
author
joaogsleite
committed
example project with typescript
1 parent c559bc3 commit 349aae9

22 files changed

+331
-15546
lines changed

example/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# See https://help.github.com/ignore-files/ for more about ignoring files.
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
44
/node_modules
5+
/.pnp
6+
.pnp.js
57

68
# testing
79
/coverage

example/README.md

Lines changed: 11 additions & 2196 deletions
Large diffs are not rendered by default.

example/package-lock.json

Lines changed: 0 additions & 13271 deletions
This file was deleted.

example/package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
{
2-
"name": "example",
2+
"name": "react-multi-lang-example",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"react": "^16.1.1",
7-
"react-dom": "^16.1.1",
8-
"react-multi-lang": "file:..",
9-
"react-scripts": "^3.0.1"
6+
"@testing-library/jest-dom": "^4.2.4",
7+
"@testing-library/react": "^9.4.0",
8+
"@testing-library/user-event": "^7.2.1",
9+
"@types/jest": "^24.9.1",
10+
"@types/node": "^12.12.26",
11+
"@types/react": "^16.9.19",
12+
"@types/react-dom": "^16.9.5",
13+
"react": "^16.12.0",
14+
"react-dom": "^16.12.0",
15+
"react-scripts": "3.3.0",
16+
"typescript": "^3.7.5",
1017
},
1118
"scripts": {
1219
"start": "react-scripts start",
1320
"build": "react-scripts build",
14-
"test": "react-scripts test --env=jsdom",
21+
"test": "react-scripts test",
1522
"eject": "react-scripts eject"
1623
},
24+
"eslintConfig": {
25+
"extends": "react-app"
26+
},
1727
"browserslist": {
1828
"production": [
1929
">0.2%",
@@ -25,5 +35,5 @@
2535
"last 1 firefox version",
2636
"last 1 safari version"
2737
]
28-
}
38+
},
2939
}

example/public/index.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6-
<meta name="theme-color" content="#000000">
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
713
<!--
8-
manifest.json provides metadata used when your web app is added to the
9-
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1016
-->
11-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
1318
<!--
1419
Notice the use of %PUBLIC_URL% in the tags above.
1520
It will be replaced with the URL of the `public` folder during the build.
@@ -22,9 +27,7 @@
2227
<title>React App</title>
2328
</head>
2429
<body>
25-
<noscript>
26-
You need to enable JavaScript to run this app.
27-
</noscript>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
2831
<div id="root"></div>
2932
<!--
3033
This HTML file is a template.

example/public/logo192.png

5.22 KB
Loading

example/public/logo512.png

9.44 KB
Loading

example/public/manifest.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
"src": "favicon.ico",
77
"sizes": "64x64 32x32 24x24 16x16",
88
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
919
}
1020
],
11-
"start_url": "./index.html",
21+
"start_url": ".",
1222
"display": "standalone",
1323
"theme_color": "#000000",
1424
"background_color": "#ffffff"

example/public/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *

example/src/App.css

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,36 @@
33
}
44

55
.App-logo {
6-
animation: App-logo-spin infinite 20s linear;
7-
height: 80px;
6+
height: 40vmin;
7+
pointer-events: none;
88
}
99

10-
.App-header {
11-
background-color: #222;
12-
height: 150px;
13-
padding: 20px;
14-
color: white;
10+
@media (prefers-reduced-motion: no-preference) {
11+
.App-logo {
12+
animation: App-logo-spin infinite 20s linear;
13+
}
1514
}
1615

17-
.App-title {
18-
font-size: 1.5em;
16+
.App-header {
17+
background-color: #282c34;
18+
min-height: 100vh;
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
justify-content: center;
23+
font-size: calc(10px + 2vmin);
24+
color: white;
1925
}
2026

21-
.App-intro {
22-
font-size: large;
27+
.App-link {
28+
color: #61dafb;
2329
}
2430

2531
@keyframes App-logo-spin {
26-
from { transform: rotate(0deg); }
27-
to { transform: rotate(360deg); }
32+
from {
33+
transform: rotate(0deg);
34+
}
35+
to {
36+
transform: rotate(360deg);
37+
}
2838
}

example/src/App.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

example/src/App.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import App from './App';
4+
5+
test('renders learn react link', () => {
6+
const { getByText } = render(<App />);
7+
const linkElement = getByText(/learn react/i);
8+
expect(linkElement).toBeInTheDocument();
9+
});

example/src/App.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import logo from './logo.svg';
3+
import './App.css';
4+
import { useTranslation, setLanguage, getLanguage } from 'react-multi-lang'
5+
6+
const App: React.FC = () => {
7+
8+
const t = useTranslation()
9+
10+
return (
11+
<div className="App">
12+
<header className="App-header">
13+
<img src={logo} className="App-logo" alt="logo" />
14+
<h1 className="App-title">
15+
{t('home.Title', {param: 'react'})}
16+
</h1>
17+
</header>
18+
<p className="App-intro">
19+
To change language just press the buttons beneath
20+
</p>
21+
<div>Selected lang <b>{getLanguage()}</b></div>
22+
<br/>
23+
<button onClick={() => setLanguage('pt')}>PT</button>
24+
<button onClick={() => setLanguage('en')}>EN</button>
25+
</div>
26+
)
27+
}
28+
29+
export default App;

example/src/index.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
body {
22
margin: 0;
3-
padding: 0;
4-
font-family: sans-serif;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
code {
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
monospace;
513
}

example/src/index.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

example/src/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import './index.css';
4+
import App from './App';
5+
import * as serviceWorker from './serviceWorker';
6+
7+
8+
import { setDefaultTranslations, setDefaultLanguage } from 'react-multi-lang'
9+
import pt from './translations/pt.json'
10+
import en from './translations/en.json'
11+
12+
setDefaultTranslations({pt, en})
13+
setDefaultLanguage('pt')
14+
15+
16+
ReactDOM.render(<App />, document.getElementById('root'));
17+
18+
// If you want your app to work offline and load faster, you can change
19+
// unregister() to register() below. Note this comes with some pitfalls.
20+
// Learn more about service workers: https://bit.ly/CRA-PWA
21+
serviceWorker.unregister();

example/src/react-app-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

0 commit comments

Comments
 (0)