Home Web Front-end JS Tutorial I have localized the best short-linking platform in the world

I have localized the best short-linking platform in the world

Nov 07, 2024 am 06:33 AM

As part of playing with Tolgee, I have tried translating dub.co, a well-established open-source company, into other languages! It took me 1 hour, and the results are astonishing!

I have localized the best short-linking platform in the world


In this tutorial, I’ll walk you through an easy and efficient approach to localization in a Next.js application using Tolgee - a platform designed for fast and autonomous translation management.

You will also learn how to integrate Tolgee with Dub.co, a popular link management platform allowing users to access and interact with the application in their preferred languages.

Prerequisites

To fully understand this tutorial, you need to have a basic understanding of React or Next.js.

You will also need to set up the following:

  • Tolgee Project - an existing project with at least two language translations.
  • Tolgee CLI - allows you to interact with the Tolgee platform from your computer using the command line.
  • Docker - required for running Dub.co. It is an open-source platform that uses containerization to make it easier to create, deploy, and run applications.
  • Docker Compose - a software application for defining and running multi-container Docker applications.
  • Python (version 3.8 or higher): necessary for configuring some of Dub.co’s packages.

What is Tolgee?

Tolgee is a developer-friendly localization platform that allows you to translate your application into any language without modifying your code. It is designed for web applications but also supports mobile and desktop applications.

With Tolgee, you don't need to look for keys in your source code, edit localization files, or perform manual exporting data for translators. Tolgee offers in-context translation, a translation memory for keeping track of already translated strings, machine and auto translations, and many others.

I have localized the best short-linking platform in the world

Please help us with a star. ?

It would help us to create more articles like this ?

Star the Tolgee repository ⭐


How to set up Dub.co on your local computer

Dub.co is an open-source link management platform that allows marketing teams to add powerful analytics to their links, create short links, generate QR codes for links, and many more. It was created by Steven Tey (formerly of Vercel).

Follow these steps to set up Dub.co on your computer:

Clone the Dub.co GitHub repository by running the code snippet below.

git clone https://github.com/dubinc/dub.git
Copy after login
Copy after login
Copy after login
Copy after login

Navigate into the dub folder and install the project dependencies:

git clone https://github.com/dubinc/dub.git
Copy after login
Copy after login
Copy after login
Copy after login

Within the apps/web folder, rename the .env.example file to .env.

Create a new Tinybird account, and copy your Admin Auth Token into the .env file.

pnpm install
Copy after login
Copy after login
Copy after login

Navigate into the packages/tinybird directory and install the Tinybird CLI using the following command:

TINYBIRD_API_KEY=<your_admin_auth_token>
Copy after login
Copy after login
Copy after login

Execute the following command in your terminal and enter your Admin Auth Token when prompted to authenticate using the Tinybird CLI:

pip3 install tinybird-cli
Copy after login
Copy after login
Copy after login

Publish the Tinybird datasource and endpoints by running the code snippet below:

tb auth
Copy after login
Copy after login
Copy after login

Create an Upstash database and copy the following credentials from the REST API section to the .env file:

tb push
Copy after login
Copy after login
Copy after login

Navigate to the QStash tab and copy the following credentials into the .env file.

UPSTASH_REDIS_REST_URL=<your_rest_url>
UPSTASH_REDIS_REST_TOKEN=<your_rest_token>
Copy after login

Next, within the apps/web directory, run the following command to start the Docker Compose stack:

QSTASH_TOKEN=
QSTASH_CURRENT_SIGNING_KEY=
QSTASH_NEXT_SIGNING_KEY=
Copy after login

Generate the Prisma client and create its database tables using the following commands:

docker-compose up
Copy after login

Dub.co supports multiple authentication methods. Create a GitHub app and copy the URL below as its callback URL.

npx prisma generate
npx prisma db push
Copy after login

Finally, start the development server:

http://localhost:8888/api/auth/callback/github
Copy after login

You can access the web application by navigating to http://localhost:8888 in your browser, create a workspace, and get started. If you encounter any issues, refer to the complete installation guide for more detailed assistance.

I have localized the best short-linking platform in the world


How to configure Tolgee in a Next.js application

In this section, you'll learn how to add Tolgee to a Next.js application and configure it to support multiple languages, allowing users to access the app in their preferred language.

To implement localization in Next.js applications, you will need to install the Tolgee React SDK.

pnpm dev
Copy after login

Next, create a Tolgee Platform account and sign into your dashboard.

I have localized the best short-linking platform in the world

Add a new project by clicking the Project button and selecting your preferred languages for the project. For this application, we'll use five languages: English (as the base language), Chinese, Hindi, Spanish, and Arabic.

I have localized the best short-linking platform in the world

Click the profile icon in the top-right corner of your dashboard, then select Project API Keys to create an API key for your Tolgee project.

I have localized the best short-linking platform in the world

Create a .env.development.local and copy your API key into the file:

git clone https://github.com/dubinc/dub.git
Copy after login
Copy after login
Copy after login
Copy after login

Select Translations from the sidebar menu and add a new translation to the project.

I have localized the best short-linking platform in the world

You can create a translation key, add the content or string you need to translate, provide a description, and then save it.

I have localized the best short-linking platform in the world

Tolgee provides various machine translation options by default, allowing you to easily translate content into the available languages within your project.

I have localized the best short-linking platform in the world

Congratulations! You’ve successfully set up the Tolgee platform for translations within your application. Next, let’s configure Tolgee within the Dub.co project to easily generate translations directly in the application.

How to set up localization in Dub.co

In this section, I’ll guide you through configuring Tolgee to support client-server interactions within the Dub.co project.

First, install the Tolgee CLI package.

pnpm install
Copy after login
Copy after login
Copy after login

Run the following code snippet to sign into your Tolgee platform using your project API key.

TINYBIRD_API_KEY=<your_admin_auth_token>
Copy after login
Copy after login
Copy after login

I have localized the best short-linking platform in the world

Next, create an i18n folder within the apps/web directory. This folder will store the JSON files containing translations for the various languages available in the Tolgee platform project.

pip3 install tinybird-cli
Copy after login
Copy after login
Copy after login

Within the apps/web directory, fetch the language translations created in your Tolgee project by running the code snippet below:

tb auth
Copy after login
Copy after login
Copy after login

I have localized the best short-linking platform in the world

The code snippet above automatically populates the i18n folder with the various language translations created within the Tolgee platform.

tb push
Copy after login
Copy after login
Copy after login

Create a tolgee folder which will contain Tolgee configurations within the apps/web directory:

git clone https://github.com/dubinc/dub.git
Copy after login
Copy after login
Copy after login
Copy after login

Add a shared.ts file in the tolgee directory, then copy the following code snippet into the file:

pnpm install
Copy after login
Copy after login
Copy after login

The code snippet above configures Tolgee with default and fallback languages to enable localization within the application.

Next, create a client.tsx file in the tolgee directory, then copy the code snippet below into the file:

TINYBIRD_API_KEY=<your_admin_auth_token>
Copy after login
Copy after login
Copy after login

The client.tsx file serves the purpose of translating client components and also enables the in-context functionality for server-rendered components. The code snippet above defines the TolgeeNextProvider component, which wraps the entire Dub.co application, providing configurations needed to manage language changes and translations.

Create a custom locale.ts file in the tolgee folder and copy the following code snippet into it:

pip3 install tinybird-cli
Copy after login
Copy after login
Copy after login

Finally, create a server.tsx file in the tolgee folder, then copy the following code snippet into the file:

tb auth
Copy after login
Copy after login
Copy after login

The application utilizes the React server cache for sharing Tolgee instance across components in a single render. This allows the app to use the Tolgee instance anywhere in the server components.

Congratulations! You’ve successfully configured Tolgee and are now ready to start adding translations to various content within the application.


How to translate your application content with Tolgee

Here, you'll learn how to translate content within your web application and see how Tolgee enables easy in-app translation.

To get started, you need to wrap the entire Dub.co application with the TolgeeNextProvider component, defined in tolgee/client.tsx. Navigate to the apps/web/app folder, then go to the app.dub.co/(dashboard) directory, and update the layout.tsx file as shown below:

tb push
Copy after login
Copy after login
Copy after login

The code snippet above wraps the dashboard routes with the Tolgee provider, enabling language switching and localization throughout the application.

Tolgee provides two hooks to help you select and translate text within your application: useTolgee and useTranslate.

  • The useTolgee hook returns the Tolgee instance, allowing you to subscribe to various events that will trigger re-renders when translating text.
  • The useTranslate hook includes a translation function (t function) that renders the actual translations directly within the app.

Update the page.tsx file in the app.dub.co/(dashboard)/[slug] directory by adding the following code snippet:

"use client";
import { PageContent } from "@/ui/layout/page-content";
import WorkspaceLinksClient from "./page-client";
//?? Tolgee installations
import { useTolgee, useTranslate } from "@tolgee/react";
import { setUserLocale } from "tolgee/locale";


export default function WorkspaceLinks() {
  const { t } = useTranslate();
  const tolgee = useTolgee(["pendingLanguage"]);
  const language = tolgee.getPendingLanguage();

  return (
    <PageContent title="Links">
    {/**-- HTML input for selecting the preferred language --*/}
      <div className="flex w-full flex-col px-10">
        <p>Select Language</p>
        <select
          defaultValue={language}
          className="rounded-sm"
          name="locale"
         >



<p>The code snippet above displays an HTML <strong><select> tag that allows users to choose and switch between different languages. The <strong>{t("hello")}</strong> element uses Tolgee’s translation function to render a value of the "hello" key based on the selected language.

<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173093241088271.jpg" class="lazy" alt="I have localized the best short-linking platform in the world"></p>

<p>Finally, you can update the remaining content throughout the application to support language changes, allowing users to view all components in their selected language.</p>

<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173093241165470.jpg" class="lazy" alt="I have localized the best short-linking platform in the world"></p>

<p>Tolgee also provides an in-context translation feature, allowing you to translate strings directly within your application, whether in development or production, simply by clicking the text and holding the Alt or Option key.</p>

<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173093241362494.jpg" class="lazy" alt="I have localized the best short-linking platform in the world"></p>

<p>Congratulations! You've successfully completed the project for this tutorial.</p>

<p>The source code for this tutorial is available here:</p>

<p>https://github.com/JanCizmar/dub-with-tolgee</p>


<hr>

<h2>
  
  
  Conclusion
</h2>

<p>So far, you’ve learnt how to add localization to your software applications using Tolgee, implement support for multiple languages, and make language switching seamless within a real-world project.</p>

<p>Tolgee is a fast, developer-focused localization platform that allows you to provide context to your content and generate translations in seconds. It also supports multiple JavaScript frameworks, including Vue, Angular, and Svelte, and integrates with tools like Figma and a REST API for flexibility.</p>

<p>If you're looking to create a personalized experience for your users, Tolgee is an excellent choice. Feel free to contribute and star our GitHub repository, and join our Slack community to connect with others and engage with the team.</p><p>Thank you for reading!</p>


          

            
        
Copy after login

The above is the detailed content of I have localized the best short-linking platform in the world. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

How to implement panel drag and drop adjustment function similar to VSCode in front-end development? How to implement panel drag and drop adjustment function similar to VSCode in front-end development? Apr 04, 2025 pm 02:06 PM

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...

See all articles