Skip to content

Commit 55423d0

Browse files
author
Maciej Warszawski
committed
setup lerna
1 parent 023f117 commit 55423d0

File tree

19 files changed

+1252
-255
lines changed

19 files changed

+1252
-255
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package.json

create-packages.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ rm -r lib/**/types.js && \
66
cp -u packages/react-intl-namespaces/package.json lib/react-intl-namespaces/package.json && \
77
cp -u packages/react-intl-namespaces-locize-client/package.json lib/react-intl-namespaces-locize-client/package.json && \
88
cp -u packages/react-intl-namespaces-locize-editor/package.json lib/react-intl-namespaces-locize-editor/package.json && \
9+
cp -u README.md lib/react-intl-namespaces && \
10+
cp -u README.md lib/react-intl-namespaces-locize-client && \
11+
cp -u README.md lib/react-intl-namespaces-locize-editor && \
912
echo success

lerna.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"lerna": "2.8.0",
3+
"packages": [
4+
"lib/*"
5+
],
6+
"version": "0.0.1-0.0"
7+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# React Intl Namespaces
2+
3+
Integrations of [react-intl] internationalization library with [locize.com]
4+
online translation service.
5+
6+
[![build-status-icon]](https://travis-ci.org/maciejw/react-intl-namespaces)
7+
![npm-version-icon]
8+
9+
## Goals of this library
10+
11+
* add support of dividing your application resources into namespaces that can be lazy loaded from server
12+
* make resources statically typed
13+
* add support of [locize.com] in-context editor.
14+
* add resource synchronization with [locize.com] or any other backend.
15+
16+
## Getting started
17+
18+
```tsx
19+
const someNamespace = defineMessages<'property1'>({
20+
property1: {
21+
defaultMessage: 'text with {someValue}',
22+
description: 'description of text with some value',
23+
id: 'property1',
24+
},
25+
});
26+
27+
const anotherNamespace = defineMessages<'property1'>({
28+
property1: {
29+
defaultMessage: 'another text',
30+
description: 'description of another text',
31+
id: 'property1',
32+
},
33+
});
34+
35+
const values = { someValue: 'value' };
36+
37+
const App = (props: IntlBackendProvider.Props) => (
38+
<IntlBackendProvider
39+
locale={props.locale}
40+
showIds={props.showIds}
41+
getMessagesFromNamespaceFactory={props.getMessagesFromNamespaceFactory}
42+
addMissingMessageFactory={props.addMissingMessageFactory}
43+
>
44+
<IntlNamespaceProvider namespace="someNamespace">
45+
<div>
46+
<FormattedMessage {...someNamespace.property1} values={values} />
47+
</div>
48+
</IntlNamespaceProvider>
49+
<IntlNamespaceProvider namespace="anotherNamespace">
50+
<div>
51+
<FormattedMessage {...anotherNamespace.property1} />
52+
</div>
53+
</IntlNamespaceProvider>
54+
</IntlBackendProvider>
55+
);
56+
```
57+
58+
This code uses two namespaces and provides a way of communication with backed using getMessagesFromNamespace and addMissingMessage API.
59+
60+
Namespaces have have the same resource keys, that do not interfere with each other.
61+
62+
Those namespaces could be application modules.
63+
64+
Also we can see with one switch resource keys instead of resource texts when we set showIds to true. This is what will be displayed
65+
66+
```txt
67+
[someNamespace:property1 (someValue)]
68+
```
69+
70+
instead of formatted
71+
72+
```txt
73+
text with value
74+
```
75+
76+
## Building
77+
78+
In order to build this library you have to clone it
79+
80+
```sh
81+
git clone https://github.com/maciejw/react-intl-namespaces.git
82+
```
83+
84+
and restore packages with
85+
86+
```sh
87+
yarn
88+
```
89+
90+
to show sample integration project you can
91+
92+
```sh
93+
yarn start
94+
```
95+
96+
you can also test with
97+
98+
```sh
99+
yarn test
100+
```
101+
102+
## Documentation
103+
104+
//TODO
105+
106+
[locize.com]: https://locize.com
107+
[react-intl]: https://github.com/yahoo/react-intl
108+
[build-status-icon]: https://travis-ci.org/maciejw/react-intl-namespaces.svg?branch=master
109+
[npm-version-icon]: https://img.shields.io/npm/v/react-intl-namespaces.svg?maxAge=2592000
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
{
2-
"name": "react-intl-namespaces-locize-client",
3-
"version": "1.0.0",
4-
"main": "index.js",
5-
"module": "index.es.js",
6-
"license": "MIT",
7-
"peerDependencies": {
8-
"react": "^16.0.0",
9-
"react-intl": "^2.4.0",
10-
"react-intl-namespaces": "^1.0.0"
11-
},
12-
"author": {
13-
"name": "Maciej Warszawski",
14-
"url": "https://github.com/maciejw"
15-
},
16-
"bugs": {
17-
"url": "https://github.com/maciejw/react-intl-namespaces/issues/new"
18-
},
19-
"repository": {
20-
"type": "git",
21-
"url": "https://github.com/maciejw/react-intl-namespaces"
22-
}
23-
}
1+
{
2+
"name": "react-intl-namespaces-locize-client",
3+
"version": "0.0.1-0.0",
4+
"main": "index.js",
5+
"module": "index.es.js",
6+
"license": "MIT",
7+
"peerDependencies": {
8+
"react": "^16.0.0",
9+
"react-intl": "^2.4.0",
10+
"react-intl-namespaces": "^1.0.0"
11+
},
12+
"author": {
13+
"name": "Maciej Warszawski",
14+
"url": "https://github.com/maciejw"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/maciejw/react-intl-namespaces/issues/new"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/maciejw/react-intl-namespaces"
22+
}
23+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# React Intl Namespaces
2+
3+
Integrations of [react-intl] internationalization library with [locize.com]
4+
online translation service.
5+
6+
[![build-status-icon]](https://travis-ci.org/maciejw/react-intl-namespaces)
7+
![npm-version-icon]
8+
9+
## Goals of this library
10+
11+
* add support of dividing your application resources into namespaces that can be lazy loaded from server
12+
* make resources statically typed
13+
* add support of [locize.com] in-context editor.
14+
* add resource synchronization with [locize.com] or any other backend.
15+
16+
## Getting started
17+
18+
```tsx
19+
const someNamespace = defineMessages<'property1'>({
20+
property1: {
21+
defaultMessage: 'text with {someValue}',
22+
description: 'description of text with some value',
23+
id: 'property1',
24+
},
25+
});
26+
27+
const anotherNamespace = defineMessages<'property1'>({
28+
property1: {
29+
defaultMessage: 'another text',
30+
description: 'description of another text',
31+
id: 'property1',
32+
},
33+
});
34+
35+
const values = { someValue: 'value' };
36+
37+
const App = (props: IntlBackendProvider.Props) => (
38+
<IntlBackendProvider
39+
locale={props.locale}
40+
showIds={props.showIds}
41+
getMessagesFromNamespaceFactory={props.getMessagesFromNamespaceFactory}
42+
addMissingMessageFactory={props.addMissingMessageFactory}
43+
>
44+
<IntlNamespaceProvider namespace="someNamespace">
45+
<div>
46+
<FormattedMessage {...someNamespace.property1} values={values} />
47+
</div>
48+
</IntlNamespaceProvider>
49+
<IntlNamespaceProvider namespace="anotherNamespace">
50+
<div>
51+
<FormattedMessage {...anotherNamespace.property1} />
52+
</div>
53+
</IntlNamespaceProvider>
54+
</IntlBackendProvider>
55+
);
56+
```
57+
58+
This code uses two namespaces and provides a way of communication with backed using getMessagesFromNamespace and addMissingMessage API.
59+
60+
Namespaces have have the same resource keys, that do not interfere with each other.
61+
62+
Those namespaces could be application modules.
63+
64+
Also we can see with one switch resource keys instead of resource texts when we set showIds to true. This is what will be displayed
65+
66+
```txt
67+
[someNamespace:property1 (someValue)]
68+
```
69+
70+
instead of formatted
71+
72+
```txt
73+
text with value
74+
```
75+
76+
## Building
77+
78+
In order to build this library you have to clone it
79+
80+
```sh
81+
git clone https://github.com/maciejw/react-intl-namespaces.git
82+
```
83+
84+
and restore packages with
85+
86+
```sh
87+
yarn
88+
```
89+
90+
to show sample integration project you can
91+
92+
```sh
93+
yarn start
94+
```
95+
96+
you can also test with
97+
98+
```sh
99+
yarn test
100+
```
101+
102+
## Documentation
103+
104+
//TODO
105+
106+
[locize.com]: https://locize.com
107+
[react-intl]: https://github.com/yahoo/react-intl
108+
[build-status-icon]: https://travis-ci.org/maciejw/react-intl-namespaces.svg?branch=master
109+
[npm-version-icon]: https://img.shields.io/npm/v/react-intl-namespaces.svg?maxAge=2592000

lib/react-intl-namespaces-locize-editor/index.es.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,16 @@ class EditorPanel$1 extends Component {
9595
}
9696
}
9797

98-
class CancelablePromise {
99-
constructor(executor, cancel) {
100-
this.cancel = cancel;
101-
this.promise = new Promise(executor);
102-
}
103-
then(onfulfilled, onrejected) {
104-
return this.promise.then(onfulfilled, onrejected);
105-
}
106-
catch(onrejected) {
107-
return this.promise.catch(onrejected);
108-
}
109-
}
110-
function delay(timeout = 0) {
111-
let timeoutHandle = 0;
112-
const p = new CancelablePromise(resolve => {
113-
timeoutHandle = window.setTimeout(resolve, timeout);
114-
}, () => window.clearTimeout(timeoutHandle));
115-
return p;
116-
}
117-
11898
var container = "EditorWindow_container__JbpaF";
11999
var iframe = "EditorWindow_iframe__3xfPU";
120100
var css$1 = ".EditorWindow_container__JbpaF {\r\n bottom: 0;\r\n -webkit-box-shadow: -3px 0 5px 0 rgba(0, 0, 0, .5);\r\n box-shadow: -3px 0 5px 0 rgba(0, 0, 0, .5);\r\n position: fixed;\r\n right: 0;\r\n top: 0;\r\n z-index: 2000;\r\n}\r\n\r\n.EditorWindow_iframe__3xfPU {\r\n border: none;\r\n height: 100%;\r\n}\r\n";
121101
__$$styleInject(css$1);
122102

103+
function delay(timeout = 0) {
104+
return new Promise(resolve => {
105+
window.setTimeout(resolve, timeout);
106+
});
107+
}
123108
class EditorWindow$1 extends Component {
124109
constructor(props, state) {
125110
super(props, state);
@@ -132,7 +117,6 @@ class EditorWindow$1 extends Component {
132117
yield delay(3000);
133118
resolve(openedWindow);
134119
})));
135-
// this.window = openedWindow;
136120
}
137121
}
138122
}
@@ -147,7 +131,7 @@ class EditorWindow$1 extends Component {
147131
resolve(e.contentWindow);
148132
}));
149133
}
150-
}, style: iframe$$1, "data-ignore-locize-editor": "true", src: this.props.url })));
134+
}, style: iframe$$1, src: this.props.url })));
151135
case 'window':
152136
return null;
153137
}

lib/react-intl-namespaces-locize-editor/index.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,16 @@ class EditorPanel$1 extends React.Component {
9999
}
100100
}
101101

102-
class CancelablePromise {
103-
constructor(executor, cancel) {
104-
this.cancel = cancel;
105-
this.promise = new Promise(executor);
106-
}
107-
then(onfulfilled, onrejected) {
108-
return this.promise.then(onfulfilled, onrejected);
109-
}
110-
catch(onrejected) {
111-
return this.promise.catch(onrejected);
112-
}
113-
}
114-
function delay(timeout = 0) {
115-
let timeoutHandle = 0;
116-
const p = new CancelablePromise(resolve => {
117-
timeoutHandle = window.setTimeout(resolve, timeout);
118-
}, () => window.clearTimeout(timeoutHandle));
119-
return p;
120-
}
121-
122102
var container = "EditorWindow_container__JbpaF";
123103
var iframe = "EditorWindow_iframe__3xfPU";
124104
var css$1 = ".EditorWindow_container__JbpaF {\r\n bottom: 0;\r\n -webkit-box-shadow: -3px 0 5px 0 rgba(0, 0, 0, .5);\r\n box-shadow: -3px 0 5px 0 rgba(0, 0, 0, .5);\r\n position: fixed;\r\n right: 0;\r\n top: 0;\r\n z-index: 2000;\r\n}\r\n\r\n.EditorWindow_iframe__3xfPU {\r\n border: none;\r\n height: 100%;\r\n}\r\n";
125105
__$$styleInject(css$1);
126106

107+
function delay(timeout = 0) {
108+
return new Promise(resolve => {
109+
window.setTimeout(resolve, timeout);
110+
});
111+
}
127112
class EditorWindow$1 extends React.Component {
128113
constructor(props, state) {
129114
super(props, state);
@@ -136,7 +121,6 @@ class EditorWindow$1 extends React.Component {
136121
yield delay(3000);
137122
resolve(openedWindow);
138123
})));
139-
// this.window = openedWindow;
140124
}
141125
}
142126
}
@@ -151,7 +135,7 @@ class EditorWindow$1 extends React.Component {
151135
resolve(e.contentWindow);
152136
}));
153137
}
154-
}, style: iframe$$1, "data-ignore-locize-editor": "true", src: this.props.url })));
138+
}, style: iframe$$1, src: this.props.url })));
155139
case 'window':
156140
return null;
157141
}

0 commit comments

Comments
 (0)