Skip to content

Commit

Permalink
chore(exampe): add typescript sample
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Apr 5, 2020
1 parent 3703974 commit 5bc13b9
Show file tree
Hide file tree
Showing 11 changed files with 1,348 additions and 3 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
}
}
],
"@babel/preset-flow",
"@babel/preset-react"
]
}
3 changes: 1 addition & 2 deletions example/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "basic",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"i18n": "NODE_ENV=development extract-messages -l=en,ja -o i18n -d en 'src/**/*.{js,tsx}'"
"i18n": "NODE_ENV=development extract-messages -l=en,ja -o i18n -d en 'src/**/*.{js,jsx}'"
},
"dependencies": {
"react": "^16.13.1",
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions example/with-typescript/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (api) {
api.cache(true)

return {
presets: ['@babel/preset-react', '@babel/preset-typescript']
}
}
10 changes: 10 additions & 0 deletions example/with-typescript/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"App": {
"hello": "Hello Button",
"submit": "Submit Button"
},
"a": {
"hello": "hello",
"world": "world"
}
}
10 changes: 10 additions & 0 deletions example/with-typescript/i18n/ja.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"App": {
"hello": "",
"submit": ""
},
"a": {
"hello": "",
"world": ""
}
}
19 changes: 19 additions & 0 deletions example/with-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "with-typescript",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"i18n": "extract-messages -l=en,ja -o i18n -d en 'src/**/*.{ts,tsx}'"
},
"dependencies": {
"react": "^16.13.1",
"react-intl": "^4.3.1"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"extract-react-intl-messages": "latest",
"typescript": "^3.8.3"
}
}
19 changes: 19 additions & 0 deletions example/with-typescript/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { injectIntl, useIntl } from 'react-intl'

export const SubmitButton = injectIntl(({ intl }) => {
const label = intl.formatMessage({
id: 'App.submit',
defaultMessage: 'Submit Button'
})
return <button aria-label={label}>{label}</button>
})

export const HelloButton = () => {
const intl = useIntl()
const label = intl.formatMessage({
id: 'App.hello',
defaultMessage: 'Hello Button'
})
return <button aria-label={label}>{label}</button>
}
12 changes: 12 additions & 0 deletions example/with-typescript/src/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineMessages } from 'react-intl'

export default defineMessages({
hello: {
id: 'a.hello',
defaultMessage: 'hello'
},
world: {
id: 'a.world',
defaultMessage: 'world'
}
})
Loading

0 comments on commit 5bc13b9

Please sign in to comment.