Skip to content

Commit

Permalink
Fix localization task hints (JabRef#2031)
Browse files Browse the repository at this point in the history
* fixLocalizationTaskHint
* added prefix to each of the gradle task names
* replace system.out with asserts in localization tests
  • Loading branch information
chriba authored and zesaro committed Oct 27, 2016
1 parent d667256 commit ace0b0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ because <additional rationale>.
Add new Localization.lang("KEY") to Java file.
Tests fail. In the test output a snippet is generated which must be added to the English translation file. There is also a snippet generated for the non-English files, but this is irrelevant.
Add snippet to English translation file located at `src/main/resources/l10n/JabRef_en.properties`
With `gradlew generateMissingTranslationKeys` the "KEY" is added to the other translation files as well.
With `gradlew localizationUpdate` the "KEY" is added to the other translation files as well.
Tests are green again.

You can also directly run the specific test in your IDE. The test "LocalizationConsistencyTest" is placed under `src/test/java/net.sf.jabref.logic.l10n/LocalizationConsistencyTest.java`
Expand Down
10 changes: 5 additions & 5 deletions localization.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
jython 'org.python:jython-standalone:2.7.0'
}

task statusWithMarkdown(type: JavaExec) {
task localizationStatusWithMarkdown(type: JavaExec) {
description "Creates an update file in Markdown"
group = 'Localization'
main 'org.python.util.jython'
Expand All @@ -19,7 +19,7 @@ task statusWithMarkdown(type: JavaExec) {
args "markdown"
}

task status(type: JavaExec) {
task localizationStatus(type: JavaExec) {
description "Prints the current status"
group = 'Localization'
main 'org.python.util.jython'
Expand All @@ -28,7 +28,7 @@ task status(type: JavaExec) {
args "status"
}

task statusExtended(type: JavaExec) {
task localizationStatusExtended(type: JavaExec) {
description "Prints the current status (extended output)"
group = 'Localization'
main 'org.python.util.jython'
Expand All @@ -38,7 +38,7 @@ task statusExtended(type: JavaExec) {
args "--extended"
}

task update(type: JavaExec) {
task localizationUpdate(type: JavaExec) {
description "Updates the localization files (fixes duplicates, adds missing keys, and sort them"
group = 'Localization'
main 'org.python.util.jython'
Expand All @@ -47,7 +47,7 @@ task update(type: JavaExec) {
args "update"
}

task updateExtended(type: JavaExec) {
task localizationUpdateExtended(type: JavaExec) {
description "Updates the localization files (fixes duplicates, adds missing keys, and sort them (extended output)"
group = 'Localization'
main 'org.python.util.jython'
Expand Down
10 changes: 5 additions & 5 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ The Script has following commands available
- prints the current status to the terminal
- `[--extended]` if the translations keys which create problems should be printed
- usable with Gradle tasks
- `$ gradle status`
- `$ gradle statusExtended`
- `$ gradle localizationStatus`
- `$ gradle localizationStatusExtended`


- `$ python scripts/syncLang.py markdown`
- Creates a markdown file of the current status and opens it
- usable with Gradle tasks
- `$ gradle statusWithMarkdown`
- `$ gradle localizationStatusWithMarkdown`


- `$ python scripts/syncLang.py update [--extended]`
- compares all the localization files against the English one and fixes unambiguous duplicates, removes obsolete keys, adds missing keys, and sorts them
- `[--extended]` if the translations keys which create problems should be printed
- usable with Gradle tasks
- `$ gradle update`
- `$ gradle updateExtended`
- `$ gradle localizationUpdate`
- `$ gradle localizationUpdateExtended`
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringJoiner;
import java.util.stream.Collectors;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class LocalizationConsistencyTest {

Expand Down Expand Up @@ -124,86 +122,49 @@ public void findMissingLocalizationKeys() throws IOException {
List<LocalizationEntry> missingKeys = LocalizationParser.find(LocalizationBundle.LANG).stream().sorted()
.distinct().collect(Collectors.toList());

printInfos(missingKeys);

String resultString = missingKeys.stream().map(Object::toString).collect(Collectors.joining("\n"));
assertEquals(
"source code contains language keys for the messages which are not in the corresponding properties file",
"", resultString);
assertEquals("DETECTED LANGUAGE KEYS WHICH ARE NOT IN THE ENGLISH LANGUAGE FILE\n" +
"1. PASTE THESE INTO THE ENGLISH LANGUAGE FILE\n" +
"2. EXECUTE: gradlew localizationUpdate\n" +
missingKeys.parallelStream()
.map(key -> String.format("%s=%s", key.getKey(), key.getKey()))
.collect(Collectors.toList()),
Collections.<LocalizationEntry>emptyList(), missingKeys);
}

@Test
public void findMissingMenuLocalizationKeys() throws IOException {
List<LocalizationEntry> missingKeys = LocalizationParser.find(LocalizationBundle.MENU).stream()
.collect(Collectors.toList());

printInfos(missingKeys);

String resultString = missingKeys.stream().map(Object::toString).collect(Collectors.joining("\n"));
assertEquals(
"source code contains language keys for the menu which are not in the corresponding properties file",
"", resultString);
assertEquals("DETECTED LANGUAGE KEYS WHICH ARE NOT IN THE ENGLISH MENU FILE\n" +
"1. PASTE THESE INTO THE ENGLISH MENU FILE\n" +
"2. EXECUTE: gradlew localizationUpdate\n" +
missingKeys.parallelStream()
.map(key -> String.format("%s=%s", key.getKey(), key.getKey()))
.collect(Collectors.toList()),
Collections.<LocalizationEntry>emptyList(), missingKeys);
}

@Test
public void findObsoleteLocalizationKeys() throws IOException {
List<String> obsoleteKeys = LocalizationParser.findObsolete(LocalizationBundle.LANG);

if (!obsoleteKeys.isEmpty()) {
System.out.println();
System.out.println("Obsolete keys found:");
System.out.println(obsoleteKeys.stream().map(Object::toString).collect(Collectors.joining("\n")));
System.out.println();
System.out.println("1. CAREFULLY CHECK IF THE KEY IS REALLY NOT USED ANYMORE");
System.out.println("2. REMOVE THESE FROM THE ENGLISH LANGUAGE FILE");
System.out.println("3. EXECUTE gradlew -b localization.gradle generateMissingTranslationKeys TO");
System.out.println("REMOVE THESE FROM THE NON-ENGLISH LANGUAGE FILES");
fail("Obsolete keys " + obsoleteKeys + " found in properties file which should be removed");
}
assertEquals("Obsolete keys found in language properties file: " + obsoleteKeys + "\n" +
"1. CHECK IF THE KEY IS REALLY NOT USED ANYMORE\n" +
"2. REMOVE THESE FROM THE ENGLISH LANGUAGE FILE\n" +
"3. EXECUTE: gradlew localizationUpdate\n",
Collections.<String>emptyList(), obsoleteKeys);
}

@Test
public void findObsoleteMenuLocalizationKeys() throws IOException {
List<String> obsoleteKeys = LocalizationParser.findObsolete(LocalizationBundle.MENU);

if (!obsoleteKeys.isEmpty()) {
System.out.println();
System.out.println("Obsolete menu keys found:");
System.out.println(obsoleteKeys.stream().map(Object::toString).collect(Collectors.joining("\n")));
System.out.println();
System.out.println("1. REMOVE THESE FROM THE ENGLISH LANGUAGE FILE");
System.out.println("2. EXECUTE gradlew -b localization.gradle generateMissingTranslationKeys" + " TO");
System.out.println("REMOVE THESE FROM THE NON-ENGLISH LANGUAGE FILES");
fail("Obsolete keys " + obsoleteKeys + " found in menu properties file which should be removed");
}
}

private void printInfos(List<LocalizationEntry> missingKeys) {
if (!missingKeys.isEmpty()) {
System.out.println(convertToEnglishPropertiesFile(missingKeys));
System.out.println();
System.out.println();
System.out.println(convertPropertiesFile(missingKeys));
}
}

private String convertToEnglishPropertiesFile(List<LocalizationEntry> missingKeys) {
System.out.println("PASTE THIS INTO THE ENGLISH LANGUAGE FILE");
StringJoiner result = new StringJoiner("\n");
for (LocalizationEntry key : missingKeys) {
result.add(String.format("%s=%s", key.getKey(), key.getKey()));
}
return result.toString();
}

private String convertPropertiesFile(List<LocalizationEntry> missingKeys) {
System.out.println("EXECUTE gradlew -b localization.gradle generateMissingTranslationKeys TO");
System.out.println("PASTE THIS INTO THE NON-ENGLISH LANGUAGE FILES");
StringJoiner result = new StringJoiner("\n");
for (LocalizationEntry key : missingKeys) {
result.add(String.format("%s=", key.getKey()));
}
return result.toString();
assertEquals("Obsolete keys found in the menu properties file: " + obsoleteKeys + "\n" +
"1. CHECK IF THE KEY IS REALLY NOT USED ANYMORE\n" +
"2. REMOVE THESE FROM THE ENGLISH MENU FILE\n" +
"3. EXECUTE: gradlew localizationUpdate\n",
Collections.<String>emptyList(), obsoleteKeys);
}

}

0 comments on commit ace0b0f

Please sign in to comment.