Issue #2251: Fix wrong support for resources with language, country, variant
This commit is contained in:
parent
77acd41cf1
commit
dea6dab124
|
|
@ -202,11 +202,9 @@ public class TranslationCheck
|
|||
*/
|
||||
private void checkExistenceOfRequiredTranslations(Set<File> filesInResourceBundle) {
|
||||
final String fullBundleName = getFullBundleName(filesInResourceBundle);
|
||||
final String extension = getFileExtensions()[0];
|
||||
|
||||
for (String languageCode : requiredTranslations) {
|
||||
final String translationFileName =
|
||||
fullBundleName + '_' + languageCode + extension;
|
||||
final String translationFileName = fullBundleName + '_' + languageCode;
|
||||
|
||||
final boolean missing = isMissing(translationFileName, filesInResourceBundle);
|
||||
if (missing) {
|
||||
|
|
@ -255,7 +253,7 @@ public class TranslationCheck
|
|||
boolean missing = false;
|
||||
for (File file : filesInResourceBundle) {
|
||||
final String currentFileName = file.getPath();
|
||||
missing = !currentFileName.equals(fileName);
|
||||
missing = !currentFileName.contains(fileName);
|
||||
if (!missing) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,4 +230,44 @@ public class TranslationCheckTest
|
|||
getPath("app-dev.properties"),
|
||||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslationFileWithLanguageCountryVariantIsMissing() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class);
|
||||
checkConfig.addAttribute("requiredTranslations", "es, de");
|
||||
|
||||
final File[] propertyFiles = {
|
||||
new File(getPath("messages_home.properties")),
|
||||
new File(getPath("messages_home_es_US.properties")),
|
||||
new File(getPath("messages_home_fr_CA_UNIX.properties")),
|
||||
};
|
||||
|
||||
final String[] expected = {
|
||||
"0: Properties file 'messages_home_de.properties' is missing.",
|
||||
};
|
||||
verify(
|
||||
createChecker(checkConfig),
|
||||
propertyFiles,
|
||||
getPath(""),
|
||||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslationFileWithLanguageCountryVariantArePresent() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class);
|
||||
checkConfig.addAttribute("requiredTranslations", "es, fr");
|
||||
|
||||
final File[] propertyFiles = {
|
||||
new File(getPath("messages_home.properties")),
|
||||
new File(getPath("messages_home_es_US.properties")),
|
||||
new File(getPath("messages_home_fr_CA_UNIX.properties")),
|
||||
};
|
||||
|
||||
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
verify(
|
||||
createChecker(checkConfig),
|
||||
propertyFiles,
|
||||
getPath(""),
|
||||
expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1615,11 +1615,15 @@ messages.properties: Key 'ok' missing.
|
|||
Allows to specify language codes of required translations which must exist in project.
|
||||
The check looks only for messages bundles which names contain the word 'messages'.
|
||||
Language code is composed of the lowercase, two-letter codes as defined by
|
||||
<a href="http://www.fatbellyman.com/webstuff/language_codes_639-1/">ISO 639-1</a>.
|
||||
<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a>.
|
||||
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 not perform the validation of ISO codes if the option
|
||||
is set to true. So, if you specify, for example, "mm" for language code,
|
||||
TranslationCheck will not warn about the incorrect language code and will use it
|
||||
for validation.
|
||||
</td>
|
||||
<td><a href="property_types.html#stringSet">String Set</a></td>
|
||||
<td><code>empty String Set</code></td>
|
||||
|
|
@ -1640,7 +1644,7 @@ messages.properties: Key 'ok' missing.
|
|||
</p>
|
||||
<source>
|
||||
<module name="Translation">
|
||||
<property name="basenameSeparator" value="STRING_LITERAL"/>
|
||||
<property name="basenameSeparator" value="-"/>
|
||||
</module>
|
||||
</source>
|
||||
|
||||
|
|
@ -1649,9 +1653,34 @@ messages.properties: Key 'ok' missing.
|
|||
</p>
|
||||
<source>
|
||||
<module name="Translation">
|
||||
<property name="requiredTranslations" value="ja, fr"/>
|
||||
<property name="requiredTranslations" value="ja, fr"/>
|
||||
</module>
|
||||
</source>
|
||||
<p>
|
||||
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:
|
||||
</p>
|
||||
<source>
|
||||
<module name="Translation">
|
||||
<property name="requiredTranslations" value="es, fr, de"/>
|
||||
</module>
|
||||
</source>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
As we can see from the configuration, the TranslationCheck was configured to check for
|
||||
'es', 'fr' and 'de' translations. Lets assume that we have the resource bunbdle:
|
||||
</p>
|
||||
<source>
|
||||
messages_home.properties
|
||||
messages_home_es_US.properties
|
||||
messages_home_fr_CA_UNIX.properties
|
||||
</source>
|
||||
<p>
|
||||
Than the check will rise the following violation:
|
||||
"0: Properties file 'messages_home_de.properties' is missing."
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="Example of Usage">
|
||||
|
|
|
|||
Loading…
Reference in New Issue