Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.

Commit 3226673

Browse files
committed
Add example
1 parent f49e60c commit 3226673

5 files changed

Lines changed: 75 additions & 0 deletions

File tree

example/dist/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Getting Started</title>
6+
</head>
7+
<body>
8+
<script src="bundle.js"></script>
9+
</body>
10+
</html>

example/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "messageformat-yaml-loader-example",
3+
"version": "0.1.0",
4+
"description": "Minimal example for messageformat-yaml-loader",
5+
"scripts": {
6+
"build": "webpack",
7+
"prepare": "npm run build"
8+
},
9+
"main": "src/index.js",
10+
"repository": "https://github.com/eemeli/messageformat-yaml-loader",
11+
"author": "Eemeli Aro <eemeli@gmail.com>",
12+
"license": "MIT",
13+
"dependencies": {
14+
"messageformat-yaml-loader": "file:../",
15+
"webpack": "^3.8.1"
16+
}
17+
}

example/src/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import messages from './messages.yml'
2+
const { format, messages: errors } = messages.en.errors
3+
4+
function component() {
5+
const element = document.createElement('div')
6+
element.innerHTML = format({
7+
attribute: 'Your message',
8+
message: errors.wrong_length({ count: 42 })
9+
})
10+
return element
11+
}
12+
13+
console.log('messages', messages)
14+
document.body.appendChild(component())

example/src/messages.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
en:
2+
errors:
3+
format: "%{attribute} %{message}"
4+
messages:
5+
confirmation: "doesn't match %{attribute}"
6+
accepted: "must be accepted"
7+
wrong_length:
8+
one: "is the wrong length (should be 1 character)"
9+
other: "is the wrong length (should be %{count} characters)"
10+
equal_to: "must be equal to %{count}"

example/webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
entry: './src/index.js',
5+
output: {
6+
filename: 'bundle.js',
7+
path: path.resolve(__dirname, 'dist')
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: [/\.yaml$/, /\.yml$/],
13+
loader: require.resolve('messageformat-yaml-loader'),
14+
options: {
15+
biDiSupport: false,
16+
defaultLocale: 'en',
17+
includeLocales: null,
18+
pluralVariable: 'count',
19+
verbose: false
20+
}
21+
}
22+
]
23+
}
24+
}

0 commit comments

Comments
 (0)