@jobber/components-native 0.110.0 → 0.111.1
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/docs/Icon/Icon.md +1 -0
- package/dist/package.json +3 -3
- package/dist/src/hooks/useAtlantisI18n/releasedLanguages.js +21 -0
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.js +4 -2
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.test.js +115 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/hooks/useAtlantisI18n/releasedLanguages.d.ts +18 -0
- package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.d.ts +3 -1
- package/package.json +3 -3
- package/src/hooks/useAtlantisI18n/releasedLanguages.ts +23 -0
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.test.ts +202 -25
- package/src/hooks/useAtlantisI18n/useAtlantisI18n.ts +13 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Languages that have been fully released and are safe to surface to users.
|
|
3
|
+
* Any locale not present in this list will fall back to "en".
|
|
4
|
+
*
|
|
5
|
+
* To release a new language, add its BCP 47 language tag here (e.g. "es").
|
|
6
|
+
*/
|
|
7
|
+
export declare const RELEASED_LANGUAGES: readonly string[];
|
|
8
|
+
/**
|
|
9
|
+
* Returns the locale to use based on what has been released. Matches on the
|
|
10
|
+
* language part of the locale (before the "-") so that regional variants like
|
|
11
|
+
* "en-CA" or "es-US" resolve correctly:
|
|
12
|
+
*
|
|
13
|
+
* - "en-CA" → "en-CA" (language "en" is released; full locale preserved for
|
|
14
|
+
* date/time formatting)
|
|
15
|
+
* - "es-US" → "en" (language "es" not yet released; falls back to "en")
|
|
16
|
+
* - "fr" → "en" (language "fr" not released; falls back to "en")
|
|
17
|
+
*/
|
|
18
|
+
export declare function getReleasedLocale(locale: string): string;
|
|
@@ -2,7 +2,9 @@ import en from "./locales/en.json";
|
|
|
2
2
|
export type I18nKeys = keyof typeof en;
|
|
3
3
|
export interface useAtlantisI18nValue {
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
5
|
+
* The effective locale, resolved from the AtlantisContext locale against the
|
|
6
|
+
* list of released languages. Regional variants (e.g. "en-CA") are preserved
|
|
7
|
+
* when their language is released. Unreleased locales fall back to "en".
|
|
6
8
|
*/
|
|
7
9
|
readonly locale: string;
|
|
8
10
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.111.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@babel/runtime": "^7.29.2",
|
|
75
75
|
"@gorhom/bottom-sheet": "^5.2.8",
|
|
76
|
-
"@jobber/design": "0.
|
|
76
|
+
"@jobber/design": "0.110.0",
|
|
77
77
|
"@jobber/hooks": "2.21.0",
|
|
78
78
|
"@react-native-community/datetimepicker": "^8.4.5",
|
|
79
79
|
"@react-native/babel-preset": "^0.82.1",
|
|
@@ -124,5 +124,5 @@
|
|
|
124
124
|
"react-native-screens": ">=4.18.0",
|
|
125
125
|
"react-native-svg": ">=12.0.0"
|
|
126
126
|
},
|
|
127
|
-
"gitHead": "
|
|
127
|
+
"gitHead": "a9b32a282f2f70d07b99600c8ce8dfdd2d6e3db9"
|
|
128
128
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Languages that have been fully released and are safe to surface to users.
|
|
3
|
+
* Any locale not present in this list will fall back to "en".
|
|
4
|
+
*
|
|
5
|
+
* To release a new language, add its BCP 47 language tag here (e.g. "es").
|
|
6
|
+
*/
|
|
7
|
+
export const RELEASED_LANGUAGES: readonly string[] = ["en"];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns the locale to use based on what has been released. Matches on the
|
|
11
|
+
* language part of the locale (before the "-") so that regional variants like
|
|
12
|
+
* "en-CA" or "es-US" resolve correctly:
|
|
13
|
+
*
|
|
14
|
+
* - "en-CA" → "en-CA" (language "en" is released; full locale preserved for
|
|
15
|
+
* date/time formatting)
|
|
16
|
+
* - "es-US" → "en" (language "es" not yet released; falls back to "en")
|
|
17
|
+
* - "fr" → "en" (language "fr" not released; falls back to "en")
|
|
18
|
+
*/
|
|
19
|
+
export function getReleasedLocale(locale: string): string {
|
|
20
|
+
const language = locale.split("-")[0];
|
|
21
|
+
|
|
22
|
+
return RELEASED_LANGUAGES.includes(language) ? locale : "en";
|
|
23
|
+
}
|
|
@@ -2,6 +2,7 @@ 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";
|
|
5
6
|
import * as context from "../../AtlantisContext";
|
|
6
7
|
|
|
7
8
|
jest.mock("../../AtlantisContext", () => ({
|
|
@@ -10,6 +11,14 @@ jest.mock("../../AtlantisContext", () => ({
|
|
|
10
11
|
...jest.requireActual("../../AtlantisContext"),
|
|
11
12
|
}));
|
|
12
13
|
|
|
14
|
+
// Mock releasedLanguages so that jest.spyOn can reliably intercept calls from
|
|
15
|
+
// inside the hook. Without this, Babel may resolve the named import as a local
|
|
16
|
+
// binding at module load time, bypassing any spy set up afterwards.
|
|
17
|
+
jest.mock("./releasedLanguages", () => ({
|
|
18
|
+
__esModule: true,
|
|
19
|
+
...jest.requireActual("./releasedLanguages"),
|
|
20
|
+
}));
|
|
21
|
+
|
|
13
22
|
const spy = jest.spyOn(context, "useAtlantisContext");
|
|
14
23
|
const testDate = new Date("2020-01-01T00:00:00.000Z");
|
|
15
24
|
const dateAfterSpringForward = new Date("2020-04-10T00:00:00.000Z");
|
|
@@ -34,7 +43,21 @@ describe("useAtlantisI18n", () => {
|
|
|
34
43
|
);
|
|
35
44
|
});
|
|
36
45
|
|
|
46
|
+
// These tests bypass the release gate via a spy so we can validate Spanish
|
|
47
|
+
// string correctness as the feature is built, independently of RELEASED_LANGUAGES.
|
|
37
48
|
describe("Español", () => {
|
|
49
|
+
let getReleasedLocaleSpy: jest.SpyInstance;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
getReleasedLocaleSpy = jest
|
|
53
|
+
.spyOn(releasedLanguages, "getReleasedLocale")
|
|
54
|
+
.mockImplementation(locale => locale);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
getReleasedLocaleSpy.mockRestore();
|
|
59
|
+
});
|
|
60
|
+
|
|
38
61
|
it("should return español", () => {
|
|
39
62
|
spy.mockReturnValueOnce({
|
|
40
63
|
...context.atlantisContextDefaultValues,
|
|
@@ -44,17 +67,191 @@ describe("useAtlantisI18n", () => {
|
|
|
44
67
|
|
|
45
68
|
expect(result.current.t("cancel")).toBe("Cancelar");
|
|
46
69
|
});
|
|
47
|
-
});
|
|
48
70
|
|
|
49
|
-
|
|
50
|
-
it("should return the english translation", () => {
|
|
71
|
+
it("should return español for regional variant es-US", () => {
|
|
51
72
|
spy.mockReturnValueOnce({
|
|
52
73
|
...context.atlantisContextDefaultValues,
|
|
53
|
-
locale: "
|
|
74
|
+
locale: "es-US",
|
|
54
75
|
});
|
|
55
76
|
const { result } = renderHook(useAtlantisI18n);
|
|
56
77
|
|
|
57
|
-
expect(result.current.t("cancel")).toBe("
|
|
78
|
+
expect(result.current.t("cancel")).toBe("Cancelar");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("formatDate", () => {
|
|
82
|
+
it("should return the date formatted for es", () => {
|
|
83
|
+
spy.mockReturnValueOnce({
|
|
84
|
+
...context.atlantisContextDefaultValues,
|
|
85
|
+
locale: "es",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
89
|
+
expect(result.current.formatDate(testDate)).toBe("1 ene 2020");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("formatTime", () => {
|
|
94
|
+
it("should return the time formatted for es", () => {
|
|
95
|
+
spy.mockReturnValueOnce({
|
|
96
|
+
...context.atlantisContextDefaultValues,
|
|
97
|
+
locale: "es",
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
101
|
+
expect(result.current.formatTime(testDate)).toBe("00:00");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("RELEASED_LANGUAGES fallback", () => {
|
|
107
|
+
describe("unsupported language (fr)", () => {
|
|
108
|
+
it("should return 'en' as the locale", () => {
|
|
109
|
+
spy.mockReturnValueOnce({
|
|
110
|
+
...context.atlantisContextDefaultValues,
|
|
111
|
+
locale: "fr",
|
|
112
|
+
});
|
|
113
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
114
|
+
|
|
115
|
+
expect(result.current.locale).toBe("en");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("should return english translations", () => {
|
|
119
|
+
spy.mockReturnValueOnce({
|
|
120
|
+
...context.atlantisContextDefaultValues,
|
|
121
|
+
locale: "fr",
|
|
122
|
+
});
|
|
123
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
124
|
+
|
|
125
|
+
expect(result.current.t("cancel")).toBe("Cancel");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("es-US (unreleased locale variant)", () => {
|
|
130
|
+
it("should return 'en' as the locale", () => {
|
|
131
|
+
spy.mockReturnValueOnce({
|
|
132
|
+
...context.atlantisContextDefaultValues,
|
|
133
|
+
locale: "es-US",
|
|
134
|
+
});
|
|
135
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
136
|
+
|
|
137
|
+
expect(result.current.locale).toBe("en");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should return english translations", () => {
|
|
141
|
+
spy.mockReturnValueOnce({
|
|
142
|
+
...context.atlantisContextDefaultValues,
|
|
143
|
+
locale: "es-US",
|
|
144
|
+
});
|
|
145
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
146
|
+
|
|
147
|
+
expect(result.current.t("cancel")).toBe("Cancel");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should format date using english locale", () => {
|
|
151
|
+
spy.mockReturnValueOnce({
|
|
152
|
+
...context.atlantisContextDefaultValues,
|
|
153
|
+
locale: "es-US",
|
|
154
|
+
});
|
|
155
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
156
|
+
|
|
157
|
+
expect(result.current.formatDate(testDate)).toBe("Jan 1, 2020");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("should format time using english locale", () => {
|
|
161
|
+
spy.mockReturnValueOnce({
|
|
162
|
+
...context.atlantisContextDefaultValues,
|
|
163
|
+
locale: "es-US",
|
|
164
|
+
});
|
|
165
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
166
|
+
|
|
167
|
+
expect(result.current.formatTime(testDate)).toBe("12:00 AM");
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("es (not yet released)", () => {
|
|
172
|
+
it("should return 'en' as the locale", () => {
|
|
173
|
+
spy.mockReturnValueOnce({
|
|
174
|
+
...context.atlantisContextDefaultValues,
|
|
175
|
+
locale: "es",
|
|
176
|
+
});
|
|
177
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
178
|
+
|
|
179
|
+
expect(result.current.locale).toBe("en");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("should return english translations", () => {
|
|
183
|
+
spy.mockReturnValueOnce({
|
|
184
|
+
...context.atlantisContextDefaultValues,
|
|
185
|
+
locale: "es",
|
|
186
|
+
});
|
|
187
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
188
|
+
|
|
189
|
+
expect(result.current.t("cancel")).toBe("Cancel");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("should format date using english locale", () => {
|
|
193
|
+
spy.mockReturnValueOnce({
|
|
194
|
+
...context.atlantisContextDefaultValues,
|
|
195
|
+
locale: "es",
|
|
196
|
+
});
|
|
197
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
198
|
+
|
|
199
|
+
expect(result.current.formatDate(testDate)).toBe("Jan 1, 2020");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("should format time using english locale", () => {
|
|
203
|
+
spy.mockReturnValueOnce({
|
|
204
|
+
...context.atlantisContextDefaultValues,
|
|
205
|
+
locale: "es",
|
|
206
|
+
});
|
|
207
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
208
|
+
|
|
209
|
+
expect(result.current.formatTime(testDate)).toBe("12:00 AM");
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe("en-CA (released language, regional variant)", () => {
|
|
214
|
+
it("should preserve the full locale for date formatting", () => {
|
|
215
|
+
spy.mockReturnValueOnce({
|
|
216
|
+
...context.atlantisContextDefaultValues,
|
|
217
|
+
locale: "en-CA",
|
|
218
|
+
});
|
|
219
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
220
|
+
|
|
221
|
+
expect(result.current.locale).toBe("en-CA");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("should return english translations", () => {
|
|
225
|
+
spy.mockReturnValueOnce({
|
|
226
|
+
...context.atlantisContextDefaultValues,
|
|
227
|
+
locale: "en-CA",
|
|
228
|
+
});
|
|
229
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
230
|
+
|
|
231
|
+
expect(result.current.t("cancel")).toBe("Cancel");
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("en-GB (released language, regional variant)", () => {
|
|
236
|
+
it("should preserve the full locale for date formatting", () => {
|
|
237
|
+
spy.mockReturnValueOnce({
|
|
238
|
+
...context.atlantisContextDefaultValues,
|
|
239
|
+
locale: "en-GB",
|
|
240
|
+
});
|
|
241
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
242
|
+
|
|
243
|
+
expect(result.current.locale).toBe("en-GB");
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should return english translations", () => {
|
|
247
|
+
spy.mockReturnValueOnce({
|
|
248
|
+
...context.atlantisContextDefaultValues,
|
|
249
|
+
locale: "en-GB",
|
|
250
|
+
});
|
|
251
|
+
const { result } = renderHook(useAtlantisI18n);
|
|
252
|
+
|
|
253
|
+
expect(result.current.t("cancel")).toBe("Cancel");
|
|
254
|
+
});
|
|
58
255
|
});
|
|
59
256
|
});
|
|
60
257
|
|
|
@@ -70,16 +267,6 @@ describe("useAtlantisI18n", () => {
|
|
|
70
267
|
expect(result.current.formatDate(testDate)).toBe("Jan 1, 2020");
|
|
71
268
|
});
|
|
72
269
|
|
|
73
|
-
it("should return the date formatted for es", () => {
|
|
74
|
-
spy.mockReturnValueOnce({
|
|
75
|
-
...context.atlantisContextDefaultValues,
|
|
76
|
-
locale: "es",
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
80
|
-
expect(result.current.formatDate(testDate)).toBe("1 ene 2020");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
270
|
describe("Timezone", () => {
|
|
84
271
|
it.each([
|
|
85
272
|
["America/New_York", "Dec 31, 2019"],
|
|
@@ -105,16 +292,6 @@ describe("useAtlantisI18n", () => {
|
|
|
105
292
|
expect(result.current.formatTime(testDate)).toBe("12:00 AM");
|
|
106
293
|
});
|
|
107
294
|
|
|
108
|
-
it("should return the date formatted for es", () => {
|
|
109
|
-
spy.mockReturnValueOnce({
|
|
110
|
-
...context.atlantisContextDefaultValues,
|
|
111
|
-
locale: "es",
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const { result } = renderHook(useAtlantisI18n);
|
|
115
|
-
expect(result.current.formatTime(testDate)).toBe("00:00");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
295
|
describe("Timezone", () => {
|
|
119
296
|
it.each([
|
|
120
297
|
["America/New_York", "7:00 PM"],
|
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
4
5
|
import { dateFormatter } from "./utils/dateFormatter";
|
|
5
6
|
import { useAtlantisContext } from "../../AtlantisContext";
|
|
6
7
|
|
|
@@ -8,7 +9,9 @@ export type I18nKeys = keyof typeof en;
|
|
|
8
9
|
|
|
9
10
|
export interface useAtlantisI18nValue {
|
|
10
11
|
/**
|
|
11
|
-
* The
|
|
12
|
+
* The effective locale, resolved from the AtlantisContext locale against the
|
|
13
|
+
* list of released languages. Regional variants (e.g. "en-CA") are preserved
|
|
14
|
+
* when their language is released. Unreleased locales fall back to "en".
|
|
12
15
|
*/
|
|
13
16
|
readonly locale: string;
|
|
14
17
|
|
|
@@ -32,7 +35,14 @@ export interface useAtlantisI18nValue {
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export function useAtlantisI18n(): useAtlantisI18nValue {
|
|
35
|
-
const {
|
|
38
|
+
const {
|
|
39
|
+
locale: contextLocale,
|
|
40
|
+
dateFormat,
|
|
41
|
+
timeFormat,
|
|
42
|
+
timeZone,
|
|
43
|
+
} = useAtlantisContext();
|
|
44
|
+
|
|
45
|
+
const locale = getReleasedLocale(contextLocale);
|
|
36
46
|
|
|
37
47
|
const t = useCallback(
|
|
38
48
|
(messageKey: keyof typeof en, values?: Record<string, string>) =>
|
|
@@ -54,7 +64,7 @@ export function useAtlantisI18n(): useAtlantisI18nValue {
|
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
function getLocalizedStrings(locale: string): typeof en {
|
|
57
|
-
switch (locale) {
|
|
67
|
+
switch (locale.split("-")[0]) {
|
|
58
68
|
case "es":
|
|
59
69
|
return es;
|
|
60
70
|
default:
|