Class TranslationCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
-
- com.puppycrawl.tools.checkstyle.checks.TranslationCheck
-
- All Implemented Interfaces:
Configurable,Contextualizable,FileSetCheck
public class TranslationCheck extends AbstractFileSetCheck
The TranslationCheck class helps to ensure the correct translation of code by checking locale-specific resource files for consistency regarding their keys. Two locale-specific resource files describing one and the same context are consistent if they contain the same keys. TranslationCheck also can check an existence of required translations which must exist in project, if 'requiredTranslations' option is used.
An example of how to configure the check is:
<module name="Translation"/>
Check has the following options:baseName - a base name regexp for resource bundles which contain message resources. It helps the check to distinguish config and localization resources. Default value is ^messages.*$
An example of how to configure the check to validate only bundles which base names start with "ButtonLabels":
<module name="Translation"> <property name="baseName" value="^ButtonLabels.*$"/> </module>To configure the check to check only files which have '.properties' and '.translations' extensions:
<module name="Translation"> <property name="fileExtensions" value="properties, translations"/> </module>requiredTranslations which allows to specify language codes of required translations which must exist in project. Language code 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. 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMSG_KEYA key is pointing to the warning message text for missing key in "messages.properties" file.static java.lang.StringMSG_KEY_MISSING_TRANSLATION_FILEA key is pointing to the warning message text for missing translation file in "messages.properties" file.
-
Constructor Summary
Constructors Constructor Description TranslationCheck()Creates a newTranslationCheckinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginProcessing(java.lang.String charset)Called when about to be called to process a set of files.voidfinishProcessing()Called when all the files have been processed.protected voidprocessFiltered(java.io.File file, FileText fileText)Called to process a file that matches the specified file extensions.voidsetBaseName(java.util.regex.Pattern baseName)Sets the base name regexp pattern.voidsetRequiredTranslations(java.lang.String... translationCodes)Sets language codes of required translations for the check.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
addMessages, destroy, fireErrors, getFileExtensions, getMessageDispatcher, init, log, log, process, setFileExtensions, setMessageDispatcher
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configure
-
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
-
-
-
-
Field Detail
-
MSG_KEY
public static final java.lang.String MSG_KEY
A key is pointing to the warning message text for missing key in "messages.properties" file.- See Also:
- Constant Field Values
-
MSG_KEY_MISSING_TRANSLATION_FILE
public static final java.lang.String MSG_KEY_MISSING_TRANSLATION_FILE
A key is pointing to the warning message text for missing translation file in "messages.properties" file.- See Also:
- Constant Field Values
-
-
Method Detail
-
setBaseName
public void setBaseName(java.util.regex.Pattern baseName)
Sets the base name regexp pattern.- Parameters:
baseName- base name regexp.
-
setRequiredTranslations
public void setRequiredTranslations(java.lang.String... translationCodes)
Sets language codes of required translations for the check.- Parameters:
translationCodes- a comma separated list of language codes.
-
beginProcessing
public void beginProcessing(java.lang.String charset)
Description copied from interface:FileSetCheckCalled when about to be called to process a set of files.- Specified by:
beginProcessingin interfaceFileSetCheck- Overrides:
beginProcessingin classAbstractFileSetCheck- Parameters:
charset- the character set used to read the files.
-
processFiltered
protected void processFiltered(java.io.File file, FileText fileText)Description copied from class:AbstractFileSetCheckCalled to process a file that matches the specified file extensions.- Specified by:
processFilteredin classAbstractFileSetCheck- Parameters:
file- the file to be processedfileText- the contents of the file.
-
finishProcessing
public void finishProcessing()
Description copied from interface:FileSetCheckCalled when all the files have been processed. This is the time to perform any checks that need to be done across a set of files. In this method, the implementation is responsible for the logging of messages.- Specified by:
finishProcessingin interfaceFileSetCheck- Overrides:
finishProcessingin classAbstractFileSetCheck
-
-