Tiny Frontend Logo
Posts 0132

On This Page

Translate Your React Application

Ever wondered what i18n stands for?

It's short for internationalization, and it's a crucial concept for any application targeting a global audience.

Think of it as the process of making your app adaptable to different languages and cultural conventions, turning it into a true citizen of the world.

Why I18n Matters

Translate Your React Application

Internationalizing your app is a smart move that benefits you in many ways:

  • Reach a wider audience: More users mean more engagement, more income, and a stronger app overall.
  • Increase user satisfaction: People feel more connected to apps in their own language, making them happier and more likely to keep using your app.
  • Create a truly inclusive experience: Remove language barriers so anyone can enjoy your app.
  • Stand out from the competition: In today's global market, multilingual apps are a must-have to attract more users and show your commitment to inclusivity.

Saying Goodbye to Hardcoded Text

Traditionally, developers hardcoded text directly within their HTML code, making it difficult to update or translate.

For example, a login button would be written as:

<button class="login-button">Login</button>

To simplify multi-languages support and translation management, we'll use a smarter approach with translation keys and files.

Here's how it works:

1. Create Translation Files

We'll store all our text in separate files for each language. For example, our English translation file might look like this:

{
  "label_login": "Login"
}

2.Use Keys in Your Code

Instead of writing "Login" directly, we'll use a key like label_login. Then, we'll use a helper function to translate these keys into the appropriate language.

<button class="login-button">
  {translate('label_login')}
</button>

This way, we can easily update our translations without touching our main code. It's much cleaner and more efficient!

Subscribe to read the full content

* Free subscribe to enjoy full content access.
* You can cancel anytime with 1-click.

Read Next

0131

Customising JavaScript fetch()

In our previous post, we explained about how the fetch API can be used in JavaScript to make GET and POST requests. Let's look at some of the more advanced concepts of the fetch API in JavaScript.

Customising JavaScript fetch()
0130

Making a POST Request to the Server

In our previous post, we wrote about GET requests using JavaScript's fetch() method. This is a simple use case where we pass in a url into the method. However, fetch() also takes in a second parameter (optional) where we can pass in various request options.

0129

Data Fetching from the Server

Do you know what AJAX is? It seems to be an "old" concept today, it allows us to use JavaScript to send asynchronous data requests to the server and update the rendering of the page locally.

Data Fetching from the Server
0128

JavaScript Currying

The first time I heard the term Currying was during a job interview preparation. Fortunately, the interviewer did not ask me any questions about it.

JavaScript Currying
0127

FormData in JavaScript

The most common way of sending data to the server in a network request is by using a JSON object. But, in some cases, JSON maybe insufficient to transmit the data.

FormData in JavaScript
0126

HTTP Status Code for SEO

When a browser sends a request, the server responds with a corresponding HTTP status code, whether the request can be fulfilled or not.

HTTP Status Code for SEO