Open 0xGeegZ opened 10 months ago
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
[X] src/components/landing/hero/hero.tsx
✅ Commit b0b7815
Modify src/components/landing/hero/hero.tsx with contents:
• Import the `useTranslations` hook from `next-intl` at the top of the file.
• Use the `useTranslations` hook to get translations for the `hero` namespace. Assign the returned translation function to a variable, e.g., `const t = useTranslations("hero")`.
• Replace all hardcoded text strings in the component with calls to the translation function `t`, passing the appropriate key as an argument. For example, replace `"AI-Driven Micro-SaaS for"` with `{t("aiDrivenMicroSaas")}`.
• Add the English translations for all the keys used in the `hero` namespace to the `src/i18n/messages/en.json` file.
[X] src/components/landing/partners/technologies.tsx
✅ Commit 76098a0
Modify src/components/landing/partners/technologies.tsx with contents:
• Import the `useTranslations` hook from `next-intl` at the top of the file.
• Use the `useTranslations` hook to get translations for the `technologies` namespace. Assign the returned translation function to a variable, e.g., `const t = useTranslations("technologies")`.
• Replace all hardcoded text strings in the component with calls to the translation function `t`, passing the appropriate key as an argument. For example, replace `"This project was built using the following technologies"` with `{t("builtUsingTechnologies")}`.
• Add the English translations for all the keys used in the `technologies` namespace to the `src/i18n/messages/en.json` file.
[X] src/components/landing/testimonials/testimonial-highlight.tsx
✅ Commit de648bf
Modify src/components/landing/testimonials/testimonial-highlight.tsx with contents:
• Import the `useTranslations` hook from `next-intl` at the top of the file.
• Use the `useTranslations` hook to get translations for the `testimonialHighlight` namespace. Assign the returned translation function to a variable, e.g., `const t = useTranslations("testimonialHighlight")`.
• Replace all hardcoded text strings in the component with calls to the translation function `t`, passing the appropriate key as an argument. For example, replace `"What people are saying"` with `{t("peopleSaying")}`.
• Add the English translations for all the keys used in the `testimonialHighlight` namespace to the `src/i18n/messages/en.json` file.
[X] src/components/landing/features/column/feature-sections.tsx
✅ Commit 95af774
Modify src/components/landing/features/column/feature-sections.tsx with contents:
• Import the `useTranslations` hook from `next-intl` at the top of the file.
• Use the `useTranslations` hook to get translations for the `featureSections` namespace. Assign the returned translation function to a variable, e.g., `const t = useTranslations("featureSections")`.
• Replace all hardcoded text strings in the component with calls to the translation function `t`, passing the appropriate key as an argument. For example, replace `"AI Feature 1"` with `{t("aiFeature1")}`.
• Add the English translations for all the keys used in the `featureSections` namespace to the `src/i18n/messages/en.json` file.
Here are my self-reviews of my changes at sweep/application-translation
.
Here is the 1st review
Thank you for your work on this pull request. The changes in `src/components/landing/features/column/feature-sections.tsx` and `src/components/landing/partners/technologies.tsx` are correct and in line with the issue requirements. However, there are a few areas that need to be addressed: - In `src/components/landing/hero/hero.tsx`, the `useTranslations` hook from `next-intl` is imported correctly, but the hardcoded text strings in the component are not replaced with calls to the translation function `t`. Please replace all hardcoded text strings in this component with calls to `t`, passing the appropriate key as an argument. - Similarly, in `src/components/landing/testimonials/testimonial-highlight.tsx`, the `useTranslations` hook is imported correctly, but the hardcoded text strings in the component are not replaced with calls to the translation function `t`. Please replace all hardcoded text strings in this component with calls to `t`, passing the appropriate key as an argument. - Lastly, please add the English translations for all the keys used in the `hero`, `technologies`, `testimonialHighlight`, and `featureSections` namespaces to the `src/i18n/messages/en.json` file. The changes in this file are not provided in the diff. Please make these changes and update the pull request. If you have any questions, feel free to ask.
I finished incorporating these changes.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord
Issue: Application Translation - Next.js TypeScript Application Translation using next-intl
Objective
The goal of this issue is to translate specific components in our Next.js application using the
next-intl
package.Files to translate:
Expected Behavior
Once the translation is implemented successfully, the application should display the content of the mentioned components in the user's preferred language, as specified in the
i18n
configuration.Actual Behavior
Currently, the components are only displaying content in the default language (English).
How to Solve
Step 1: Understand the Translation Files Structure
The English translations for the application are located in
src/i18n/messages/en.json
. You will insert the English translations for the components here. Each file should have its own namespace.For example, for
stats.tsx
component, you must have a namespace such as"stats": {}
in theen.json
file.Step 2: Determine if the Component is a Client Component or a Server Component
Client Component:
use client
instruction at the top of the file.async
function.export function StarterPacksTestimonials() {}
Server Component:
use client
instruction at the top of the file.async
function.export default async function StarterPacksPage() {}
Step 3: Implement the Translation
The implementation of the translation depends on whether the component is a client component or a server component. The changes you need to make in each component are:
next-intl
in the right way (depending if it's a client or server component).next-intl
package.src/i18n/messages/en.json
file.Let's take a look at some examples based on the files you provided.
Example 1: Server Component (
StaterPacksPage
)In this case, we are using the
getTranslations
function fromnext-intl/server
.In the above code snippet, we've imported the
getTranslations
function fromnext-intl/server
as this is a server component. We then use thegetTranslations
function to get translations for thestarterPack
namespace. The translation functiont
is then used to replace hardcoded strings. For example,{t("heroTitle")}
will get the translated text for theheroTitle
key in thestarterPack
namespace fromen.json
.Example 2: Client Component (
StarterPacksTestimonials
)In this case, we are using the
useTranslations
hook fromnext-intl
.In the above code snippet, we've imported the
useTranslations
hook fromnext-intl
as this is a client component. We then use theuseTranslations
hook to get translations for thetestimonials
namespace. The translation functiont
is then used to replace hardcoded strings. For example,{t("heroTitle")}
will get the translated text for theheroTitle
key in thetestimonials
namespace fromen.json
. For a detailed guide on how to implement translations in client components and server components, refer to the following resources:Step 4: Review Example Files
You have to refer to the following files that have already been translated to understand how to apply translations, so check them carefully:
-
You must use these examples to apply the translation in the same way and be sure to manage Server Component and Client Component in the correct manner.
And do not forget to add translation for each component in the
src/i18n/messages/en.json
file, this is critical so your pull request have to include en.json file with new translations.Summary
By following these steps, you should be able to successfully translate the necessary components and enhance our application's internationalization. Remember to replace the hardcoded text strings with translation function calls from the
next-intl
package and to add the appropriate namespace to the translation function calls.Please, set the same title for your pull request as the issue title. And please, add comments only if it helps to understand your code.
If you encounter any issues or have any questions, feel free to ask for help. Happy coding!
Checklist
- [X] ``src/components/landing/hero/hero.tsx`` ✅ Commitb0b7815
- [X] ``src/components/landing/partners/technologies.tsx`` ✅ Commit76098a0
- [X] ``src/components/landing/testimonials/testimonial-highlight.tsx`` ✅ Commitde648bf
- [X] ``src/components/landing/features/column/feature-sections.tsx`` ✅ Commit95af774
![Flowchart](https://raw.githubusercontent.com/0xGeegZ/ai-micro-saas-starter/sweep/assets/5123647a01f460146f9cfed7256a88d3f56616994ac16981e64cb4d6f035fe30_12_flowchart.svg)