From 08aa8577b6e1c2cddff086912542c7d54d7378a2 Mon Sep 17 00:00:00 2001 From: shivam Date: Sun, 19 Mar 2023 04:16:02 -0700 Subject: [PATCH] Issue #7593: Update doc for translation --- .../checkstyle/checks/TranslationCheck.java | 74 ++++++++++++++----- src/xdocs/config_misc.xml | 73 +++++++++++++----- 2 files changed, 107 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java index b443a29f9bc..f079bdb170d 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java @@ -128,18 +128,35 @@ * * *

+ * 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 only files which have '.properties' and * '.translations' extensions: *

*
  * <module name="Translation">
  *   <property name="fileExtensions" value="properties, translations"/>
+ *   <property name="requiredTranslations" value="fr"/>
  * </module>
  * 
*

- * 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. + * Example: *

+ *
+ * #messages.properties
+ * hello=Hello
+ * cancel=Cancel
+ *
+ * #messages.translations
+ * hello=Hallo
+ * ok=OK
+ * 
+ *
+ * messages.properties: Properties file 'messages_fr.properties' is missing.
+ * messages.translations: Properties file 'messages_fr.translations' is missing.
+ * 
*

* An example of how to configure the check to validate only bundles which base * names start with "ButtonLabels": @@ -147,40 +164,57 @@ *

  * <module name="Translation">
  *   <property name="baseName" value="^ButtonLabels.*$"/>
+ *   <property name="requiredTranslations" value="fr"/>
  * </module>
  * 
*

- * To configure the check to check existence of Japanese and French translations: + * Example: *

*
- * <module name="Translation">
- *   <property name="requiredTranslations" value="ja, fr"/>
- * </module>
+ * #ButtonLabels.properties
+ * hello=Hello
+ * cancel=Cancel
+ *
+ * #ButtonLabels_fr.properties
+ * hello=Bonjour
+ * name=Nom
+ * 
+ *
+ * ButtonLabels.properties: Key 'name' is missing.
+ * ButtonLabels_fr.properties: Key 'cancel' is missing.
  * 
*

- * The following example shows how the check works if there is a message bundle - * which element name contains language code, county code, platform name. - * Consider that we have the below configuration: + * To configure the check to check existence of Japanese and French translations: *

*
  * <module name="Translation">
- *   <property name="requiredTranslations" value="es, fr, de"/>
+ *   <property name="requiredTranslations" value="ja, fr"/>
  * </module>
  * 
*

- * As we can see from the configuration, the TranslationCheck was configured - * to check an existence of 'es', 'fr' and 'de' translations. Let's assume that - * we have the resource bundle: + * Example: *

*
- * messages_home.properties
- * messages_home_es_US.properties
- * messages_home_fr_CA_UNIX.properties
+ * #messages.properties
+ * hello=Hello
+ * cancel=Cancel
+ *
+ * #messages_ja.properties
+ * greeting=こんにちは
+ * age=年齢
+ *
+ * #messages_fr.properties
+ * greeting=Bonjour
+ * name=Nom
+ * 
+ *
+ * messages.properties: Key 'age' missing.
+ * messages.properties: Key 'name' missing.
+ * messages_fr.properties: Key 'age' missing.
+ * messages_fr.properties: Key 'cancel' missing.
+ * messages_ja.properties: Key 'cancel' missing.
+ * messages_ja.properties: Key 'name' missing.
  * 
- *

- * Than the check will rise the following violation: "0: Properties file - * 'messages_home_de.properties' is missing." - *

*

* Parent is {@code com.puppycrawl.tools.checkstyle.Checker} *

diff --git a/src/xdocs/config_misc.xml b/src/xdocs/config_misc.xml index 2d40bdcaba1..c93c88db924 100644 --- a/src/xdocs/config_misc.xml +++ b/src/xdocs/config_misc.xml @@ -2340,6 +2340,10 @@ messages.properties: Key 'ok' missing. +

+ 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 only files which have '.properties' and '.translations' extensions: @@ -2347,12 +2351,25 @@ messages.properties: Key 'ok' missing. <module name="Translation"> <property name="fileExtensions" value="properties, translations"/> + <property name="requiredTranslations" value="fr"/> </module>

- 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. + Example:

+ +#messages.properties +hello=Hello +cancel=Cancel + +#messages.translations +hello=Hallo +ok=OK + + +messages.properties: Properties file 'messages_fr.properties' is missing. +messages.translations: Properties file 'messages_fr.translations' is missing. +

An example of how to configure the check to validate only bundles which base names start with "ButtonLabels": @@ -2360,9 +2377,25 @@ messages.properties: Key 'ok' missing. <module name="Translation"> <property name="baseName" value="^ButtonLabels.*$"/> + <property name="requiredTranslations" value="fr"/> </module> +

+ Example: +

+ +#ButtonLabels.properties +hello=Hello +cancel=Cancel +#ButtonLabels_fr.properties +hello=Bonjour +name=Nom + + +ButtonLabels.properties: Key 'name' is missing. +ButtonLabels_fr.properties: Key 'cancel' is missing. +

To configure the check to check existence of Japanese and French translations:

@@ -2372,29 +2405,29 @@ messages.properties: Key 'ok' missing. </module>

- The following example shows how the check works if there is a message bundle which - element name contains language code, county code, platform name. - Consider that we have the below configuration: + Example:

-<module name="Translation"> - <property name="requiredTranslations" value="es, fr, de"/> -</module> +#messages.properties +hello=Hello +cancel=Cancel + +#messages_ja.properties +greeting=こんにちは +age=年齢 + +#messages_fr.properties +greeting=Bonjour +name=Nom -

- As we can see from the configuration, the TranslationCheck was configured to check - an existence of 'es', 'fr' and 'de' translations. Let's assume that we have the resource - bundle: -

-messages_home.properties -messages_home_es_US.properties -messages_home_fr_CA_UNIX.properties +messages.properties: Key 'age' missing. +messages.properties: Key 'name' missing. +messages_fr.properties: Key 'age' missing. +messages_fr.properties: Key 'cancel' missing. +messages_ja.properties: Key 'cancel' missing. +messages_ja.properties: Key 'name' missing. -

- Than the check will rise the following violation: - "0: Properties file 'messages_home_de.properties' is missing." -