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 static localized text #3400

Merged
merged 1 commit into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 12 additions & 7 deletions src/main/java/org/jabref/gui/search/SearchDisplayMode.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
package org.jabref.gui.search;

import java.util.function.Supplier;

import org.jabref.logic.l10n.Localization;

/**
* Collects the possible search modes
*/
public enum SearchDisplayMode {

FLOAT(Localization.lang("Float"), Localization.lang("Gray out non-hits")),
FILTER(Localization.lang("Filter"), Localization.lang("Hide non-hits"));
FLOAT(() -> Localization.lang("Float"), () -> Localization.lang("Gray out non-hits")),
FILTER(() -> Localization.lang("Filter"), () -> Localization.lang("Hide non-hits"));

private final String displayName;
private final String toolTipText;
private final Supplier<String> displayName;
private final Supplier<String> toolTipText;

SearchDisplayMode(String displayName, String toolTipText) {
/**
* We have to use supplier for the localized text so that language changes are correctly reflected.
*/
SearchDisplayMode(Supplier<String> displayName, Supplier<String> toolTipText) {
this.displayName = displayName;
this.toolTipText = toolTipText;
}

public String getDisplayName() {
return displayName;
return displayName.get();
}

public String getToolTipText() {
return toolTipText;
return toolTipText.get();
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/l10n/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private Localization() {
public static String lang(String key, String... params) {
if (localizedMessages == null) {
// I'm logging this because it should never happen
LOGGER.error("Messages are not initialized.");
LOGGER.error("Messages are not initialized before accessing " + key);
setLanguage("en");
}
return lookup(localizedMessages, "message", key, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;

import org.jabref.logic.l10n.Localization;

Expand All @@ -19,18 +20,16 @@

public class ProtectedTermsLoader {

private static final Map<String, String> INTERNAL_LISTS = new HashMap<>();
private static final Map<String, Supplier<String>> INTERNAL_LISTS = new HashMap<>();

private static final Log LOGGER = LogFactory.getLog(ProtectedTermsLoader.class);

private final List<ProtectedTermsList> mainList = new ArrayList<>();

static {
INTERNAL_LISTS.put("/protectedterms/months_weekdays.terms", Localization.lang("Months and weekdays in English"));
INTERNAL_LISTS.put("/protectedterms/countries_territories.terms",
Localization.lang("Countries and territories in English"));
INTERNAL_LISTS.put("/protectedterms/electrical_engineering.terms",
Localization.lang("Electrical engineering terms"));
INTERNAL_LISTS.put("/protectedterms/months_weekdays.terms", () -> Localization.lang("Months and weekdays in English"));
INTERNAL_LISTS.put("/protectedterms/countries_territories.terms", () -> Localization.lang("Countries and territories in English"));
INTERNAL_LISTS.put("/protectedterms/electrical_engineering.terms", () -> Localization.lang("Electrical engineering terms"));
}

public ProtectedTermsLoader(ProtectedTermsPreferences preferences) {
Expand All @@ -47,15 +46,15 @@ public void update(ProtectedTermsPreferences preferences) {
// Read internal lists
for (String filename : preferences.getEnabledInternalTermLists()) {
if (INTERNAL_LISTS.containsKey(filename)) {
mainList.add(readProtectedTermsListFromResource(filename, INTERNAL_LISTS.get(filename), true));
mainList.add(readProtectedTermsListFromResource(filename, INTERNAL_LISTS.get(filename).get(), true));
} else {
LOGGER.warn("Protected terms resource '" + filename + "' is no longer available.");
}
}
for (String filename : preferences.getDisabledInternalTermLists()) {
if (INTERNAL_LISTS.containsKey(filename)) {
if (!preferences.getEnabledInternalTermLists().contains(filename)) {
mainList.add(readProtectedTermsListFromResource(filename, INTERNAL_LISTS.get(filename), false));
mainList.add(readProtectedTermsListFromResource(filename, INTERNAL_LISTS.get(filename).get(), false));
}
} else {
LOGGER.warn("Protected terms resource '" + filename + "' is no longer available.");
Expand All @@ -67,7 +66,7 @@ public void update(ProtectedTermsPreferences preferences) {
if (!preferences.getEnabledInternalTermLists().contains(filename)
&& !preferences.getDisabledInternalTermLists().contains(filename)) {
// New internal list, add it
mainList.add(readProtectedTermsListFromResource(filename, INTERNAL_LISTS.get(filename), true));
mainList.add(readProtectedTermsListFromResource(filename, INTERNAL_LISTS.get(filename).get(), true));
LOGGER.warn("New protected terms resource '" + filename + "' is available and enabled by default.");
}
}
Expand Down