Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #85 from zanata/remove_underscore
Browse files Browse the repository at this point in the history
Fix warning "Use of '_' might not be supported..."
  • Loading branch information
seanf committed Feb 25, 2016
2 parents e1a0bba + 6ff1248 commit 4651b86
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.google.common.base.Strings;

import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;

public interface ConsoleInteractor {
/**
Expand Down Expand Up @@ -69,7 +69,7 @@ public boolean isAnswerValid(String answer) {

@Override
public String invalidErrorMessage(String answer) {
return String.format(_("expected.and.actual.answer"), "y or n",
return String.format(get("expected.and.actual.answer"), "y or n",
answer);
}
};
Expand All @@ -81,7 +81,7 @@ public boolean isAnswerValid(String answer) {

@Override
public String invalidErrorMessage(String answer) {
return _("no.blank.answer");
return get("no.blank.answer");
}
};
static final AnswerValidator ANY = new AnswerValidator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.google.common.collect.Lists;

import static org.zanata.client.commands.StringUtil.indent;
import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;

/**
* @author Patrick Huang <a
Expand Down Expand Up @@ -74,7 +74,7 @@ public String expectAnswerWithRetry(AnswerValidator answersValidator) {
return line;
} else {
printfln(DisplayMode.Warning, answersValidator.invalidErrorMessage(line));
printf(_("re-enter.prompt"));
printf(get("re-enter.prompt"));
return expectAnswerWithRetry(answersValidator);
}
}
Expand Down Expand Up @@ -188,10 +188,10 @@ public String invalidErrorMessage(String answer) {
String expected =
Iterables.toString(expectedAnswers);
if (expected.length() < 200) {
return String.format(_("expected.and.actual.answer"),
return String.format(get("expected.and.actual.answer"),
expectedAnswers, answer);
} else {
return String.format(_("invalid.answer"), answer);
return String.format(get("invalid.answer"), answer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class Messages {

private static ResourceBundle bundle = ResourceBundle.getBundle("prompts");

public static String _(String key) {
public static String get(String key) {
if (bundle.containsKey(key)) {
return bundle.getString(key);
}
Expand All @@ -48,7 +48,7 @@ public static String _(String key) {
}

public static String format(String key, Object... args) {
String template = _(key);
String template = get(key);
return MessageFormat.format(template, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Warning;
import static org.zanata.client.commands.FileMappingRuleHandler.*;
import static org.zanata.client.commands.FileMappingRuleHandler.Placeholders.allHolders;
import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;

public class OptionsUtil {
private static final Logger log = LoggerFactory
Expand Down Expand Up @@ -71,7 +71,8 @@ public static void applyConfigFiles(ConfigurableOptions opts)
&& !projectConfig.getLocales().isEmpty();
if (localesDefinedInFile) {
ConsoleInteractorImpl console = new ConsoleInteractorImpl(opts);
console.printfln(Warning, _("locales.in.config.deprecated"));
console.printfln(Warning, get(
"locales.in.config.deprecated"));
} else {
shouldFetchLocalesFromServer = true;
}
Expand Down Expand Up @@ -171,18 +172,18 @@ protected static void checkPotentialMistakesInRules(
for (FileMappingRule mappingRule : opts.getFileMappingRules()) {
String rule = mappingRule.getRule();
if (!isRuleValid(rule)) {
console.printfln(Warning, _("invalid.rule"), rule);
console.printfln(Warning, get("invalid.rule"), rule);
invalid = true;
}
if (ruleMayHaveProblem(rule)) {
console.printfln(Warning, _("unrecognized.variables"),
console.printfln(Warning, get("unrecognized.variables"),
allHolders(), rule);
potentialProblem = true;
}
}
Preconditions.checkState(!invalid);
if (potentialProblem && opts.isInteractiveMode()) {
console.printfln(Question, _("confirm.rule"));
console.printfln(Question, get("confirm.rule"));
console.expectYes();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.Map;

import static com.google.common.base.Preconditions.checkState;
import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;

/**
* Resolve translation file destination. It will first try to apply file mapping
Expand Down Expand Up @@ -128,7 +128,7 @@ private File getDefaultTransFileFromProjectType(
QualifiedSrcDocName qualifiedSrcDocName, LocaleMapping localeMapping,
ProjectType projectType, Optional<String> translationFileExtension) {
FileMappingRule rule = PROJECT_TYPE_FILE_MAPPING_RULES.get(projectType);
checkState(rule != null, _("no.default.mapping"), projectType);
checkState(rule != null, get("no.default.mapping"), projectType);
String relativePath = new FileMappingRuleHandler(rule, projectType, opts)
.getRelativeTransFilePathForSourceDoc(qualifiedSrcDocName,
localeMapping, translationFileExtension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package org.zanata.client.commands;

import static org.zanata.client.commands.ConsoleInteractorImpl.AnswerValidator;
import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;
import static org.zanata.util.VersionUtility.getVersionInfo;

import java.io.BufferedWriter;
Expand Down Expand Up @@ -103,8 +103,8 @@ public boolean needToCheckUpdates(boolean interactiveMode) {
try {
if (!updateMarker.exists()) {
createUpdateMarkerFile(updateMarker);
console.printfln(_("update.marker.created"), updateMarker);
console.printfln(_("update.marker.hint"));
console.printfln(get("update.marker.created"), updateMarker);
console.printfln(get("update.marker.hint"));
return true;
}
// read the content and see if we need to check
Expand All @@ -115,7 +115,7 @@ public boolean needToCheckUpdates(boolean interactiveMode) {
boolean timeToCheck = daysPassed.compareTo(frequency.days()) >= 0;
boolean noAsking = readNoAsking(props);
if (timeToCheck && !noAsking && interactiveMode) {
console.printf(_("check.update.yes.no"), daysPassed.getDays());
console.printf(get("check.update.yes.no"), daysPassed.getDays());
String check = console.expectAnswerWithRetry(
AnswerValidator.YES_NO);
if (check.toLowerCase().startsWith("n")) {
Expand Down Expand Up @@ -159,15 +159,15 @@ private static Properties loadFileToProperties(File updateMarker) {
private static void createUpdateMarkerFile(File updateMarker)
throws IOException {
boolean created = updateMarker.createNewFile();
Preconditions.checkState(created, _("create.file.failure"),
Preconditions.checkState(created, get("create.file.failure"),
updateMarker);
String today = DATE_FORMATTER.print(new DateTime());
Properties props = new Properties();
props.setProperty(LAST_CHECKED, today);
props.setComment(FREQUENCY, _("valid.frequency"));
props.setComment(FREQUENCY, get("valid.frequency"));
props.setProperty(FREQUENCY, "weekly");
props.setProperty(NO_ASKING, "true");
props.setComment(NO_ASKING, _("no.check.update.prompt"));
props.setComment(NO_ASKING, get("no.check.update.prompt"));
props.store(new BufferedWriter(new FileWriterWithEncoding(updateMarker,
Charsets.UTF_8)), null);
}
Expand All @@ -178,9 +178,9 @@ public void checkNewerVersion() {
return;
}
if (latestVersion.get().compareTo(currentVersionNo) > 0) {
console.printfln(_("suggest.update"), latestVersion.get());
console.printfln(get("suggest.update"), latestVersion.get());
} else {
console.printfln(_("latest.version.confirm"));
console.printfln(get("latest.version.confirm"));
}
try {
Properties props = loadFileToProperties(updateMarker);
Expand Down Expand Up @@ -220,12 +220,12 @@ private Optional<String> checkLatestVersion(ConsoleInteractor console) {
log.debug(
"Failed to resolve latest client artifact [status {}]. Ignored",
response.getStatus());
console.printfln(_("check.update.failed"));
console.printfln(get("check.update.failed"));
return Optional.absent();
}
} catch (Exception e) {
log.warn("Exception when checking updates", e);
console.printfln(_("check.update.failed"));
console.printfln(get("check.update.failed"));
return Optional.absent();
}
// cheap xml parsing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Hint;
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Question;
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Warning;
import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -142,42 +142,42 @@ protected void ensureServerVersion() {
getClientFactory().getServerVersionInfo().getVersionNo();

if (new VersionComparator().compare(serverVersion, "3.4.0") < 0) {
console.printfln(Warning, _("server.incompatible"));
console.printfln(Hint, _("server.incompatible.hint"));
throw new RuntimeException(_("server.incompatible"));
console.printfln(Warning, get("server.incompatible"));
console.printfln(Hint, get("server.incompatible.hint"));
throw new RuntimeException(get("server.incompatible"));
}
}

private void displayAdviceAboutWhatIsNext(boolean hasOldConfig) {
console.printfln(_("what.next"));
console.printfln(get("what.next"));
if (hasOldConfig) {
console.printfln(_("compare.project.config"),
console.printfln(get("compare.project.config"),
projectConfigHandler.getBackup());
}
console.printfln(_("view.project"),
console.printfln(get("view.project"),
getProjectIterationUrl(getOpts().getUrl(), getOpts().getProj(),
getOpts().getProjectVersion()));
if (isInvokedByMaven()) {
console.printfln(_("mvn.push.source"));
console.printfln(_("mvn.push.both"));
console.printfln(_("mvn.push.trans"));
console.printfln(_("mvn.help"));
console.printfln(get("mvn.push.source"));
console.printfln(get("mvn.push.both"));
console.printfln(get("mvn.push.trans"));
console.printfln(get("mvn.help"));
} else {
console.printfln(_("cli.push.source"));
console.printfln(_("cli.push.both"));
console.printfln(_("cli.push.trans"));
console.printfln(_("cli.help"));
console.printfln(get("cli.push.source"));
console.printfln(get("cli.push.both"));
console.printfln(get("cli.push.trans"));
console.printfln(get("cli.help"));
}
console.printfln(_("browse.online.help"));
console.printfln(get("browse.online.help"));
}

private void advancedSettingsReminder() {
ConfigurableProjectOptions opts = getOpts();
console.printfln(Warning, _("customize.languages.warning"));
console.printfln(Hint, _("view.project"),
console.printfln(Warning, get("customize.languages.warning"));
console.printfln(Hint, get("view.project"),
getProjectIterationUrl(opts.getUrl(), opts.getProj(),
opts.getProjectVersion()));
console.printf(Question, _("continue.yes.no"));
console.printf(Question, get("continue.yes.no"));
console.expectYes();
}

Expand All @@ -191,7 +191,7 @@ private void applyConfigFileSilently()
OptionsUtil.applyConfigFiles(opts);
logger.setLevel(preLevel);
console.printfln(
Confirmation, _("project.version.type.confirmation"),
Confirmation, get("project.version.type.confirmation"),
opts.getProjectType(), opts.getProj(), opts
.getProjectVersion());
}
Expand All @@ -209,9 +209,9 @@ private static String getProjectIterationUrl(URL server, String projectSlug,

public static void offerRetryOnServerError(Exception e,
ConsoleInteractor consoleInteractor) {
consoleInteractor.printfln(Warning, _("server.error"),
consoleInteractor.printfln(Warning, get("server.error"),
Throwables.getRootCause(e).getMessage());
consoleInteractor.printf(Question, _("server.error.try.again"));
consoleInteractor.printf(Question, get("server.error.try.again"));
consoleInteractor.expectYes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Confirmation;
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Question;
import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Warning;
import static org.zanata.client.commands.Messages._;
import static org.zanata.client.commands.Messages.get;

/**
* @author Patrick Huang
Expand All @@ -59,8 +59,8 @@ protected void handleExistingProjectConfig() throws IOException {
File projectConfig = getOpts().getProjectConfig();
if (projectConfig.exists()) {
consoleInteractor
.printfln(Warning, _("project.config.exists"))
.printf(Question, _("continue.yes.no"));
.printfln(Warning, get("project.config.exists"))
.printf(Question, get("continue.yes.no"));
consoleInteractor.expectYes();
// back up old zanata.xml
String suffix = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(
Expand All @@ -69,7 +69,7 @@ protected void handleExistingProjectConfig() throws IOException {
"zanata.xml." + suffix);
FileUtils.moveFile(projectConfig, backup);
consoleInteractor
.printfln(Confirmation, _("backup.old.project.config"), backup);
.printfln(Confirmation, get("backup.old.project.config"), backup);

clearValuesSetByConfigurableMojo();
}
Expand Down
Loading

0 comments on commit 4651b86

Please sign in to comment.