i18n files are used in SAPUI5 for translating applications. Per language one file is created, containing key-value-pairs (see documentation), see example:
showHelloButtonText=Say Hello
helloMsg=Hello {0}
This tool helps to validate those files.
To check the i18n files of an application, just call the validator in your applications directory:
Usage: ui5-i18n-validator [options]
Options:
--bail-on-error, -b Cancel npm task, if any errors were found [boolean]
--rules, -r List of rules, seperated by space [string]
As best practice is, that the i18n-files are located in a dedicated i18n directory, the directories must be organized like this:
App directory
├─ dist
└─ webapp
├─ controller
├─ i18n
│ ├─ i18n.properties
│ ├─ i18n_de.properties
│ ├─ i18n_en.properties
│ ├─ ...
├─ view
Maybe in further versions, and if requested, the path to i18n directory can be configured.
ui5-i18n-validator --bail-on-error will exit the process with error code 1.
Hint: This can be helpful, for example in CI/CD scenarios, when you want the build process to fail, if there are errors.
If the parameter is not provided, the process will end with no error code (0).
ui5-i18n-validator --rules missing-keys empty-keys will only check the two rules, which are provided as parameter.
Following rules exist:
missing-keysempty-keyshardcoded-texts
For a detailed description of the rules see chapter Validation rules.
If the parameter is not provided, all rules will be used for validation.
Currently following rules are supported for validating translations:
This rule checks, if there are keys defined for one language, which are missing for another. For example:
i18n_en.properties:
formTitle = Form
sendBtn = Send
i18n_de.properties:
formTitle = Formular
In this case the validator will print the following content on CLI:
Checking missing keys:
‼ Following keys exist in *en* but are missing in *de*
× sendBtn
If there's no key missing, the output will look like this:
Checking missing keys:
√ No missing keys found.
This rule will check if there are keys defined, missing a value. For example:
i18n_en.properties:
formTitle = Form
sendBtn =
In this case, the validator will print a message like this:
Checking empty keys:
‼ Following keys are empty in en
× sendBtn
In case there's no value missing, the output will look like this:
Checking empty keys:
√ No empty keys found.
Basically this rule checks all xml files in the webapp folder for attributes, which should be translated (for a complete list of attributes see Chapter Limitations). If an attributes value does not start with an {, the validator assumes, that it's not translated. So:
<!-- This would be an error -->
<Page title="View 1" id="page">
<!-- This would be fine -->
<Page title="{i18n>viewTitle}" id="page">If there are hardcoded texts, the output will look like this:
Checking hardcoded texts:
‼ Following propably hardcoded texts were found in View1.xml
× line: 9 attribute: title value: View 1
In case there are no hardcoded texts found, the output will look like this:
Checking hardcoded texts:
√ No hardcoded texts found.
Ensuring that there are definitely no hardcoded texts, can be very complex. So there are some limitations:
- Only
xmlfiles are checked. So hardcoded texts from JavaScript files won't be found (e.g.MessageBox.show("hello world")) - Only some xml attributes are currently checked, wheter they are hardcoded or not. As of now, the following attributes are checked:
title,subtitle,text,placeholder,headerText,objectTitle,objectSubtitle,secondTitle,label
Would be great if you contribute. There's lots of room for improvement. See CONTRIBUTING.md.
MIT © Lukas Böhm