How to Manage Resource Files for Effective Internationalization & Localization
Resource files are a crucial component of software localization. If you’re a developer or work in localization, you’ve probably heard of them. But for those who haven’t, don’t worry – we’ll break it down
What’s a resource file?
A resource file stores all the user-facing text in an app or website. Instead of hardcoding phrases like “Click here” or “Welcome” directly into your code, you put them in a separate file. This file is basically a list of labels and their corresponding text in different languages.
For example:
WELCOME_MESSAGE = Welcome
CLICK_HERE = Click here
Then, for other languages, you create similar files with the same labels but translated text:
WELCOME_MESSAGE = Bienvenue
CLICK_HERE = Cliquez ici
These files come in different formats depending on what programming language or framework you’re using. Java uses .properties files, .NET uses .resx, and web apps often use JSON.
Why bother with resource files?
You might be wondering why you’d go through the trouble of setting up these files. Well, there are a few good reasons:
By using resource files, you’re setting yourself up for success when it comes to making your app available in multiple languages. Although it may seem like extra work initially, the benefits are significant over time.
Common File Formats for Resource Files
As we already mentioned, different programming languages handle resource files in their own formats. How to denote locales, how to pass locales in the application execution path, and how to fall back on the default locale when a given locale resource is not found.
Here are some common examples:
Following these standard file formats, will help developers streamline the internationalization (i18n) process and make it easier to manage localization (l10n).
Challenges with Non-Standard Resource Files
While standard formats simplify localization, some developers use non-standard methods to store resource files. Here are some real-life examples:
Using JSON files with locale as the root key
In this case, JSON files are named with locales, which means the filename itself indicates the language or region (e.g., en.json for English). However, inside the file, the locale is used as the root key. This means that all strings or data in the file are nested under the locale identifier within the file structure.
Instead of:
领英推荐
This structure can make it harder to manage if there are multiple locales in one file, as it requires additional handling when extracting translations.
Storing all locales in a single YAML file
At build time the file is split into multiple YAML files, each representing a specific locale. These files are then converted into CSV format and sent for translation. Once the translations are complete, the CSV files are returned, reprocessed back into their respective formats (YAML), and then pushed into a database to update the localized content.
This method allows the central management of multiple locales but adds complexity during the translation and build process.
Create multiple YAML files for different locales
During the build time, these YAML files are combined into a single read-only JSON file that contains all the locales’ data. This can cause the following problems:
Storing resource files in deeply nested paths
Instead of placing the resource files directly in a directory tied to the locale (e.g., en/resources.json for English), they are stored in a more complex directory structure, located “somewhere below,” such as en/my/deep/path/to/the/resources.json.?
This approach complicates the organization and retrieval of localization files, making it harder to manage and track them, as the directory structure is unnecessarily deep or non-standard.
Misuse of YAML by formatting it like XML?
Instead of following proper YAML syntax it is formatted like XML. This incorrect approach adds unnecessary complexity.
The correct approach simplifies it by using direct key-value pairs:
Using the same naming for resource files
Multiple files, which are meant to store different types of content or resources, all share the same filename, like “en.json” for English content. This causes confusion and difficulty in managing these files because it’s hard to distinguish between them without looking at the directory path. Best practices recommend giving each file a unique, descriptive name (e.g., menu_en.json or homepage_en.json) to improve clarity and organization.
These “creative” approaches in resource file management can lead to additional work for both developers and localization teams. It may require creating custom scripts, managing complex directory structures, and developing specialized workflows for translation and file validation. This can increase the risk of errors and slow down the localization process and as a consequence, the development cycle.
Best Practices for Managing Resource Files
To make the i18n and l10n processes smoother, follow these best practices:
Lingoport offers solutions that can help automate and streamline your i18n and l10n processes, ensuring your software is ready for global markets. If you need any support contact us. We can help you go global at the speed of development.