⌨️ How to automate i18n and l10n?
Introduction
In this tutorial, we will learn how to automate the process of internationalization (i18n) and localization (l10n) with Boyka Framework.
Supported languages
Currently, Boyka Framework supports the following languages:
- English (EN)
- German (GR)
- Arabic (AR)
Step 1: Update the project configuration
You need to first configure your Boyka projects configuration file to specify the languages you want to support and the folder where the language files are located.
In the boyka-config.json
file, in your platform specific block, add the following configuration:
{
"ui": {
"web": {
"test_local_en": {
"base_url": "https://webdriver.io/",
"browser": "CHROME",
"resize": "MAXIMIZED",
"language": {
"language": "EN"
},
"highlight": false,
"headless": true
},
}
}
}
Language setting is also supported for API and Mobile platforms.
You can check out the complete configuration details about the language configuration in the Boyka Framework Configuration documentation.
Step 2: Create language files
Create a folder named lang
in the src/test/resources
directory of your project. Inside this folder, create a file for each language you want to support with the abbreviation of the supported languages mentioned above.
For example, create en.json
for English and gr.json
for German, same as in the example below:
English language file:
{
"title": "Next-gen browser and mobile automation test framework for Node.js"
}
German language file:
{
"title": "Test-Framework für Browser und mobile Automatisierung der nächsten Generation für Node.js"
}
Step 3: Create POJO classes
Create a POJO class for the language file you created in the previous step. The class should have all the fields defined in the language file, and each field should have a getter method.
You can use the @Getter
annotation from the Lombok library to generate the getter methods automatically.
Follow the example below:
package io.github.boykaframework.testng.ui.lang.data;
import lombok.Getter;
@Getter
public class LocaleData {
private String title;
}
Step 4: Access the language files
To access the language files, you can use the getLanguage
method from the LanguageAction
class.
Check the example below:
import static io.github.boykaframework.actions.data.LanguageAction.withLanguage;
. . .
final var expectedTitle = withLanguage ().getLanguage (LocaleData.class)
.getTitle ();
This method takes the class type of the POJO you created in the previous step and returns an instance of that class with the values from the language file.
Conclusion
Hope this tutorial helped you to automate the process of internationalization (i18n) and localization (l10n) with Boyka Framework. You can now easily manage your language files and access them in your tests.
If there is a language you want to add, please feel free to create a new feature request on GitHub or contribute to the project by creating a pull request. We would love to have your contribution to the Boyka Framework community.
If you have any questions or feedback, please feel free to reach out to us on our Discord server.