Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix localization task hints #2031

Merged
merged 4 commits into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.EMPTY_LIST, missingKeys);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collections.emptyList() is the preferred way to access it (don't ask me why).

Copy link
Contributor Author

@chriba chriba Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage of Collections.EMPTY_LIST is that this list is immutable.
Collections.emptyList() is also immutable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collections.emptyList() is better because it is a generic implementatin! The constant is not generic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's also immuntable: https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#emptyList--
(Unlike this method, the field does not provide type safety.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I changed the lists.

}

@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.EMPTY_LIST, 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.EMPTY_LIST, 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.EMPTY_LIST, obsoleteKeys);
}

}