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

feat: Add t.has to check whether a given message exists #1399

Merged
merged 5 commits into from
Oct 9, 2024

Conversation

tholander
Copy link
Contributor

@tholander tholander commented Oct 3, 2024

import {useTranslations} from 'next-intl';

function AboutPage() {
  const t = useTranslations('AboutPage');

  if (!t.has('title')) {
    notFound()
  }

  // ...
}

Closes #88

Copy link

vercel bot commented Oct 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 8:05am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 8:05am
next-intl-example-app-router-without-i18n-routing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 8:05am

Copy link

vercel bot commented Oct 3, 2024

Someone is attempting to deploy a commit to the next-intl Team on Vercel.

A member of the Team first needs to authorize it.

 - E2E test
 - Tests for type safety
 - Bump size
 - Expose on `getTranslations`
 - Refactor `craeteBaseTranslator` slightly to reduce bundle size
@amannn amannn changed the title feat: add optional message check function feat: Add t.has for checking whether a message exists for the current locale Oct 8, 2024
Copy link
Owner

@amannn amannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tholander This looks fantastic, thanks a lot for taking the initiative on this! 💯

During the review I've added a commit to add a few more tests, hope that's ok for you.

I'll do another review tomorrow, but I think this is good to go!

…slations

# Conflicts:
#	examples/example-app-router-playground/src/components/AsyncComponent.tsx
@amannn amannn changed the title feat: Add t.has for checking whether a message exists for the current locale feat: Add t.has to check whether a given message exists Oct 9, 2024
@amannn amannn merged commit ee1a2a9 into amannn:main Oct 9, 2024
8 checks passed
@blazingh
Copy link

thanks a lot for this.

juanforlizzi pushed a commit to juanforlizzi/next-intl that referenced this pull request Jan 16, 2025

Co-authored-by: Théo Holander <theo.holander@reflet-digital.com>
Co-authored-by: Jan Amann <jan@amann.work>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional translations
3 participants