<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: yanafeshchuk</title>
    <description>The latest articles on DEV Community by yanafeshchuk (@yanafeshchuk).</description>
    <link>https://dev.to/yanafeshchuk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1116958%2F55f25231-72b4-4ffb-a68a-d8b36d860139.png</url>
      <title>DEV Community: yanafeshchuk</title>
      <link>https://dev.to/yanafeshchuk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yanafeshchuk"/>
    <language>en</language>
    <item>
      <title>Astro Websites Localization and Internalization</title>
      <dc:creator>yanafeshchuk</dc:creator>
      <pubDate>Wed, 12 Jul 2023 09:21:21 +0000</pubDate>
      <link>https://dev.to/crowdin/astro-websites-localization-and-internalization-3cl0</link>
      <guid>https://dev.to/crowdin/astro-websites-localization-and-internalization-3cl0</guid>
      <description>&lt;p&gt;In this article, you will learn the basics of Astro localization, so you can make your website multilingual to reach new markets. We’ll discuss i18n and localization best practices that will ensure that you can adapt an application to meet the cultural, language, and other requirements of a country or region you’re targeting.&lt;/p&gt;

&lt;p&gt;Integrating your localization software with an Astro-based website is an important step to automating the localization process.&lt;/p&gt;

&lt;p&gt;Let’s start with a walk-through on how to set up language sub-paths and connect &lt;a href="https://crowdin.com/"&gt;Crowdin&lt;/a&gt; to your Astro project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Astro localization
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we will use Crowdin to translate an English Astro website into French and Spanish.&lt;/p&gt;

&lt;p&gt;Let’s see how we can initiate our project in Crowdin. Typically, you would follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign up for a Crowdin or Crowdin Enterprise account and create a project.&lt;/li&gt;
&lt;li&gt;Add the project name, source language, visibility and target languages. In our case, we’ll have English as the source language and French and Spanish as the target languages.&lt;/li&gt;
&lt;li&gt;Upload the content you want to translate, such as documents, strings, or multimedia files.&lt;/li&gt;
&lt;li&gt;Define your target languages and invite translators to join your project.&lt;/li&gt;
&lt;li&gt;Translators can access and translate the content directly in the Crowdin Editor, using built-in translation tools such as translation memory and glossary management.&lt;/li&gt;
&lt;li&gt;Proofreaders can review the translated content and provide feedback or approve it.&lt;/li&gt;
&lt;li&gt;Once translations are completed, you can download the translated files and use them in your website.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Astro Site Preparation
&lt;/h2&gt;

&lt;p&gt;Astro is a comprehensive web development tool for building fast websites focusing on content.&lt;br&gt;
Let’s initialize a new Astro site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# create a new project with npm&lt;/span&gt;
npm create astro@latest

&lt;span class="c"&gt;# create a new project with pnpm&lt;/span&gt;
pnpm create astro@latest

&lt;span class="c"&gt;# create a new project with yarn&lt;/span&gt;
yarn create astro
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will prompt you to enter a project name and select a template. For this tutorial, we’ll use the &lt;code&gt;blog&lt;/code&gt; template and TypeScript as the language.&lt;/p&gt;

&lt;p&gt;Then, organize your translations within the &lt;a href="https://docs.astro.build/en/reference/configuration-reference/#publicdir"&gt;Astro’s publicDir&lt;/a&gt;, in the &lt;code&gt;locales&lt;/code&gt; directory. In the example below, we show a simple use case of implementing language sub-paths in Astro using a JSON files to store translations. We will work with three languages, en, fr, and es. In this case, you might have the following locale structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public
└── locales
    ├── en
    |   └── translation.json
    └── fr
    |   └── translation.json
    └── es
        └── translation.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The translation files will have the following structure:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;public/locales/en/translation.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.home"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Home"&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.blog"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.about"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"About"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;public/locales/fr/translation.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.home"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Page d'Accueil"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.blog"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Blogue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.about"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"À propos de"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;public/locales/es/translation.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.home"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Página Principal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.blog"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nav.about"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Acerca de"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can be either a plain or nested JSON file depending on your needs. The filename should be the same for all languages. The only difference is the language code in the path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crowdin CLI Configuration
&lt;/h2&gt;

&lt;p&gt;In Astro, you can incorporate &lt;a href="https://crowdin.github.io/crowdin-cli/"&gt;Crowdin CLI&lt;/a&gt; in your project to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automate the process of updating your source files in your Crowdin project&lt;/li&gt;
&lt;li&gt;Download translations from Crowdin and automatically save them in the correct locations&lt;/li&gt;
&lt;li&gt;Upload all your existing translations to Crowdin in minutes
The easiest way to install the Crowdin CLI is to use npm:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @crowdin/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit the &lt;a href="https://crowdin.github.io/crowdin-cli/installation"&gt;official CLI documentation&lt;/a&gt; to explore other installation options.&lt;/p&gt;

&lt;p&gt;To configure Crowdin CLI in your project, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;crowdin init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll be prompted to enter your Crowdin Project ID and your Personal Access Token. It will generate the &lt;code&gt;crowdin.yml&lt;/code&gt; file in the root directory of your project.&lt;/p&gt;

&lt;p&gt;To set up the Crowdin CLI for your Astro project, you need to add the following configuration to the &lt;code&gt;crowdin.yml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;project_id"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;project-id"&lt;/span&gt;
&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;api_token"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;personal-access-token"&lt;/span&gt;

&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;base_path"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;."&lt;/span&gt;
&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;preserve_hierarchy"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;base_url"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.crowdin.com"&lt;/span&gt; &lt;span class="c1"&gt;# https://{organization-name}.api.crowdin.com for Crowdin Enterprise&lt;/span&gt;

&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;files"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;
  &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source"&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/public/locales/en/translation.json"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Source language file pattern&lt;/span&gt;
    &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;translation"&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/public/locales/%two_letters_code%/translation.json"&lt;/span&gt;  &lt;span class="c1"&gt;# Translation files pattern&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s recommended to use &lt;a href="https://developer.crowdin.com/configuration-file/#api-credentials-from-environment-variables"&gt;environment variables&lt;/a&gt; for referencing the token in your &lt;code&gt;crowdin.yml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;project_id_env"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CROWDIN_PROJECT_ID"&lt;/span&gt;
&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;api_token_env"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CROWDIN_PERSONAL_TOKEN"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  VCS (Git) Integrations
&lt;/h2&gt;

&lt;p&gt;Crowdin provides VCS (version control systems) integrations for different platforms including GitHub, GitLab, Bitbucket, Azure Repos and other platforms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: supports various GitHub workflows, such as pull request and push notifications, branch updates, and automatic commits.&lt;/li&gt;
&lt;li&gt;GitLab: allows you to synchronize your source and translation files with your GitLab repository, as well as manage your project languages and track the translation progress.&lt;/li&gt;
&lt;li&gt;Bitbucket: allow you to automate updating your source and translation files with your Bitbucket repository.&lt;/li&gt;
&lt;li&gt;Azure Repos: allows you to synchronize your source and translation files with your Azure Repos repository&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also use the &lt;a href="https://github.com/marketplace/actions/crowdin-action"&gt;Crowdin GitHub Action&lt;/a&gt; to automatically manage and synchronize localization resources with your Crowdin project using GitHub workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Language Sub-Paths in Astro
&lt;/h2&gt;

&lt;p&gt;Organizing translations for your website or application to language sub-paths in Astro is easy. It simplifies the management process and guarantees a consistent user experience across your application.&lt;/p&gt;

&lt;p&gt;Setting up these sub-paths involves including the “lang” parameter in your Astro routes, making the process straightforward. The sub-paths create distinct paths for each section of your site, each with its translations.&lt;/p&gt;

&lt;p&gt;Let’s connect the previously created JSON files with the Astro project using the &lt;a href="https://github.com/yassinedoghri/astro-i18next"&gt;astro-i18next&lt;/a&gt; package.&lt;/p&gt;

&lt;p&gt;To use the &lt;code&gt;astro-i18next&lt;/code&gt; package, you need to install it first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# npm&lt;/span&gt;
npm &lt;span class="nb"&gt;install &lt;/span&gt;astro-i18next

&lt;span class="c"&gt;# yarn&lt;/span&gt;
yarn add astro-i18next

&lt;span class="c"&gt;# pnpm&lt;/span&gt;
pnpm add astro-i18next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing the package, you can start using it to internationalize your project. To do this, you need to add &lt;code&gt;astro-i18next&lt;/code&gt; to your &lt;code&gt;astro.config.mjs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;astro/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;mdx&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@astrojs/mdx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sitemap&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@astrojs/sitemap&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;astroI18next&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;astro-i18next&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;site&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;integrations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mdx&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;sitemap&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;astroI18next&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure &lt;code&gt;astro-i18next&lt;/code&gt; in your &lt;code&gt;astro-i18next.config.mjs&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @type {import('astro-i18next').AstroI18nextConfig} */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;defaultLocale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;locales&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to use the &lt;code&gt;t()&lt;/code&gt; function available in the &lt;code&gt;astro-i18next&lt;/code&gt; package to translate the header link titles, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;---
import HeaderLink from './HeaderLink.astro';
import { SITE_TITLE } from '../consts';
import i18next, { t } from 'i18next';

const lang = i18next.language;
const base = lang === 'en' ? '' : `/${lang}`;
---

&lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;
    {SITE_TITLE}
  &lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;HeaderLink&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;{`${base}/`}&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{ t('nav.home') }&lt;span class="nt"&gt;&amp;lt;/HeaderLink&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;HeaderLink&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;{`${base}/blog`}&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{ t('nav.blog') }&lt;span class="nt"&gt;&amp;lt;/HeaderLink&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;HeaderLink&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;{`${base}/about`}&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{ t('nav.about') }&lt;span class="nt"&gt;&amp;lt;/HeaderLink&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;HeaderLink&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://twitter.com/astrodotbuild"&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Twitter&lt;span class="nt"&gt;&amp;lt;/HeaderLink&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;HeaderLink&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://github.com/withastro/astro"&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;GitHub&lt;span class="nt"&gt;&amp;lt;/HeaderLink&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that we use the &lt;code&gt;i18next.language&lt;/code&gt; variable to get the current language in order to build the base path for header links. The t() function is used to translate the text.&lt;/p&gt;

&lt;p&gt;The package also provides a language switcher component that you can use to switch between languages. To use it, you need to import the &lt;code&gt;LanguageSelector&lt;/code&gt; component from the &lt;code&gt;astro-i18next&lt;/code&gt; package. Let’s add it to the &lt;code&gt;src/components/Footer.astro&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;---
import { LanguageSelector } from 'astro-i18next/components';
---

&lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;LanguageSelector&lt;/span&gt; &lt;span class="na"&gt;showFlag=&lt;/span&gt;&lt;span class="s"&gt;{true}&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create localized pages using the generate command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx astro-i18next generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're all set! Now we can run the project and see the results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re all set! Now we can run the project and see the results:&lt;br&gt;
Go to the project in a web browser (&lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;) and try to change the language 🚀&lt;/p&gt;

&lt;p&gt;The localized pages will be available at the following URLs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt; - English&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://localhost:3000/es"&gt;http://localhost:3000/es&lt;/a&gt; - Spanish&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://localhost:3000/fr"&gt;http://localhost:3000/fr&lt;/a&gt; - French
Check out a minimalistic Astro web application on &lt;a href="https://github.com/yassinedoghri/astro-i18next/tree/beta/examples"&gt;GitHub&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connecting Crowdin in an Astro Context
&lt;/h2&gt;

&lt;p&gt;Connecting Crowdin to Astro is easy using APIs provided by Crowdin. To integrate Crowdin with Astro, follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a project in Crowdin and set up your translation workflow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connect your repository to Crowdin to sync your source files and translations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s an example of using Crowdin to manage translations in an Astro website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In Crowdin, create a new project and upload the source files you need to translate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set up the translation workflows, translation memory, and terminology management.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connect your repository to Crowdin to sync your source files and translations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To switch between languages, use the &lt;code&gt;lang&lt;/code&gt; parameter in your Astro routes. For example, when a user visits &lt;code&gt;/es/blog&lt;/code&gt;, the API will retrieve the Spanish translations. If the user visits &lt;code&gt;/fr/blog&lt;/code&gt;, the API will retrieve the French translations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  i18n Implementation in Astro
&lt;/h2&gt;

&lt;p&gt;Internationalization, or i18n, in Astro, refers to changing a web application to support multiple languages, date and time styles, and number styles. Visit the &lt;a href="https://docs.astro.build/en/recipes/i18n/"&gt;Astro documentation&lt;/a&gt; to learn more about i18n in Astro.&lt;/p&gt;

&lt;h2&gt;
  
  
  Considerations for Crowdin as a Translation Management System using Astro
&lt;/h2&gt;

&lt;p&gt;There are aspects to consider when working with Crowdin as a TMS with the Astro web framework. These factors may need paying attention to before you can get started with your application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Integration: Ensure that Crowdin integrates seamlessly with the Astro framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Translation process: Make sure that you have a simple process for handling translation requests, revisions, and approvals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Terminology management: Use Crowdin’s terminology management feature to ensure you use consistent terminology throughout the translation process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Translation memory: Take advantage of Crowdin’s translation memory feature to store and reuse translations for frequently used phrases and sentences.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Project management: Use Crowdin’s project management tools to keep track of the translation process, deadlines, and progress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User management: Consider setting up user roles and permissions within Crowdin. This allows you to manage access to the translation project and ensure that the right people have access to the right information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performance: Test the performance of the integration between Crowdin and Astro to ensure that it performs well in production.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error handling: Handle errors gracefully and log them meaningfully, so you can debug and resolve issues when they arise.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;By utilizing Astro and Crowdin, you can streamline the localization process, and the result will be a web application accessible to a diverse global audience.&lt;br&gt;
&lt;a href="https://accounts.crowdin.com/register"&gt;Start a free 14-day trial&lt;/a&gt; today to make your company multilingual with Crowdin.&lt;/p&gt;

</description>
      <category>engineeringteams</category>
      <category>framework</category>
    </item>
  </channel>
</rss>
