@jobber/components-native 0.112.1 → 0.113.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +4 -3
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.js +2 -4
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.test.js +15 -115
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.d.ts +1 -3
- package/package.json +4 -3
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.test.ts +25 -202
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.ts +3 -13
- package/dist/src/hooks/useAtlantisI18n/releasedLanguages.js +0 -21
- package/dist/types/src/hooks/useAtlantisI18n/releasedLanguages.d.ts +0 -18
- package/src/hooks/useAtlantisI18n/releasedLanguages.ts +0 -23
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.113.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"compile": "tsc -p tsconfig.build.json",
|
|
54
54
|
"build:clean": "rm -rf ./dist",
|
|
55
55
|
"storybook": "storybook dev -p 6008 --disable-telemetry",
|
|
56
|
-
"storybook:build": "storybook build --disable-telemetry"
|
|
56
|
+
"storybook:build": "storybook build --disable-telemetry",
|
|
57
|
+
"lint:locales": "node scripts/check-locale-parity.mjs"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"@react-native-clipboard/clipboard": "^1.11.2",
|
|
@@ -124,5 +125,5 @@
|
|
|
124
125
|
"react-native-screens": ">=4.18.0",
|
|
125
126
|
"react-native-svg": ">=12.0.0"
|
|
126
127
|
},
|
|
127
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "25cd8815738e86b9f49311096e7d4ffd02d843b5"
|
|
128
129
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import en from "./locales/en.json";
|
|
3
3
|
import es from "./locales/es.json";
|
|
4
|
-
import { getReleasedLocale } from "./releasedLanguages";
|
|
5
4
|
import { dateFormatter } from "./utils/dateFormatter";
|
|
6
5
|
import { useAtlantisContext } from "../../AtlantisContext";
|
|
7
6
|
export function useAtlantisI18n() {
|
|
8
|
-
const { locale
|
|
9
|
-
const locale = getReleasedLocale(contextLocale);
|
|
7
|
+
const { locale, dateFormat, timeFormat, timeZone } = useAtlantisContext();
|
|
10
8
|
const t = useCallback((messageKey, values) => formatMessage(messageKey, values, locale), [formatMessage, locale]);
|
|
11
9
|
const formatDate = useCallback((date) => dateFormatter(date, dateFormat, { locale, timeZone }), [dateFormatter, locale]);
|
|
12
10
|
const formatTime = useCallback((date) => dateFormatter(date, timeFormat, { locale, timeZone }), [dateFormatter, locale]);
|
|
13
11
|
return { locale, t, formatDate, formatTime };
|
|
14
12
|
}
|
|
15
13
|
function getLocalizedStrings(locale) {
|
|
16
|
-
switch (locale
|
|
14
|
+
switch (locale) {
|
|
17
15
|
case "es":
|
|
18
16
|
return es;
|
|
19
17
|
default:
|
|
@@ -2,15 +2,10 @@ import { renderHook } from "@testing-library/react-native";
|
|
|
2
2
|
import { useAtlantisI18n } from ".";
|
|
3
3
|
import en from "./locales/en.json";
|
|
4
4
|
import es from "./locales/es.json";
|
|
5
|
-
import * as releasedLanguages from "./releasedLanguages";
|
|
6
5
|
import * as context from "../../AtlantisContext";
|
|
7
6
|
jest.mock("../../AtlantisContext", () => (Object.assign({
|
|
8
7
|
// need to mark this as a module so that we can spy on it
|
|
9
8
|
__esModule: true }, jest.requireActual("../../AtlantisContext"))));
|
|
10
|
-
// Mock releasedLanguages so that jest.spyOn can reliably intercept calls from
|
|
11
|
-
// inside the hook. Without this, Babel may resolve the named import as a local
|
|
12
|
-
// binding at module load time, bypassing any spy set up afterwards.
|
|
13
|
-
jest.mock("./releasedLanguages", () => (Object.assign({ __esModule: true }, jest.requireActual("./releasedLanguages"))));
|
|
14
9
|
const spy = jest.spyOn(context, "useAtlantisContext");
|
|
15
10
|
const testDate = new Date("2020-01-01T00:00:00.000Z");
|
|
16
11
|
const dateAfterSpringForward = new Date("2020-04-10T00:00:00.000Z");
|
|
@@ -27,123 +22,18 @@ describe("useAtlantisI18n", () => {
|
|
|
27
22
|
const { result } = renderHook(useAtlantisI18n);
|
|
28
23
|
expect(result.current.t("FormatFile.preview", { item: "🔱" })).toBe("Preview 🔱");
|
|
29
24
|
});
|
|
30
|
-
// These tests bypass the release gate via a spy so we can validate Spanish
|
|
31
|
-
// string correctness as the feature is built, independently of RELEASED_LANGUAGES.
|
|
32
25
|
describe("Español", () => {
|
|
33
|
-
let getReleasedLocaleSpy;
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
getReleasedLocaleSpy = jest
|
|
36
|
-
.spyOn(releasedLanguages, "getReleasedLocale")
|
|
37
|
-
.mockImplementation(locale => locale);
|
|
38
|
-
});
|
|
39
|
-
afterEach(() => {
|
|
40
|
-
getReleasedLocaleSpy.mockRestore();
|
|
41
|
-
});
|
|
42
26
|
it("should return español", () => {
|
|
43
27
|
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
44
28
|
const { result } = renderHook(useAtlantisI18n);
|
|
45
29
|
expect(result.current.t("cancel")).toBe("Cancelar");
|
|
46
30
|
});
|
|
47
|
-
it("should return español for regional variant es-US", () => {
|
|
48
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es-US" }));
|
|
49
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
50
|
-
expect(result.current.t("cancel")).toBe("Cancelar");
|
|
51
|
-
});
|
|
52
|
-
describe("formatDate", () => {
|
|
53
|
-
it("should return the date formatted for es", () => {
|
|
54
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
55
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
56
|
-
expect(result.current.formatDate(testDate)).toBe("1 ene 2020");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe("formatTime", () => {
|
|
60
|
-
it("should return the time formatted for es", () => {
|
|
61
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
62
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
63
|
-
expect(result.current.formatTime(testDate)).toBe("00:00");
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
31
|
});
|
|
67
|
-
describe("
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
expect(result.current.locale).toBe("en");
|
|
73
|
-
});
|
|
74
|
-
it("should return english translations", () => {
|
|
75
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "fr" }));
|
|
76
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
77
|
-
expect(result.current.t("cancel")).toBe("Cancel");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe("es-US (unreleased locale variant)", () => {
|
|
81
|
-
it("should return 'en' as the locale", () => {
|
|
82
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es-US" }));
|
|
83
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
84
|
-
expect(result.current.locale).toBe("en");
|
|
85
|
-
});
|
|
86
|
-
it("should return english translations", () => {
|
|
87
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es-US" }));
|
|
88
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
89
|
-
expect(result.current.t("cancel")).toBe("Cancel");
|
|
90
|
-
});
|
|
91
|
-
it("should format date using english locale", () => {
|
|
92
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es-US" }));
|
|
93
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
94
|
-
expect(result.current.formatDate(testDate)).toBe("Jan 1, 2020");
|
|
95
|
-
});
|
|
96
|
-
it("should format time using english locale", () => {
|
|
97
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es-US" }));
|
|
98
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
99
|
-
expect(result.current.formatTime(testDate)).toBe("12:00 AM");
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe("es (not yet released)", () => {
|
|
103
|
-
it("should return 'en' as the locale", () => {
|
|
104
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
105
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
106
|
-
expect(result.current.locale).toBe("en");
|
|
107
|
-
});
|
|
108
|
-
it("should return english translations", () => {
|
|
109
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
110
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
111
|
-
expect(result.current.t("cancel")).toBe("Cancel");
|
|
112
|
-
});
|
|
113
|
-
it("should format date using english locale", () => {
|
|
114
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
115
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
116
|
-
expect(result.current.formatDate(testDate)).toBe("Jan 1, 2020");
|
|
117
|
-
});
|
|
118
|
-
it("should format time using english locale", () => {
|
|
119
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
120
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
121
|
-
expect(result.current.formatTime(testDate)).toBe("12:00 AM");
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
describe("en-CA (released language, regional variant)", () => {
|
|
125
|
-
it("should preserve the full locale for date formatting", () => {
|
|
126
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "en-CA" }));
|
|
127
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
128
|
-
expect(result.current.locale).toBe("en-CA");
|
|
129
|
-
});
|
|
130
|
-
it("should return english translations", () => {
|
|
131
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "en-CA" }));
|
|
132
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
133
|
-
expect(result.current.t("cancel")).toBe("Cancel");
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe("en-GB (released language, regional variant)", () => {
|
|
137
|
-
it("should preserve the full locale for date formatting", () => {
|
|
138
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "en-GB" }));
|
|
139
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
140
|
-
expect(result.current.locale).toBe("en-GB");
|
|
141
|
-
});
|
|
142
|
-
it("should return english translations", () => {
|
|
143
|
-
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "en-GB" }));
|
|
144
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
145
|
-
expect(result.current.t("cancel")).toBe("Cancel");
|
|
146
|
-
});
|
|
32
|
+
describe("Unsupported language", () => {
|
|
33
|
+
it("should return the english translation", () => {
|
|
34
|
+
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "fr" }));
|
|
35
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
36
|
+
expect(result.current.t("cancel")).toBe("Cancel");
|
|
147
37
|
});
|
|
148
38
|
});
|
|
149
39
|
describe("Translation files", () => {
|
|
@@ -156,6 +46,11 @@ describe("useAtlantisI18n", () => {
|
|
|
156
46
|
const { result } = renderHook(useAtlantisI18n);
|
|
157
47
|
expect(result.current.formatDate(testDate)).toBe("Jan 1, 2020");
|
|
158
48
|
});
|
|
49
|
+
it("should return the date formatted for es", () => {
|
|
50
|
+
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
51
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
52
|
+
expect(result.current.formatDate(testDate)).toBe("1 ene 2020");
|
|
53
|
+
});
|
|
159
54
|
describe("Timezone", () => {
|
|
160
55
|
it.each([
|
|
161
56
|
["America/New_York", "Dec 31, 2019"],
|
|
@@ -175,6 +70,11 @@ describe("useAtlantisI18n", () => {
|
|
|
175
70
|
const { result } = renderHook(useAtlantisI18n);
|
|
176
71
|
expect(result.current.formatTime(testDate)).toBe("12:00 AM");
|
|
177
72
|
});
|
|
73
|
+
it("should return the time formatted for es", () => {
|
|
74
|
+
spy.mockReturnValueOnce(Object.assign(Object.assign({}, context.atlantisContextDefaultValues), { locale: "es" }));
|
|
75
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
76
|
+
expect(result.current.formatTime(testDate)).toBe("00:00");
|
|
77
|
+
});
|
|
178
78
|
describe("Timezone", () => {
|
|
179
79
|
it.each([
|
|
180
80
|
["America/New_York", "7:00 PM"],
|