Skip to content

Commit 80b471b

Browse files
committed
Add more i18n strings
1 parent f41d9f1 commit 80b471b

File tree

12 files changed

+82
-40
lines changed

12 files changed

+82
-40
lines changed

src/main/i18n/link/infra/packwiz/installer/Msgs_en.properties

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ok = OK
22
cancel = Cancel
33
continue = Continue
4-
continueAnyways = Continue Anyways
4+
continueAnyway = Continue Anyway
55
quit = Quit
66
ignore = Ignore
77
update = Update
@@ -38,5 +38,41 @@ modName = Mod Name
3838
optionalMods = Optional Mods
3939
noOptionalMods = No Optional Mods
4040

41+
failedFileDownloads = Failed file downloads
4142
selectOption = Select an option
4243
selectFile = Select a file
44+
selectOptionalMods = Select Optional Mods
45+
46+
requireBootstrap = This program must be run through packwiz-installer-bootstrap. Use --bootstrap-no-update to disable updating.
47+
failedParseCliArg = Failed to parse command line arguments: {0}
48+
tooManyCliArg = Too many arguments specified!
49+
noPackUrlCliArg = pack.toml URI to install from must be specified!
50+
invalidHttpUrl = Invalid HTTP/HTTPS URL for pack file: {0}
51+
failedParseFilePath = Failed to parse file path for pack file: {0}
52+
invalidFilePath = Invalid pack file path: {0}
53+
invalidUrlScheme = Unsupported scheme for pack file: {0}
54+
unknownSide = Unknown side name: {0}
55+
invalidFolderPath = Invalid pack folder path
56+
invalidMultiMcPath = Invalid MultiMC folder path
57+
invalidManifestPath = Invalid manifest file path
58+
invalidTimeoutCliArg = Invalid timeout value
59+
failedUpdate = Update process failed
60+
failedUpdateDesc = Failed to download modpack, the following errors were encountered:
61+
successfulUpdate = Finished successfully!
62+
fatalError = A fatal error occurred:\
63+
{0}
64+
65+
invalidHashJsonData = Invalid hash JSON data
66+
unknownHashType = Unknown hash type: {0}
67+
failedCreateHashObj = Failed to create hash object
68+
invalidModFileHash = Invalid mod file hash
69+
linkedFileNotExist = Linked file doesn't exist!
70+
httpNoResponseBody = HTTP response in onResponse must have a response body
71+
httpRequestFailed = HTTP request failed
72+
httpInternalFatal = Internal fatal HTTP request error
73+
invalidPathNulByte = Invalid path; contains NUL bytes: {0}
74+
invalidPathVolumeLetter = Invalid path; contains volume letter: {0}
75+
failedHttpRequest = Failed to make HTTP request to {0}: {1}
76+
failedHttpNonSuccessCode = Non-successful error code from HTTP request: {0}
77+
filePathNotFound = File path not found: {0}
78+
failedReadFile = Failed to read file

src/main/java/link/infra/packwiz/installer/RequiresBootstrap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void main(String[] args) {
1919
return "";
2020
}).anyMatch(str -> str.equals("g") || str.equals("no-gui"))) {
2121
System.out.println(
22-
"This program must be run through packwiz-installer-bootstrap. Use --bootstrap-no-update to disable updating.");
22+
Msgs.getRequireBootstrap().invoke());
2323
System.exit(1);
2424
} else {
2525
try {
@@ -28,7 +28,7 @@ public static void main(String[] args) {
2828
// Ignore the exceptions, just continue using the ugly L&F
2929
}
3030
JOptionPane.showMessageDialog(null,
31-
"This program must be run through packwiz-installer-bootstrap. Use --bootstrap-no-update to disable updating.",
31+
Msgs.getRequireBootstrap().invoke(),
3232
"packwiz-installer", JOptionPane.ERROR_MESSAGE);
3333
System.exit(1);
3434
}

src/main/kotlin/link/infra/packwiz/installer/Main.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Main(args: Array<String>) {
4545
} catch (ignored: Exception) {
4646
// Ignore the exceptions, just continue using the ugly L&F
4747
}
48-
JOptionPane.showMessageDialog(null, "Failed to parse command line arguments: $e",
48+
JOptionPane.showMessageDialog(null, Msgs.failedParseCliArg(e.toString()),
4949
"packwiz-installer", JOptionPane.ERROR_MESSAGE)
5050
}
5151
}
@@ -60,9 +60,9 @@ class Main(args: Array<String>) {
6060

6161
val unparsedArgs = cmd.args
6262
if (unparsedArgs.size > 1) {
63-
ui.showErrorAndExit("Too many arguments specified!")
63+
ui.showErrorAndExit(Msgs.tooManyCliArg())
6464
} else if (unparsedArgs.isEmpty()) {
65-
ui.showErrorAndExit("pack.toml URI to install from must be specified!")
65+
ui.showErrorAndExit(Msgs.noPackUrlCliArg())
6666
}
6767

6868
val title = cmd.getOptionValue("title")
@@ -76,44 +76,44 @@ class Main(args: Array<String>) {
7676

7777
val packFile = when {
7878
// HTTP(s) URLs
79-
Regex("^https?://", RegexOption.IGNORE_CASE).containsMatchIn(packFileRaw) -> ui.wrap("Invalid HTTP/HTTPS URL for pack file: $packFileRaw") {
79+
Regex("^https?://", RegexOption.IGNORE_CASE).containsMatchIn(packFileRaw) -> ui.wrap(Msgs.invalidHttpUrl(packFileRaw)) {
8080
HttpUrlPath(packFileRaw.toHttpUrl().resolve(".")!!, packFileRaw.toHttpUrl().pathSegments.last())
8181
}
8282
// File URIs (uses same logic as old packwiz-installer, for backwards compat)
8383
Regex("^file:", RegexOption.IGNORE_CASE).containsMatchIn(packFileRaw) -> {
84-
ui.wrap("Failed to parse file path for pack file: $packFileRaw") {
84+
ui.wrap(Msgs.failedParseFilePath(packFileRaw)) {
8585
val path = Paths.get(URI(packFileRaw)).toOkioPath()
86-
PackwizFilePath(path.parent ?: ui.showErrorAndExit("Invalid pack file path: $packFileRaw"), path.name)
86+
PackwizFilePath(path.parent ?: ui.showErrorAndExit(Msgs.invalidFilePath(packFileRaw)), path.name)
8787
}
8888
}
8989
// Other URIs (unsupported)
90-
Regex("^[a-z][a-z\\d+\\-.]*://", RegexOption.IGNORE_CASE).containsMatchIn(packFileRaw) -> ui.showErrorAndExit("Unsupported scheme for pack file: $packFileRaw")
90+
Regex("^[a-z][a-z\\d+\\-.]*://", RegexOption.IGNORE_CASE).containsMatchIn(packFileRaw) -> ui.showErrorAndExit(Msgs.invalidUrlScheme(packFileRaw))
9191
// None of the above matches -> interpret as file path
92-
else -> PackwizFilePath(packFileRaw.toPath().parent ?: ui.showErrorAndExit("Invalid pack file path: $packFileRaw"), packFileRaw.toPath().name)
92+
else -> PackwizFilePath(packFileRaw.toPath().parent ?: ui.showErrorAndExit(Msgs.invalidFilePath(packFileRaw)), packFileRaw.toPath().name)
9393
}
9494
val side = cmd.getOptionValue("side")?.let {
95-
Side.from(it) ?: ui.showErrorAndExit("Unknown side name: $it")
95+
Side.from(it) ?: ui.showErrorAndExit(Msgs.unknownSide(it))
9696
} ?: Side.CLIENT
97-
val packFolder = ui.wrap("Invalid pack folder path") {
97+
val packFolder = ui.wrap(Msgs.invalidFolderPath()) {
9898
cmd.getOptionValue("pack-folder")?.let{ PackwizFilePath(it.toPath()) } ?: PackwizFilePath(".".toPath())
9999
}
100-
val multimcFolder = ui.wrap("Invalid MultiMC folder path") {
100+
val multimcFolder = ui.wrap(Msgs.invalidMultiMcPath()) {
101101
cmd.getOptionValue("multimc-folder")?.let{ PackwizFilePath(it.toPath()) } ?: PackwizFilePath("..".toPath())
102102
}
103-
val manifestFile = ui.wrap("Invalid manifest file path") {
103+
val manifestFile = ui.wrap(Msgs.invalidManifestPath()) {
104104
packFolder / (cmd.getOptionValue("meta-file") ?: "packwiz.json")
105105
}
106-
val timeout = ui.wrap("Invalid timeout value") {
106+
val timeout = ui.wrap(Msgs.invalidTimeoutCliArg()) {
107107
cmd.getOptionValue("timeout")?.toLong() ?: 10
108108
}
109109

110110
// Start update process!
111111
try {
112112
UpdateManager(UpdateManager.Options(packFile, manifestFile, packFolder, multimcFolder, side, timeout), ui)
113113
} catch (e: Exception) {
114-
ui.showErrorAndExit("Update process failed", e)
114+
ui.showErrorAndExit(Msgs.failedUpdate(), e)
115115
}
116-
println("Finished successfully!")
116+
println(Msgs.successfulUpdate())
117117
ui.dispose()
118118
}
119119

@@ -157,7 +157,7 @@ class Main(args: Array<String>) {
157157
if (guiEnabled) {
158158
EventQueue.invokeLater {
159159
JOptionPane.showMessageDialog(null,
160-
"A fatal error occurred: \n$e",
160+
Msgs.fatalError(e.toString()),
161161
"packwiz-installer", JOptionPane.ERROR_MESSAGE)
162162
exitProcess(1)
163163
}

src/main/kotlin/link/infra/packwiz/installer/metadata/IndexFile.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package link.infra.packwiz.installer.metadata
22

33
import cc.ekblad.toml.decode
44
import cc.ekblad.toml.tomlMapper
5+
import link.infra.packwiz.installer.Msgs
56
import link.infra.packwiz.installer.metadata.hash.Hash
67
import link.infra.packwiz.installer.metadata.hash.HashFormat
78
import link.infra.packwiz.installer.target.ClientHolder
@@ -42,15 +43,15 @@ data class IndexFile(
4243
linkedFile = ModFile.mapper(file).decode<ModFile>(fileStream.buffer().inputStream())
4344
if (fileHash != fileStream.hash) {
4445
// TODO: propagate details about hash, and show better error!
45-
throw Exception("Invalid mod file hash")
46+
throw Exception(Msgs.invalidModFileHash())
4647
}
4748
}
4849

4950
@Throws(Exception::class)
5051
fun getSource(clientHolder: ClientHolder): Source {
5152
return if (metafile) {
5253
if (linkedFile == null) {
53-
throw Exception("Linked file doesn't exist!")
54+
throw Exception(Msgs.linkedFileNotExist())
5455
}
5556
linkedFile!!.getSource(clientHolder)
5657
} else {

src/main/kotlin/link/infra/packwiz/installer/metadata/hash/Hash.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package link.infra.packwiz.installer.metadata.hash
22

33
import com.google.gson.*
4+
import link.infra.packwiz.installer.Msgs
45
import link.infra.packwiz.installer.metadata.hash.Hash.SourceProvider
56
import okio.ByteString
67
import okio.ByteString.Companion.decodeHex
@@ -64,12 +65,12 @@ data class Hash<T>(val type: HashFormat<T>, val value: T) {
6465
type = obj["type"].asString
6566
value = obj["value"].asString
6667
} catch (e: NullPointerException) {
67-
throw JsonParseException("Invalid hash JSON data")
68+
throw JsonParseException(Msgs.invalidHashJsonData())
6869
}
6970
return try {
70-
(HashFormat.fromName(type) ?: throw JsonParseException("Unknown hash type $type")).fromString(value)
71+
(HashFormat.fromName(type) ?: throw JsonParseException(Msgs.unknownHashType(type))).fromString(value)
7172
} catch (e: Exception) {
72-
throw JsonParseException("Failed to create hash object", e)
73+
throw JsonParseException(Msgs.failedCreateHashObj(), e)
7374
}
7475
}
7576
}

src/main/kotlin/link/infra/packwiz/installer/metadata/hash/HashFormat.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package link.infra.packwiz.installer.metadata.hash
22

33
import cc.ekblad.toml.model.TomlValue
44
import cc.ekblad.toml.tomlMapper
5+
import link.infra.packwiz.installer.Msgs
56
import link.infra.packwiz.installer.metadata.hash.Hash.Encoding
67
import link.infra.packwiz.installer.metadata.hash.Hash.SourceProvider
78
import link.infra.packwiz.installer.metadata.hash.Hash.SourceProvider.Companion.fromOkio
@@ -32,7 +33,7 @@ sealed class HashFormat<T>(val formatName: String): Encoding<T>, SourceProvider<
3233

3334
fun mapper() = tomlMapper {
3435
// TODO: better exception?
35-
decoder { it: TomlValue.String -> fromName(it.value) ?: throw Exception("Hash format ${it.value} not supported") }
36+
decoder { it: TomlValue.String -> fromName(it.value) ?: throw Exception(Msgs.unknownHashType(it.value)) }
3637
encoder { it: HashFormat<*> -> TomlValue.String(it.formatName) }
3738
}
3839
}

src/main/kotlin/link/infra/packwiz/installer/request/RequestExceptions.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package link.infra.packwiz.installer.request
22

3+
import link.infra.packwiz.installer.Msgs
34
import okio.IOException
45

56
sealed class RequestException: Exception {
@@ -17,9 +18,9 @@ sealed class RequestException: Exception {
1718
constructor(message: String, cause: Throwable) : super(message, cause)
1819
constructor(message: String) : super(message)
1920

20-
class NoResponseBody: HTTP("HTTP response in onResponse must have a response body")
21-
class RequestFailed(cause: IOException): HTTP("HTTP request failed", cause)
22-
class IllegalState(cause: IllegalStateException): HTTP("Internal fatal HTTP request error", cause)
21+
class NoResponseBody: HTTP(Msgs.httpNoResponseBody())
22+
class RequestFailed(cause: IOException): HTTP(Msgs.httpRequestFailed(), cause)
23+
class IllegalState(cause: IllegalStateException): HTTP(Msgs.httpInternalFatal(), cause)
2324
}
2425
}
2526

@@ -31,8 +32,8 @@ sealed class RequestException: Exception {
3132
constructor(message: String) : super(message)
3233

3334
// TODO: move out of RequestException?
34-
class PathContainsNUL(path: String): Validation("Invalid path; contains NUL bytes: ${path.replace("\u0000", "")}")
35-
class PathContainsVolumeLetter(path: String): Validation("Invalid path; contains volume letter: $path")
35+
class PathContainsNUL(path: String): Validation(Msgs.invalidPathNulByte(path.replace("\u0000", "")))
36+
class PathContainsVolumeLetter(path: String): Validation(Msgs.invalidPathVolumeLetter(path))
3637
}
3738

3839
/**
@@ -46,22 +47,22 @@ sealed class RequestException: Exception {
4647
sealed class HTTP: Response {
4748
val res: okhttp3.Response
4849

49-
constructor(req: okhttp3.Request, res: okhttp3.Response, message: String, cause: Throwable) : super("Failed to make HTTP request to ${req.url}: $message", cause) {
50+
constructor(req: okhttp3.Request, res: okhttp3.Response, message: String, cause: Throwable) : super(Msgs.failedHttpRequest(req.url, message), cause) {
5051
this.res = res
5152
}
52-
constructor(req: okhttp3.Request, res: okhttp3.Response, message: String) : super("Failed to make HTTP request to ${req.url}: $message") {
53+
constructor(req: okhttp3.Request, res: okhttp3.Response, message: String) : super(Msgs.failedHttpRequest(req.url, message)) {
5354
this.res = res
5455
}
5556

56-
class ErrorCode(req: okhttp3.Request, res: okhttp3.Response): HTTP(req, res, "Non-successful error code from HTTP request: ${res.code}")
57+
class ErrorCode(req: okhttp3.Request, res: okhttp3.Response): HTTP(req, res, Msgs.failedHttpNonSuccessCode(res.code))
5758
}
5859

5960
sealed class File: RequestException {
6061
constructor(message: String, cause: Throwable) : super(message, cause)
6162
constructor(message: String) : super(message)
6263

63-
class FileNotFound(file: String): File("File path not found: $file")
64-
class Other(cause: Throwable): File("Failed to read file", cause)
64+
class FileNotFound(file: String): File(Msgs.filePathNotFound(file))
65+
class Other(cause: Throwable): File(Msgs.failedReadFile(), cause)
6566
}
6667
}
6768
}

src/main/kotlin/link/infra/packwiz/installer/target/Side.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package link.infra.packwiz.installer.target
33
import cc.ekblad.toml.model.TomlValue
44
import cc.ekblad.toml.tomlMapper
55
import com.google.gson.annotations.SerializedName
6+
import link.infra.packwiz.installer.Msgs
67

78
enum class Side(sideName: String) {
89
@SerializedName("client")
@@ -42,7 +43,7 @@ enum class Side(sideName: String) {
4243

4344
fun mapper() = tomlMapper {
4445
encoder { it: Side -> TomlValue.String(it.sideName) }
45-
decoder { it: TomlValue.String -> from(it.value) ?: throw Exception("Invalid side name ${it.value}") }
46+
decoder { it: TomlValue.String -> from(it.value) ?: throw Exception(Msgs.unknownSide(it.value)) }
4647
}
4748
}
4849
}

src/main/kotlin/link/infra/packwiz/installer/ui/cli/CLIHandler.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package link.infra.packwiz.installer.ui.cli
22

3+
import link.infra.packwiz.installer.Msgs
34
import link.infra.packwiz.installer.ui.IUserInterface
45
import link.infra.packwiz.installer.ui.IUserInterface.ExceptionListResult
56
import link.infra.packwiz.installer.ui.data.ExceptionDetails
@@ -55,7 +56,7 @@ class CLIHandler : IUserInterface {
5556
}
5657

5758
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): ExceptionListResult {
58-
println("Failed to download modpack, the following errors were encountered:")
59+
println(Msgs.failedUpdateDesc())
5960
for (ex in exceptions) {
6061
print(ex.name + ": ")
6162
ex.exception.printStackTrace()

src/main/kotlin/link/infra/packwiz/installer/ui/gui/ExceptionListWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.util.concurrent.CompletableFuture
1717
import javax.swing.*
1818
import javax.swing.border.EmptyBorder
1919

20-
class ExceptionListWindow(eList: List<ExceptionDetails>, future: CompletableFuture<IUserInterface.ExceptionListResult>, numTotal: Int, allowsIgnore: Boolean, parentWindow: JFrame?) : JDialog(parentWindow, "Failed file downloads", true) {
20+
class ExceptionListWindow(eList: List<ExceptionDetails>, future: CompletableFuture<IUserInterface.ExceptionListResult>, numTotal: Int, allowsIgnore: Boolean, parentWindow: JFrame?) : JDialog(parentWindow, Msgs.failedFileDownloads(), true) {
2121
private val lblExceptionStacktrace: JTextArea
2222

2323
private class ExceptionListModel(private val details: List<ExceptionDetails>) : AbstractListModel<String>() {

0 commit comments

Comments
 (0)