Best Practices for Localization in Microservices

Harun Keles0glu
3 min readJun 20, 2023

--

Localization is a crucial aspect of developing microservices that cater to a global user base. By adapting your application to different languages, cultures, and regions, you can provide a personalized and inclusive experience to your users. In this article, we will explore the best practices for implementing localization in microservices, covering various aspects from standardization to technical considerations.

1. Separation of Resource Files

To effectively manage localization in microservices, it is important to separate translation texts from the source code. You can place translation texts in a separate file or a database, providing a more flexible environment for your software development team to update and manage translation files.

2. Standardization of Translation Files

Create separate translation files for each language and organize them in a standardized directory structure. This ensures that each language has its own translation file and that changes do not affect other languages. You can organize translation files in key-value pairs. A good way to organize your language files is to use a directory or file structure based on the ISO code of the language. For example, the “en” directory corresponds to the English language, and the “tr” directory corresponds to the Turkish language. This way, you can create a separate directory or file for each language and store the relevant language files within it.

Directory based

locales/
├── en/
│ └── translation.json
├── tr/
│ └── translation.json
├── es/
│ └── translation.json
└── fr/
└── translation.json

File based:

locales/
├── en.json
├── fr.json
├── de.json
└── ...

It is recommended to store your translation files in a structured data format such as JSON or YAML. This allows for easy access to translation keys and their corresponding texts. Additionally, you can read, write, and update your language files easily.

en.json

{
"home_page.title": "Ana Sayfa",
"home_page.description": "Merhaba, dünyaya hoş geldiniz!"
}

The recommended approach is to create keys in a clear, consistent, and categorized manner. Keys are typically written in lowercase and separated by underscores.

3. Configuration of Localization

Use a configuration mechanism to manage localization in your microservices. This allows you to load translations based on the user’s language preference at runtime. The language preference can typically be obtained from the user’s browser settings or login information.

4. Live Broadcasting of Language Changes

It is important to immediately update localization when a user changes their language preference to provide a seamless experience. Therefore, you need to use a mechanism displayed correctly.

5. Translation Workflow and Management

Create a workflow to effectively manage the translation process. Plan translation activities to minimize interaction between the translation team and the software development team. You can use a version control system to easily track changes.

Bonus

If you are a small startup and don’t have the time or resources to deal with translations, I can recommend AI-based localization libraries. I can suggest my own simple npm library that I have developed, which I’m confident will help you with your needs.

@celsus-ai/localize
@kelesoglu/localise-ai

These best practices will help you manage localization more effectively in your microservices. Sharing language resources between microservices and implementing fast language changes will enhance the user experience.

--

--

Harun Keles0glu
Harun Keles0glu

No responses yet