From 7e36b3cbd1ae5cf41fd9101ac8c69fe751200d58 Mon Sep 17 00:00:00 2001 From: alexkravin Date: Tue, 16 Dec 2014 14:10:57 +0400 Subject: [PATCH] Translation Check - update changes due to new option, issue #149 --- .../checkstyle/checks/TranslationCheck.java | 12 ++++++++++++ .../checks/TranslationCheckTest.java | 19 +++++++++++++++++++ .../tools/checkstyle/app-dev.properties | 12 ++++++++++++ .../tools/checkstyle/app-stage.properties | 12 ++++++++++++ src/xdocs/config_misc.xml | 17 ++++++++++++++++- 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/app-dev.properties create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/app-stage.properties 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 62a1c5676..cf2560b23 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java @@ -52,6 +52,18 @@ import java.util.Map.Entry; *
  * <module name="Translation"/>
  * 
+ * Check has a property basenameSeparator which allows setting separator in file names, + * default value is '_'. + *

+ * E.g.: + *

+ *

+ * messages_test.properties //separator is '_' + *

+ *

+ * app-dev.properties //separator is '-' + *

+ *
* @author Alexandra Bunge * @author lkuehne */ diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java index f37ebb52e..d0dbb314b 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java @@ -61,4 +61,23 @@ public class TranslationCheckTest // key2=y // should not result in error message about key1 missing in the y bundle + @Test + public void testBaseNameSeparator() throws Exception + { + final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class); + checkConfig.addAttribute("basenameSeparator", "-"); + final String[] expected = { + "0: Key 'only.english' missing.", + }; + final File[] propertyFiles = new File[] { + new File(getPath("app-dev.properties")), + new File(getPath("app-stage.properties")), + }; + verify( + createChecker(checkConfig), + propertyFiles, + getPath("app-dev.properties"), + expected); + } + } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/app-dev.properties b/src/test/resources/com/puppycrawl/tools/checkstyle/app-dev.properties new file mode 100644 index 000000000..9a7ae0711 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/app-dev.properties @@ -0,0 +1,12 @@ +# input file for TranslationCheck + +# a key that is available in all translations +hello=Hallo + +# whitespace at end of key should be trimmed before comparing. +# the german translation does not contain whitespace, no error should +# be reported here +cancel=Abbrechen + +# a key that is missing in german translation +#only.english=only english diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/app-stage.properties b/src/test/resources/com/puppycrawl/tools/checkstyle/app-stage.properties new file mode 100644 index 000000000..a82290c28 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/app-stage.properties @@ -0,0 +1,12 @@ +# input file for TranslationCheck + +# a key that is available in all translations +hello=Hello + +# whitespace at end of key should be trimmed before comparing. +# the german translation does not contain whitespace, no error should +# be reported here +cancel = Cancel + +# a key that is missing in german translation +only.english=only english diff --git a/src/xdocs/config_misc.xml b/src/xdocs/config_misc.xml index d44177d9a..e682ad25d 100755 --- a/src/xdocs/config_misc.xml +++ b/src/xdocs/config_misc.xml @@ -215,16 +215,31 @@ messages.properties: Key 'ok' missing. String Set properties + + basenameSeparator + Allows setting file names separator + String + _ +

- To configure the check: + To configure the check for files with '_' name separator:

<module name="Translation"/> + +

+ To configure the check for files with user-set name separator: +

+ +<module name="Translation"> + <property name="basenameSeparator" value="STRING_LITERAL"/> +</module> +