I. Introduction
When developing applications that require support for multiple languages, localization automation can streamline the process by automatically managing string files that define key-value pairs. These key-value pairs consist of unique keys that retrieve corresponding values for content specific to the selected language, simplifying the management of language-specific data.
When working on multi-platform projects, it is important to be aware that each platform may have its own unique string file format. For example, iOS uses the .strings format, while Android uses .xml, and Flutter uses the .json format. These file formats have different structures and syntax, which can make it challenging to manage language-specific data across multiple platforms.
II. Problem
Localization workflow automation can address common challenges in multilingual projects by streamlining processes and minimizing errors:
– Collaborators editing the same string file may lead to conflicts or duplicate keys.
– The teams (iOS and Android) do not agree on keys. Usually, developers do not decide the values but rely on translators or clients to provide them. If the keys are not the same, it causes many difficulties.
– For each key, the developer needs to provide temporary values for the corresponding language without knowing the meaning by using Google Translate to translate and then copy into each file.
III. Solution
Google Sheets provides an ideal platform for collaboration on a single file, as it enables multiple users to access and edit the same file simultaneously. By leveraging the power of Google Sheets, developers can work together on a single file in real-time, thereby streamlining the collaboration process and enabling more efficient workflows.
This approach can be particularly helpful for multi-person projects, as it allows team members to view and modify the same data, share feedback, and make updates as needed.
Define key-value pairs for English
In mobile development, localization string files are typically used to provide translations for app content in different languages. Key-value pairs are a common way to define these translations in these files.
By using Google Sheets in conjunction with localization automation, teams can enhance efficiency, minimize errors, and maintain consistency across platforms, all while simplifying collaboration in multilingual projects.
Write a script to automatically generate content for the corresponding string files for each language
What is Google Apps Script?
Google Apps Script is a platform for developing applications quickly, designed to facilitate the creation of business applications that can be seamlessly integrated with Google Workspace. By using modern JavaScript, developers can easily write code that leverages the built-in libraries available for popular Google Workspace applications, including Gmail, Calendar, Drive, and many more.
Access the Apps Scripts editor
By utilizing Google Apps Script, developers can write functions to convert key-value pairs into string files within Google Sheets, with the script being based on JavaScript.
We define 3 functions for 3 platform (iOS, Android, Flutter), each function will have 3 parameters
Screens: all values of the screen name.
Keys: all values of the keys
Values: all values of the value
The function is designed to merge values with their corresponding keys and screens, creating a final output that accurately reflects the original data. To accomplish this, the function loops through all values and matches them with their respective keys and screens before merging them.
For strings with internal formats, we convert them to the correct format for each platform using the replace function.
– For example, %s will be converted to %@ on iOS.
Code
iOS
Android
Flutter
Back to the Google Sheet file, using the corresponding functions for iOS, Flutter, and Android.
For other languages, we use Google Translate to translate and then use the localize function above to generate the corresponding string files. When using GOOGLETRANSLATE to convert text from one language to another, it is necessary to specify the two-letter language codes of both the source and target languages as the 2nd and 3rd parameters.
After completing the necessary steps to generate values for iOS, Android, and Flutter, the next action is to copy these values into a text editor. By doing so, developers can easily view and compare the results side-by-side, making it easier to identify any discrepancies or errors that may require further attention.
Automatically update the corresponding values for each file.
Automated localization helps address the challenge of keeping string files updated after edits by automating the synchronization process. Manually copying and pasting values every time a change is made can be a tedious and error-prone task, which is why we leverage the tool `gspread` (https://github.com/burnash/gspread) to streamline this process.
By utilizing `gspread`, developers can automate the synchronization of data between the string files and the corresponding values, thereby reducing the risk of human error and saving valuable time and resources. This automation ensures that the project remains up-to-date and accurate, while also enabling a more efficient and streamlined development process.
After installing `gspread`, we create a tools folder in each corresponding platform, where we have 2 files updateLocalization.py and updateLocalization.sh
– updateLocalization.py is used to access the Google Sheet file and copy the desired cell value. The Column value is determined by the first parameter of the argument vector, and the Row value is the same as the Row with the cell value gspreadIOS.
– updateLocalization.sh is used to call updateLocalization.py to get the value and copy it to the string file.
Every time we need to update the content of the string file, we only need to run a single command.
IV. Conclusion
Localization automation, utilizing Google Sheets and Scripts, significantly simplifies the management of language-specific data in mobile, front-end, and back-end development. This approach offers a convenient and efficient way to manage language-specific data and automate the synchronization of data between various platforms.
By leveraging the power of Google Sheets and Scripts, localization automation enhances accuracy and efficiency, making it easier to maintain consistent language support across all platforms. This approach can be especially beneficial for multilingual projects or projects that involve frequent updates and changes, as it allows developers to easily manage and update language-specific data in a centralized location.
Our developers have experience with hundreds of mobile projects and know the latest trends and technologies to make your app stand out. Get expert consultation and top-notch support from us now!
Resources
Demo source code: Repos’s link