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

More lagstat localization #156

Merged
merged 4 commits into from
Feb 5, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiled class file
build/
emulinker/build/
emulinker/bin/
target/
*.class

Expand Down
3 changes: 1 addition & 2 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions emulinker/src/main/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ KailleraServerImpl.TweetCloseMessage=(opponent found)
KailleraServerImpl.CanceledPendingTweet=Canceled pending tweet.

Lagstat.GameNotLaggy=The game does not appear to be significantly laggy.
Lagstat.LagstatReset=LagStat has been reset!
Lagstat.LagstatReset=LagStat has been reset\!
! Error message displayed if you run /lagstat too early after the game starts.
Lagstat.LagstatNotReady=Wait a minute or so after the game starts to run lagstat.
! Example: Total lag over the last 1.0m: 0.02s
Lagstat.TotalGameLagSummary=Total lag over the last {}: {}
Lagstat.TotalGameLagSummary=Total lag over the last {0}\: {1}
! Example: Recommendation: nue should try playing on 2f. Enter 25 in the ping spoof field when joining. If lag continues, run /lagstat again.
Lagstat.LagReductionRecommendation=Recommendation: {} should try playing on {number,integer}f. Enter {number,integer} in the ping spoof field when joining. If lag continues, run /lagstat again.
Lagstat.LagReductionRecommendation=Recommendation\: {0} should try playing on {1,number,integer}f. Enter {2,number,integer} in the ping spoof field when joining. If lag continues, run /lagstat again.

! Measurement of seconds. Examples: 0.03s, 1s
Time.SecondsAbbreviation={number}s
Time.SecondsAbbreviation={0}s
! Measurement of minutes. Examples: 0.5m, 1m
Time.MinutesAbbreviation={number}m
Time.MinutesAbbreviation={0}m
8 changes: 4 additions & 4 deletions emulinker/src/main/i18n/messages_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ Lagstat.LagstatReset=LagStat has been reset\!
! Error message displayed if you run /lagstat too early after the game starts.
Lagstat.LagstatNotReady=Wait a minute or so after the game starts to run lagstat.
! Example: Total lag over the last 1.0m: 0.02s
Lagstat.TotalGameLagSummary=Total lag over the last {}\: {}
Lagstat.TotalGameLagSummary=Total lag over the last {0}\: {1}
! Example: Recommendation: nue should try playing on 2f. Enter 25 in the ping spoof field when joining. If lag continues, run /lagstat again.
Lagstat.LagReductionRecommendation=Recommendation\: {} should try playing on {number,integer}f. Enter {number,integer} in the ping spoof field when joining. If lag continues, run /lagstat again.
Lagstat.LagReductionRecommendation=Recommendation\: {0} should try playing on {1,number,integer}f. Enter {2,number,integer} in the ping spoof field when joining. If lag continues, run /lagstat again.

! Measurement of seconds. Examples: 0.03s, 1s
Time.SecondsAbbreviation={number}s
Time.SecondsAbbreviation={0}s
! Measurement of minutes. Examples: 0.5m, 1m
Time.MinutesAbbreviation={number}m
Time.MinutesAbbreviation={0}m
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class GameChatAction(
player.resetLag()
}
game.resetLag()
game.announce("Lagstat.LagstatReset")
game.announce(EmuLang.getString("Lagstat.LagstatReset"))
} else if (
message.message.startsWith("/fps ") &&
message.message.removePrefix("/fps ").toDoubleOrNull() != null &&
Expand Down
41 changes: 25 additions & 16 deletions emulinker/src/main/java/org/emulinker/util/EmuUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.DurationUnit
import kotlin.time.DurationUnit.MINUTES
import kotlin.time.DurationUnit.SECONDS
import kotlin.time.DurationUnit.*
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.format.DateTimeComponents
Expand Down Expand Up @@ -310,22 +309,32 @@ object EmuUtil {
*
* For example: 5s in English and 5秒 in Japanese.
*/
fun Duration.toLocalizedString(unit: DurationUnit, decimals: Int = 0): String =
when (unit) {
DurationUnit.NANOSECONDS,
DurationUnit.MICROSECONDS,
DurationUnit.MILLISECONDS,
DurationUnit.HOURS,
DurationUnit.DAYS -> TODO("Unit $unit not yet supported")
SECONDS -> {
val number = this.toString(unit, decimals).removeSuffix("s")
EmuLang.getString("Time.SecondsAbbreviation", number)
fun Duration.toLocalizedString(unit: DurationUnit, decimals: Int = 0): String {
val unitSuffix =
when (unit) {
NANOSECONDS -> "ns"
MICROSECONDS -> "us"
MILLISECONDS -> "ms"
SECONDS -> "s"
MINUTES -> "m"
HOURS -> "h"
DAYS -> "d"
}
MINUTES -> {
val number = this.toString(unit, decimals).removeSuffix("m")
EmuLang.getString("Time.MinutesAbbreviation", number)

val i18nTemplate =
when (unit) {
NANOSECONDS,
MICROSECONDS,
MILLISECONDS,
HOURS,
DAYS -> TODO("Unit $unit not yet supported")
SECONDS -> "Time.SecondsAbbreviation"
MINUTES -> "Time.MinutesAbbreviation"
}
}

val number = this.toString(unit, decimals).removeSuffix(unitSuffix)
return EmuLang.getString(i18nTemplate, number)
}

// TODO(nue): Get rid of this after it's confirmed it can be safely removed.
/** NOOP placeholder for a function that _used to_ call [Thread.sleep]. */
Expand Down