Translation
Since Checkstyle 3.0
Description
requiredTranslations
option is used.
Notes
Language code for the property requiredTranslations
is composed of
the lowercase, two-letter codes as defined by
ISO 639-1.
Default value is empty String Set which means that only the existence
of default translation is checked. Note, if you specify language codes (or just
one language code) of required translations the check will also check for
existence of default translation files in project.
Note: If your project uses preprocessed translation files and the original files
do not have the properties
extension,
you can specify additional file extensions
via the fileExtensions
property.
Attention: the check will perform the validation of ISO codes if the option is used. So, if you specify, for example, "mm" for language code, TranslationCheck will rise violation that the language code is incorrect.
Attention: this Check could produce false-positives if it is used with Checker that use cache (property "cacheFile") This is known design problem, will be addressed at issue.
Properties
name | description | type | default value | since |
---|---|---|---|---|
baseName | Specify Base name of resource bundles which contain message resources. It helps the check to distinguish config and localization resources. | Pattern | "^messages.*$" |
6.17 |
fileExtensions | Specify the file extensions of the files to process. | String[] | .properties |
3.0 |
requiredTranslations | Specify language codes of required translations which must exist in project. | String[] | {} |
6.11 |
Examples
Note, that files with the same path and base name but which have different extensions will be considered as files that belong to different resource bundles.
To configure the check to check existence of Japanese and French translations:
<module name="Checker">
<module name="Translation">
<property name="requiredTranslations" value="es, fr"/>
</module>
</module>
Example1 (target folder structure):
messages.properties
messages_fr.properties
messages_es.properties
Contents of messages.properties file:
hello=Hello
cancel=Cancel
Contents of messages_es.properties file:
greeting=Saludo
age=Edad
Contents of messages_fr.properties file:
greeting=Bonjour
name=Nom
Validation for Example1:
messages.properties // violation 'Key 'age', 'name' and 'greeting' missing.'
messages_fr.properties // violation 'Key 'age', 'cancel' and 'hello' missing.'
messages_es.properties // violation 'Key 'cancel', 'name' and 'hello' missing.'
An example of how to configure the check to validate only bundles which base names start with "ButtonLabels":
<module name="Checker">
<module name="Translation">
<property name="baseName" value="^ButtonLabels.*$"/>
<property name="requiredTranslations" value="fr"/>
</module>
</module>
Example2 (target folder structure):
ButtonLabels.properties
ButtonLabels_fr.properties
Contents of ButtonLabels.properties file:
hello=Hello
cancel=Cancel
Contents of ButtonLabels_fr.properties file:
hello=Bonjour
name=Nom
Validation for Example2:
ButtonLabels.properties // violation 'Key 'name' is missing.'
ButtonLabels_fr.properties // violation 'Key 'cancel' is missing.'
To configure the check to check only files which have '.properties' and '.translations' extensions:
<module name="Checker">
<module name="Translation">
<property name="fileExtensions" value="properties"/>
<property name="fileExtensions" value="translations"/>
<property name="requiredTranslations" value="fr"/>
</module>
</module>
Example3 no messages_home_fr.* files (target folder structure):
messages_home.properties
messages_home.translations
Contents of messages_home.properties file:
hello=Hello
cancel=Cancel
Contents of messages_home.translations file:
hello=Hallo
ok=OK
Validation for Example3:
messages_home.properties // violation,
'Properties file 'messages_home_fr.properties' missing.'
messages_home.translations // violation,
'Properties file 'messages_home_fr.translations' missing.'
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks