Skip to content

Commit

Permalink
[error-prone] i18n: internationalize messages in error prone plugin
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 942e588e0b432e0c9e78c14636b17ed3e4de4232
  • Loading branch information
chashnikov authored and intellij-monorepo-bot committed Oct 16, 2020
1 parent 0b4d877 commit db93586
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions error-prone/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<depends>com.intellij.modules.java</depends>
<vendor>JetBrains</vendor>

<resource-bundle>messages.ErrorProneBundle</resource-bundle>
<extensions defaultExtensionNs="com.intellij">
<java.compiler implementation="org.intellij.errorProne.ErrorProneJavaBackendCompiler"/>
<projectService serviceImplementation="org.intellij.errorProne.ErrorProneCompilerConfiguration"/>
Expand Down
4 changes: 4 additions & 0 deletions error-prone/resources/messages/ErrorProneBundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
compiler.name.javac.with.error.prone=Javac with error-prone
error.text.failed.to.download.error.prone.compiler.jars.0=Failed to download error-prone compiler JARs: {0}
error.text.no.compiler.jars.were.downloaded=No compiler JARs were downloaded
error.text.no.error.prone.compiler.versions.loaded=No error-prone compiler versions loaded
30 changes: 30 additions & 0 deletions error-prone/src/org/intellij/errorProne/ErrorProneBundle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.intellij.errorProne;

import com.intellij.DynamicBundle;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;

import java.util.function.Supplier;

public class ErrorProneBundle extends DynamicBundle {
@NonNls private static final String BUNDLE = "messages.ErrorProneBundle";
private static final ErrorProneBundle INSTANCE = new ErrorProneBundle();

private ErrorProneBundle() {
super(BUNDLE);
}

@NotNull
public static @Nls String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) {
return INSTANCE.getMessage(key, params);
}

@NotNull
public static Supplier<@Nls String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key,
Object @NotNull ... params) {
return INSTANCE.getLazyMessage(key, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean execute(@NotNull CompileContext context) {
DownloadableFileSetVersions<DownloadableFileSetDescription> versions = service.createFileSetVersions(null, getClass().getResource("/library/error-prone.xml"));
List<DownloadableFileSetDescription> descriptions = versions.fetchVersions();
if (descriptions.isEmpty()) {
context.addMessage(CompilerMessageCategory.ERROR, "No error-prone compiler versions loaded", null, -1, -1);
context.addMessage(CompilerMessageCategory.ERROR, ErrorProneBundle.message("error.text.no.error.prone.compiler.versions.loaded"), null, -1, -1);
return false;
}

Expand All @@ -42,13 +42,14 @@ public boolean execute(@NotNull CompileContext context) {
try {
List<Pair<File, DownloadableFileDescription>> pairs = service.createDownloader(latestVersion).download(cacheDir);
if (pairs.isEmpty() || ErrorProneClasspathProvider.getJarFiles(cacheDir).length == 0) {
context.addMessage(CompilerMessageCategory.ERROR, "No compiler JARs were downloaded", null, -1, -1);
context.addMessage(CompilerMessageCategory.ERROR, ErrorProneBundle.message("error.text.no.compiler.jars.were.downloaded"), null, -1, -1);
return false;
}
}
catch (IOException e) {
LOG.info(e);
context.addMessage(CompilerMessageCategory.ERROR, "Failed to download error-prone compiler JARs: " + e.getMessage(), null, -1, -1);
context.addMessage(CompilerMessageCategory.ERROR,
ErrorProneBundle.message("error.text.failed.to.download.error.prone.compiler.jars.0", e.getMessage()), null, -1, -1);
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getId() {
@NotNull
@Override
public String getPresentableName() {
return "Javac with error-prone";
return ErrorProneBundle.message("compiler.name.javac.with.error.prone");
}

@NotNull
Expand Down

0 comments on commit db93586

Please sign in to comment.