Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add t, useTranslation helpers to use translations #395

Merged
merged 7 commits into from
Jul 5, 2024

Conversation

sidvishnoi
Copy link
Member

@sidvishnoi sidvishnoi commented Jul 5, 2024

Context

Making translations easier to use.

Changes proposed in this pull request

Adds following helpers:

  • t(key, optionalSubsitutions) added to background container
    • as a shorter call over this.browser.i18n.getMessage(key, optionalSubsitutions),
    • where TypeScript ensures key exists in _locales
  • For popup, a const t = useTranslation() helper.
  • In popup, reduces place where we need to import browser from 'webextension-polyfill', make it easier to test. The context default just returns passed key as is.

@github-actions github-actions bot added area: background Improvements or additions to extension background script area: popup Improvements or additions to extension popup labels Jul 5, 2024
@raducristianpopa
Copy link
Member

raducristianpopa commented Jul 5, 2024

Extension builds preview

Name Link
Latest commit 20b069e
Latest job logs Run #9809767084
BadgeDownload
BadgeDownload

@sidvishnoi
Copy link
Member Author

I'll add a useBrowser hook next for browser in popup, so we can pass a mock browser for testing easily.

src/background/services/tabEvents.ts Outdated Show resolved Hide resolved
src/shared/helpers.ts Outdated Show resolved Hide resolved
src/shared/helpers.ts Outdated Show resolved Hide resolved
@raducristianpopa
Copy link
Member

I'll add a useBrowser hook next for browser in popup, so we can pass a mock browser for testing easily.

Let's do this in this PR as well.

@sidvishnoi
Copy link
Member Author

Let's do this in this PR as well.

I'll send a follow-up. Keeping this PR focused on translations.

src/shared/helpers.ts Outdated Show resolved Hide resolved
src/background/container.ts Outdated Show resolved Hide resolved
src/background/container.ts Outdated Show resolved Hide resolved
src/background/services/tabEvents.ts Outdated Show resolved Hide resolved
src/background/services/tabEvents.ts Outdated Show resolved Hide resolved
src/popup/lib/context.tsx Outdated Show resolved Hide resolved
sidvishnoi and others added 2 commits July 5, 2024 19:50
Co-authored-by: Radu-Cristian Popa <radu.popa@breakpointit.eu>
@sidvishnoi sidvishnoi merged commit 7f7d678 into main Jul 5, 2024
8 checks passed
@sidvishnoi sidvishnoi deleted the translation-helpers branch July 5, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: background Improvements or additions to extension background script area: popup Improvements or additions to extension popup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants