Skip to content

Commit 8a9270a

Browse files
authored
Merge pull request #39 from agilebits/ry/upgrades
Upgrade packages and add Prettier
2 parents edab5d1 + d0c78ef commit 8a9270a

35 files changed

+1626
-915
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ jobs:
1111
- run: npm ci
1212
- run: npm run build
1313
- run: npm test
14+
- run: npm run prettier-check

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
package-lock.json
3+
**/*.js

CREDITS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
While this library does not bundle third-party code, we're grateful to the following projects for both inspiration and the feature integrations they make possible:
44

5-
* Parts of the API were inspired by [format-message](https://github.com/format-message/format-message), Copyright (c) 2015 Andy VanWagoner.
5+
- Parts of the API were inspired by [format-message](https://github.com/format-message/format-message), Copyright (c) 2015 Andy VanWagoner.
66

7-
* Build-time compilation of ICU messages is provided by [MessageFormat](https://messageformat.github.io/messageformat/), Copyright (c) 2012-2018 Alex Sexton, Eemeli Aro, and Contributors.
7+
- Build-time compilation of ICU messages is provided by [MessageFormat](https://messageformat.github.io/messageformat/), Copyright (c) 2012-2018 Alex Sexton, Eemeli Aro, and Contributors.
88

9-
* [ICU](http://site.icu-project.org/) (International Components for Unicode) and its syntax are Copyright (c) 1991-2018 Unicode.
9+
- [ICU](http://site.icu-project.org/) (International Components for Unicode) and its syntax are Copyright (c) 1991-2018 Unicode.
1010

11-
* [React](https://github.com/reactjs/reactjs.org) is Copyright (c) 2013-2018 Facebook.
11+
- [React](https://github.com/reactjs/reactjs.org) is Copyright (c) 2013-2018 Facebook.

LICENSE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
55
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66

77
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8-

README.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Just wrap your user-facing strings in `T`. Don't worry about IDs.
88

99
```js
1010
// Import T as a singleton
11-
import {T} from "t-i18n"
11+
import { T } from "t-i18n";
1212

13-
T("Hello world")
13+
T("Hello world");
1414
```
1515

1616
Extract the strings from your code:
@@ -30,12 +30,12 @@ Then load the translations, pass them to `T` and set the locale.
3030

3131
```js
3232
T.set({
33-
locale: "es",
34-
messages: {
35-
en: englishJSON,
36-
es: spanishJSON
37-
}
38-
})
33+
locale: "es",
34+
messages: {
35+
en: englishJSON,
36+
es: spanishJSON,
37+
},
38+
});
3939
```
4040

4141
And that's it. You're localized.
@@ -46,10 +46,10 @@ Formatting is provided courtesy of the [Intl](https://developer.mozilla.org/en-U
4646

4747
```js
4848
// Get a localized, formatted date
49-
T.date(Date.now(), "short")
49+
T.date(Date.now(), "short");
5050

5151
// Or a number
52-
T.number(5, "currency")
52+
T.number(5, "currency");
5353
```
5454

5555
Formatters cache themselves automatically, so you don't have to.
@@ -60,20 +60,17 @@ Basic values are easy to replace.
6060

6161
```js
6262
// "First name: Wendy"
63-
T("First name: {userName}", { userName: "Wendy"})
63+
T("First name: {userName}", { userName: "Wendy" });
6464
```
6565

6666
Non-string values (like React components) can be interpolated using an XML syntax.
6767

6868
```jsx
6969
// ["There's a ", <button>button</button>, " in my sentence!"]
70-
T.$(
71-
"There's a <myButton /> in my {text}!",
72-
{
73-
myButton: () => <button>button</button>,
74-
text: "sentence",
75-
}
76-
)
70+
T.$("There's a <myButton /> in my {text}!", {
71+
myButton: () => <button>button</button>,
72+
text: "sentence",
73+
});
7774
```
7875

7976
If your components have string children, you can translate them inline.
@@ -84,12 +81,12 @@ If your components have string children, you can translate them inline.
8481
// " to change your profile picture."
8582
// ]
8683
T.$(
87-
"<link>Visit your <strong>profile</strong></link> to change your profile picture.",
88-
{
89-
link: (...children) => <a href={"/user/" + user.uuid}>{...children}</a>,
90-
strong: (...children) => <strong>{...children}</strong>,
91-
}
92-
)
84+
"<link>Visit your <strong>profile</strong></link> to change your profile picture.",
85+
{
86+
link: (...children) => <a href={"/user/" + user.uuid}>{...children}</a>,
87+
strong: (...children) => <strong>{...children}</strong>,
88+
},
89+
);
9390
```
9491

9592
## Pluralization and advanced ICU syntax
@@ -98,5 +95,5 @@ To get locale-aware pluralization, you should [precompile your translations](htt
9895

9996
```js
10097
// Pluralization with ICU syntax
101-
T("You have { plural, numCats, =0 {0 cats} other {# cats} }", {numCats: 4})
102-
```
98+
T("You have { plural, numCats, =0 {0 cats} other {# cats} }", { numCats: 4 });
99+
```

dist/es6/format.d.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
export declare type IntlFormat = Intl.DateTimeFormat | Intl.NumberFormat;
2-
export declare type IntlFormatType<X extends IntlFormat> = X extends Intl.DateTimeFormat ? typeof Intl.DateTimeFormat : typeof Intl.NumberFormat;
3-
export declare type IntlFormatOptions<X extends IntlFormat> = X extends Intl.DateTimeFormat ? Intl.DateTimeFormatOptions : Intl.NumberFormatOptions;
4-
export declare type CachedFormatter<X extends IntlFormat> = (locale: string, formatOptions?: IntlFormatOptions<X>) => X;
1+
export type IntlFormat = Intl.DateTimeFormat | Intl.NumberFormat;
2+
export type IntlFormatType<X extends IntlFormat> = X extends Intl.DateTimeFormat ? typeof Intl.DateTimeFormat : typeof Intl.NumberFormat;
3+
export type IntlFormatOptions<X extends IntlFormat> = X extends Intl.DateTimeFormat ? Intl.DateTimeFormatOptions : Intl.NumberFormatOptions;
4+
export type CachedFormatter<X extends IntlFormat> = (locale: string, formatOptions?: IntlFormatOptions<X>) => X;
55
export declare const dateTimeFormats: {
6-
short: {
7-
month: string;
8-
day: string;
9-
year: string;
6+
readonly short: {
7+
readonly month: "short";
8+
readonly day: "numeric";
9+
readonly year: "numeric";
1010
};
11-
long: {
12-
month: string;
13-
day: string;
14-
year: string;
11+
readonly long: {
12+
readonly month: "long";
13+
readonly day: "numeric";
14+
readonly year: "numeric";
1515
};
16-
dateTime: {
17-
month: string;
18-
day: string;
19-
year: string;
20-
hour: string;
21-
minute: string;
16+
readonly dateTime: {
17+
readonly month: "short";
18+
readonly day: "numeric";
19+
readonly year: "numeric";
20+
readonly hour: "numeric";
21+
readonly minute: "numeric";
2222
};
2323
};
2424
export declare const numberFormats: {
25-
currency: {
26-
style: string;
27-
currency: string;
25+
readonly currency: {
26+
readonly style: "currency";
27+
readonly currency: "USD";
2828
};
29-
decimal: {
30-
style: string;
29+
readonly decimal: {
30+
readonly style: "decimal";
3131
};
32-
percent: {
33-
style: string;
32+
readonly percent: {
33+
readonly style: "percent";
3434
};
3535
};
3636
export default function createCachedFormatter<X extends IntlFormat>(intlFormat: IntlFormatType<X>): CachedFormatter<X>;

dist/es6/t-i18n.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IntlFormatters {
1212
date: (value: Date | number, formatName?: keyof typeof dateTimeFormats, locale?: string) => string;
1313
number: (value: number, formatName?: keyof typeof numberFormats, locale?: string) => string;
1414
}
15-
export declare type TFunc = BasicTFunc & IntlFormatters;
15+
export type TFunc = BasicTFunc & IntlFormatters;
1616
export declare const makeBasicT: () => BasicTFunc;
1717
export declare const makeT: () => TFunc;
1818
declare const _default: TFunc;

dist/es6/t-i18n.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const makeIntlFormatters = (locale) => {
2424
const getDateTimeFormat = () => {
2525
const delegate = Intl.DateTimeFormat;
2626
function DateTimeFormat() {
27-
var _a, _b, _c;
27+
var _a;
2828
const args = Array.prototype.slice.apply(arguments);
29-
const lang = typeof ((_a = args) === null || _a === void 0 ? void 0 : _a[0]) === "string" ? args[0] : "en-US";
30-
const timeZone = typeof ((_c = (_b = args) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.timeZone) === "string" ? args[1].timeZone : "America/Toronto";
29+
const lang = typeof (args === null || args === void 0 ? void 0 : args[0]) === "string" ? args[0] : "en-US";
30+
const timeZone = typeof ((_a = args === null || args === void 0 ? void 0 : args[1]) === null || _a === void 0 ? void 0 : _a.timeZone) === "string" ? args[1].timeZone : "America/Toronto";
3131
return delegate.apply(this, [lang, timeZone]);
3232
}
3333
DateTimeFormat.prototype = delegate.prototype;

dist/es6/types.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export declare type MFunc = (replacements?: IcuReplacements) => string;
2-
export declare type Compiler = (message: string) => MFunc;
1+
export type MFunc = (replacements?: IcuReplacements) => string;
2+
export type Compiler = (message: string) => MFunc;
33
export interface Messages {
44
[s: string]: {
55
[s: string]: string | MFunc;
@@ -10,8 +10,8 @@ export interface Config {
1010
locale: string;
1111
idGenerator: (message: string) => string;
1212
}
13-
export declare type Mutable<X> = {
14-
[P in keyof X]: X[P];
13+
export type Mutable<X> = {
14+
-readonly [P in keyof X]: X[P];
1515
};
1616
export interface IcuReplacements {
1717
readonly [s: string]: string | number;

dist/es6/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

0 commit comments

Comments
 (0)