Skip to content

Commit

Permalink
feat: add i18n support for the matching rules section
Browse files Browse the repository at this point in the history
  • Loading branch information
aug-dev committed Aug 10, 2024
1 parent 6556524 commit 92d6f3e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/_locales/en/messages.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default exportAsMessages({
// The text of an OK button.
okButton: "OK",

// The text that represents the user's own personal blocklist.
personalBlocklist: "Personal Blocklist",

// The text that means one site has been blocked.
content_singleSiteBlocked: "uBlacklist has blocked 1 site",

Expand Down Expand Up @@ -89,6 +92,18 @@ export default exportAsMessages({
// The text of the button to activate this extension.
popup_activateButton: "Activate",

// The title of the disclosure widget that contains the matching rules information.
popup_matchingRules: "Matching Rules",

// The label for the textarea that shows rules blocking the entry.
popup_blockingRulesLabel: "Rules blocking this entry",

// The label for the textarea that shows rules unblocking the entry.
popup_unblockingRulesLabel: "Rules unblocking this entry",

// The label for the textarea that shows rules highlighting the entry.
popup_highlightingRulesLabel: "Rules highlighting this entry",

// The title of the general section.
options_generalTitle: "General",

Expand Down
5 changes: 5 additions & 0 deletions src/common/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type MessageName =
| "unauthorizedError"
| "cancelButton"
| "okButton"
| "personalBlocklist"
| "content_singleSiteBlocked"
| "content_multipleSitesBlocked"
| "content_showBlockedSitesLink"
Expand All @@ -27,6 +28,10 @@ export type MessageName =
| "popup_active"
| "popup_inactive"
| "popup_activateButton"
| "popup_matchingRules"
| "popup_blockingRulesLabel"
| "popup_unblockingRulesLabel"
| "popup_highlightingRulesLabel"
| "options_generalTitle"
| "options_blacklistLabel"
| "options_blacklistHelper"
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/block-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ const BlockDialogContent: React.FC<BlockDialogContentProps> = ({
}}
>
<DetailsSummary className={FOCUS_START_CLASS}>
Matching Rules
{translate("popup_matchingRules")}
</DetailsSummary>
<DetailsBody>
<Row>
<RowItem expanded>
<LabelWrapper fullWidth>
<ControlLabel for="blocking-rules-text">
Rules blocking this entry:
{translate("popup_blockingRulesLabel")}
</ControlLabel>
</LabelWrapper>
{state.matchingRulesOpen && (
Expand All @@ -318,7 +318,7 @@ const BlockDialogContent: React.FC<BlockDialogContentProps> = ({
<RowItem expanded>
<LabelWrapper fullWidth>
<ControlLabel for="unblocking-rules-text">
Rules unblocking this entry:
{translate("popup_unblockingRulesLabel")}
</ControlLabel>
</LabelWrapper>
{state.matchingRulesOpen && (
Expand All @@ -339,7 +339,7 @@ const BlockDialogContent: React.FC<BlockDialogContentProps> = ({
<RowItem expanded>
<LabelWrapper fullWidth>
<ControlLabel for="highlight-rules-text">
Rules highlighting this entry:
{translate("popup_highlightingRulesLabel")}
</ControlLabel>
</LabelWrapper>
{state.matchingRulesOpen && (
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/interactive-ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class InteractiveRuleset {
// Get rules from user's personal blacklist
// Note: I need to internationalize this string later with translate() !!
const matches = getMatchesPerRuleset(
"personal-blacklist",
"personal-blocklist",
this.userRuleset,
props,
);
Expand Down Expand Up @@ -345,7 +345,7 @@ function getMatchesPerRuleset(
// "Block this website" button.
// This ensures the line numbers are accurate without reloading.
const rulesetLines =
rulesetName === "personal-blacklist" ? [...ruleset] : null;
rulesetName === "personal-blocklist" ? [...ruleset] : null;
const previousMatchIndexes = new Map<string, number>();

for (let { lineNumber, specifier } of rawResults) {
Expand Down
7 changes: 6 additions & 1 deletion src/scripts/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dayjs from "dayjs";
import type { InteractiveRuleset } from "./interactive-ruleset.ts";
import { translate } from "./locales.ts";
import {
type LinkProps,
Ruleset,
Expand Down Expand Up @@ -180,7 +181,11 @@ export function getMatchingRulesText(
// Check whether the ruleset contains rules of the current rule type
if (match[ruleType].length === 0) continue;
// Add header with ruleset name
matchingRulesText[ruleType] += `# ${match.rulesetName}\n`;
const headerContent =
match.rulesetName === "personal-blocklist"
? translate("personalBlocklist")
: match.rulesetName;
matchingRulesText[ruleType] += `# ${headerContent}\n`;
// Add individual rules
matchingRulesText[ruleType] += match[ruleType]
.map(({ lineContent, lineNumber }) => {
Expand Down

0 comments on commit 92d6f3e

Please sign in to comment.