Skip to content

Commit 5735215

Browse files
authored
refactor: change getI18String to getEnglishText (#1157)
1 parent 6c343d4 commit 5735215

13 files changed

+50
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
2-
import { getI18nString } from "~/utils/i18n";
2+
import { getEnglishText } from "~/utils/i18n";
33

44
export const ROADMAP_LINK_NAME = new RegExp(
5-
getI18nString("i18n.components.btn_road_map.aria_label"),
5+
getEnglishText("i18n.components.btn_road_map.aria_label"),
66
"i"
77
);
88
export const ACTIVIST_LANDING_LINK_NAME = new RegExp(
9-
getI18nString("i18n.components.logo_activist.aria_label"),
9+
getEnglishText("i18n.components.logo_activist.aria_label"),
1010
"i"
1111
);
1212
export const SIGN_IN_LINK_NAME = new RegExp(
13-
getI18nString("i18n._global.sign_in_aria_label"),
13+
getEnglishText("i18n._global.sign_in_aria_label"),
1414
"i"
1515
);
1616
export const SIGN_UP_LINK_NAME = new RegExp(
17-
getI18nString("i18n._global.sign_up_aria_label"),
17+
getEnglishText("i18n._global.sign_up_aria_label"),
1818
"i"
1919
);

frontend/test-e2e/component-objects/InfoMenu.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
3-
import { getI18nString } from "~/utils/i18n";
3+
import { getEnglishText } from "~/utils/i18n";
44

55
export const newInfoMenu = (parent: Page | Locator) => ({
66
toggleOpenButton: parent.getByRole("button", {
77
name: new RegExp(
8-
getI18nString("i18n.components.dropdown_info.info_aria_label"),
8+
getEnglishText("i18n.components.dropdown_info.info_aria_label"),
99
"i"
1010
),
1111
}),

frontend/test-e2e/component-objects/LanguageMenu.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
33
import { LOCALE_CODE } from "~/locales";
4-
import { getI18nString } from "~/utils/i18n";
4+
import { getEnglishText } from "~/utils/i18n";
55

66
const getMenuLocator = (parent: Page | Locator) =>
77
parent.locator(".dropdown-language").getByRole("menu");
@@ -44,7 +44,7 @@ export const newLanguageMenu = (
4444
menu: getMenuLocator(parent),
4545
toggleOpenButton: parent.getByRole("button", {
4646
name: new RegExp(
47-
getI18nString(
47+
getEnglishText(
4848
"i18n.components.dropdown_language.open_dropdown_aria_label"
4949
),
5050
"i"

frontend/test-e2e/component-objects/PasswordStrength.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
33
import { expect } from "playwright/test";
4-
import { getI18nString } from "~/utils/i18n";
4+
import { getEnglishText } from "~/utils/i18n";
55

66
export const PASSWORD_RATING = {
77
INVALID: new RegExp(
8-
getI18nString("i18n.components.indicator_password_strength.invalid"),
8+
getEnglishText("i18n.components.indicator_password_strength.invalid"),
99
"i"
1010
),
1111
VERY_WEAK: new RegExp(
12-
getI18nString("i18n.components.indicator_password_strength.very_weak"),
12+
getEnglishText("i18n.components.indicator_password_strength.very_weak"),
1313
"i"
1414
),
1515
WEAK: new RegExp(
16-
getI18nString("i18n.components.indicator_password_strength.weak"),
16+
getEnglishText("i18n.components.indicator_password_strength.weak"),
1717
"i"
1818
),
1919
MEDIUM: new RegExp(
20-
getI18nString("i18n.components.indicator_password_strength.medium"),
20+
getEnglishText("i18n.components.indicator_password_strength.medium"),
2121
"i"
2222
),
2323
STRONG: new RegExp(
24-
getI18nString("i18n.components.indicator_password_strength.strong"),
24+
getEnglishText("i18n.components.indicator_password_strength.strong"),
2525
"i"
2626
),
2727
VERY_STRONG: new RegExp(
28-
getI18nString("i18n.components.indicator_password_strength.very_strong"),
28+
getEnglishText("i18n.components.indicator_password_strength.very_strong"),
2929
"i"
3030
),
3131
};

frontend/test-e2e/component-objects/SidebarLeft.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
33
import { expect } from "playwright/test";
4-
import { getI18nString } from "~/utils/i18n";
4+
import { getEnglishText } from "~/utils/i18n";
55

66
export const newSidebarLeft = (page: Page) => new SidebarLeft(page);
77

@@ -20,7 +20,7 @@ export class SidebarLeft {
2020

2121
this.lockToggle = this.root.getByRole("button", {
2222
name: new RegExp(
23-
getI18nString(
23+
getEnglishText(
2424
"i18n.components.sidebar_left_header.sidebar_collapse_aria_label"
2525
),
2626
"i"

frontend/test-e2e/component-objects/SidebarRight.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
33
import { LOCALE_CODE } from "~/locales";
4-
import { getI18nString } from "~/utils/i18n";
4+
import { getEnglishText } from "~/utils/i18n";
55

66
export const newSidebarRight = (
77
parent: Page | Locator,
@@ -53,15 +53,15 @@ export const newSidebarRight = (
5353
parent,
5454
closeButton: parent.getByRole("button", {
5555
name: new RegExp(
56-
getI18nString(
56+
getEnglishText(
5757
"i18n.components.sidebar_right_hamburger.collapse_aria_label"
5858
),
5959
"i"
6060
),
6161
}),
6262
openButton: parent.getByRole("button", {
6363
name: new RegExp(
64-
getI18nString(
64+
getEnglishText(
6565
"i18n.components.sidebar_right_hamburger.collapse_aria_label"
6666
),
6767
"i"
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
3-
import { getI18nString } from "~/utils/i18n";
3+
import { getEnglishText } from "~/utils/i18n";
44

55
export const newSignInMenu = (parent: Page | Locator) => ({
66
toggleOpenButton: parent.locator("#user-options").getByRole("button", {
77
name: new RegExp(
8-
getI18nString(
8+
getEnglishText(
99
"i18n.components.dropdown_user_options.username_aria_label"
1010
),
1111
"i"
1212
),
1313
}),
1414
signInOption: parent.locator("#user-options").getByRole("menuitem", {
15-
name: new RegExp(getI18nString("i18n._global.sign_in"), "i"),
15+
name: new RegExp(getEnglishText("i18n._global.sign_in"), "i"),
1616
}),
1717
signUpOption: parent.locator("#user-options").getByRole("menuitem", {
18-
name: new RegExp(getI18nString("i18n._global.sign_up"), "i"),
18+
name: new RegExp(getEnglishText("i18n._global.sign_up"), "i"),
1919
}),
2020
});

frontend/test-e2e/component-objects/ThemeMenu.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Locator, Page } from "playwright";
3-
import { getI18nString } from "~/utils/i18n";
3+
import { getEnglishText } from "~/utils/i18n";
44

55
export const newThemeMenu = (parent: Page | Locator) => ({
66
parent,
77
menu: parent.locator(".dropdown-theme").getByRole("menu"),
88
toggleOpenButton: parent.getByRole("button", {
99
name: new RegExp(
10-
getI18nString("i18n.components.dropdown_theme.open_dropdown_aria_label"),
10+
getEnglishText("i18n.components.dropdown_theme.open_dropdown_aria_label"),
1111
"i"
1212
),
1313
}),
1414

1515
systemThemeOption: parent.getByRole("menuitem", {
1616
name: new RegExp(
17-
getI18nString("i18n.components.dropdown_theme.system_aria_label"),
17+
getEnglishText("i18n.components.dropdown_theme.system_aria_label"),
1818
"i"
1919
),
2020
}),
2121

2222
lightThemeOption: parent.getByRole("menuitem", {
2323
name: new RegExp(
24-
getI18nString("i18n.components.dropdown_theme.light_aria_label"),
24+
getEnglishText("i18n.components.dropdown_theme.light_aria_label"),
2525
"i"
2626
),
2727
}),
2828

2929
darkThemeOption: parent.getByRole("menuitem", {
3030
name: new RegExp(
31-
getI18nString("i18n.components.dropdown_theme.dark_aria_label"),
31+
getEnglishText("i18n.components.dropdown_theme.dark_aria_label"),
3232
"i"
3333
),
3434
}),
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import type { Page } from "@playwright/test";
3-
import { getI18nString } from "~/utils/i18n";
3+
import { getEnglishText } from "~/utils/i18n";
44

55
export const newSignInPage = (page: Page) => ({
66
signUpLink: page.getByRole("link", {
7-
name: new RegExp(getI18nString("i18n._global.sign_up_aria_label"), "i"),
7+
name: new RegExp(getEnglishText("i18n._global.sign_up_aria_label"), "i"),
88
}),
99
usernameInput: page.locator("#sign-in-username input"),
1010
passwordInput: page.locator("#sign-in-password input"),
@@ -14,12 +14,12 @@ export const newSignInPage = (page: Page) => ({
1414
// Currently a button but should be a link
1515
forgotPasswordLink: page.getByRole("button", {
1616
name: new RegExp(
17-
getI18nString("i18n._global.auth.reset_password_forgot_password"),
17+
getEnglishText("i18n._global.auth.reset_password_forgot_password"),
1818
"i"
1919
),
2020
}),
2121

2222
signInButton: page.getByRole("button", {
23-
name: new RegExp(getI18nString("i18n._global.sign_in_aria_label"), "i"),
23+
name: new RegExp(getEnglishText("i18n._global.sign_in_aria_label"), "i"),
2424
}),
2525
});

frontend/test-e2e/specs/all/landing-page.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
import { expect, test } from "playwright/test";
3-
import { getI18nString } from "~/utils/i18n";
3+
import { getEnglishText } from "~/utils/i18n";
44

55
test.beforeEach(async ({ page }) => {
66
await page.goto("/en");
77
await expect(page.getByRole("heading", { level: 1 })).toHaveText(
8-
new RegExp(getI18nString("i18n.components.landing_splash.header"), "i")
8+
new RegExp(getEnglishText("i18n.components.landing_splash.header"), "i")
99
);
1010
});
1111

@@ -27,7 +27,7 @@ test.describe("Landing Page", { tag: ["@desktop", "@mobile"] }, () => {
2727
test("User can go to Organizations page", async ({ page }) => {
2828
const organizationsLink = page.getByRole("link", {
2929
name: new RegExp(
30-
getI18nString(
30+
getEnglishText(
3131
"i18n.components.landing_splash.view_organizations_aria_label"
3232
),
3333
"i"
@@ -41,7 +41,7 @@ test.describe("Landing Page", { tag: ["@desktop", "@mobile"] }, () => {
4141
test("User can go to Events page", async ({ page }) => {
4242
const eventsLink = page.getByRole("link", {
4343
name: new RegExp(
44-
getI18nString("i18n.components.landing_splash.view_events_aria_label"),
44+
getEnglishText("i18n.components.landing_splash.view_events_aria_label"),
4545
"i"
4646
),
4747
});
@@ -54,39 +54,39 @@ test.describe("Landing Page", { tag: ["@desktop", "@mobile"] }, () => {
5454
const links = [
5555
{
5656
name: new RegExp(
57-
getI18nString("i18n.pages.index.get_active_aria_label"),
57+
getEnglishText("i18n.pages.index.get_active_aria_label"),
5858
"i"
5959
),
6060
url: "https://docs.activist.org/activist",
6161
},
6262

6363
{
6464
name: new RegExp(
65-
getI18nString("i18n.pages.index.get_organized_aria_label"),
65+
getEnglishText("i18n.pages.index.get_organized_aria_label"),
6666
"i"
6767
),
6868
url: "https://docs.activist.org/activist",
6969
},
7070

7171
{
7272
name: new RegExp(
73-
getI18nString("i18n.pages.index.grow_organization_aria_label"),
73+
getEnglishText("i18n.pages.index.grow_organization_aria_label"),
7474
"i"
7575
),
7676
url: "https://docs.activist.org/activist",
7777
},
7878

7979
{
8080
name: new RegExp(
81-
getI18nString("i18n.pages.index.activist_section_btn_aria_label"),
81+
getEnglishText("i18n.pages.index.activist_section_btn_aria_label"),
8282
"i"
8383
),
8484
url: "https://docs.activist.org/activist",
8585
},
8686

8787
{
8888
name: new RegExp(
89-
getI18nString(
89+
getEnglishText(
9090
"i18n.pages.index.our_supporters_btn_become_aria_label"
9191
),
9292
"i"
@@ -96,7 +96,7 @@ test.describe("Landing Page", { tag: ["@desktop", "@mobile"] }, () => {
9696

9797
{
9898
name: new RegExp(
99-
getI18nString("i18n.pages.index.our_supporters_btn_view_aria_label"),
99+
getEnglishText("i18n.pages.index.our_supporters_btn_view_aria_label"),
100100
"i"
101101
),
102102
url: "https://docs.activist.org/activist/organization/community/supporters",

frontend/test-e2e/specs/desktop/landing-page.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { expectTheme } from "~/test-e2e/assertions";
1111
import { newLanguageMenu } from "~/test-e2e/component-objects/LanguageMenu";
1212
import { newThemeMenu } from "~/test-e2e/component-objects/ThemeMenu";
1313
import { newLandingPage } from "~/test-e2e/page-objects/LandingPage";
14-
import { getI18nString } from "~/utils/i18n";
14+
import { getEnglishText } from "~/utils/i18n";
1515

1616
test.beforeEach(async ({ page }) => {
1717
await page.goto("/en");
1818
await expect(page.getByRole("heading", { level: 1 })).toHaveText(
19-
new RegExp(getI18nString("i18n.components.landing_splash.header"), "i")
19+
new RegExp(getEnglishText("i18n.components.landing_splash.header"), "i")
2020
);
2121
});
2222

frontend/test-e2e/specs/mobile/landing-page.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { newSidebarRight } from "~/test-e2e/component-objects/SidebarRight";
99
import { newSignInMenu } from "~/test-e2e/component-objects/SignInMenu";
1010
import { newThemeMenu } from "~/test-e2e/component-objects/ThemeMenu";
1111
import { newLandingPage } from "~/test-e2e/page-objects/LandingPage";
12-
import { getI18nString } from "~/utils/i18n";
12+
import { getEnglishText } from "~/utils/i18n";
1313

1414
test.beforeEach(async ({ page }) => {
1515
await page.goto("/en");
1616
await expect(page.getByRole("heading", { level: 1 })).toHaveText(
17-
new RegExp(getI18nString("i18n.components.landing_splash.header"), "i")
17+
new RegExp(getEnglishText("i18n.components.landing_splash.header"), "i")
1818
);
1919
});
2020

frontend/utils/i18n.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const localeFiles: Record<LOCALE_CODE, LocaleFile> = {
1717
};
1818

1919
export function getLocaleText(locale?: LOCALE_CODE): LocaleFile {
20-
return localeFiles[locale || LOCALE_CODE.ENGLISH];
20+
return localeFiles[locale ?? LOCALE_CODE.ENGLISH];
2121
}
2222

23-
export const getI18nString = (key: string) => {
23+
export const getEnglishText = (key: string) => {
2424
return getLocaleText(LOCALE_CODE.ENGLISH)[key];
2525
};

0 commit comments

Comments
 (0)