Speedrun Next.js
Let's speedrun creating a new app and internationalizing it with GT.
Overview
In this guide, we'll go over two things:
- Creating a new Next.js app
- Internationalizing it with General Translation
In total, this should take less than 10 minutes.
Prerequisites
We assume that you either have experience using React in some capacity and are familiar with Typescript.
Step 1: Create a new Next.js app
First, navigate to the directory of your choice in terminal and run the following command:
A set up wizard will appear, you can just select the default value for each option.
Step 2: Install the libraries
Navigate to your Next.js project's root directory and run:
Step 3: Add your environment variables.
Navigate to your GT Dashboard.
Go to the Dev Api Keys page on the nav bar and create a new API key and Project ID.
Then add them to your .env
file.
Step 4: Run the CLI tool
Run the CLI tool to setup your codebase for translation.
Step 5: Modify the root layout
Modify the lang
prop in the <html>
tag in the src/app/layout.tsx
file.
It should use await getLocale()
to get the current locale.
Step 6: Start your app
Your app is internationalized! 🎉 Let's test it!
Let's change your browser's language settings.
Start your Next.js app.
Open up your app in your preferred browser (usually at http://localhost:3000). If you have set up everything correctly, you should see your app in the language you set in your browser.
Troubleshooting
Notes
- Translate arbitrary jsx with the
<T>
component. - If translation is not working when you change your language, check your browser's cookies.
Next steps
- Star our GitHub repo gt-next.
- Set up Right to Left language support.
- Try a more advanced example.