From 112d78dd200c63b85e0de75c8b646898cbae55d0 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 9 Oct 2024 18:46:27 -0700 Subject: [PATCH] Support additional pluralization forms --- pkg/server/client.go | 2 +- pkg/server/database.go | 1 + pkg/server/locales/bgammon.pot | 27 ++++++++++++++++----------- pkg/server/server.go | 9 +++------ pkg/server/server_command.go | 8 ++++---- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pkg/server/client.go b/pkg/server/client.go index b49408b..71374ea 100644 --- a/pkg/server/client.go +++ b/pkg/server/client.go @@ -210,7 +210,7 @@ func (c *serverClient) sendEvent(e interface{}) { case *bgammon.EventFailedOk: c.Write([]byte(fmt.Sprintf("failedok %s", ev.Reason))) case *bgammon.EventWin: - if ev.Points != 0 { + if ev.Points > 1 { c.Write([]byte(fmt.Sprintf("win %s wins %d points!", ev.Player, ev.Points))) } else { c.Write([]byte(fmt.Sprintf("win %s wins!", ev.Player))) diff --git a/pkg/server/database.go b/pkg/server/database.go index 6c515df..b5aa477 100644 --- a/pkg/server/database.go +++ b/pkg/server/database.go @@ -697,6 +697,7 @@ func recordMatchResult(g *serverGame, matchType int) (int, error) { g.client2.account.competitive.setRating(g.Variant, g.Points > 1, int(rating2New*100)) } } + delta := rating1New - rating1 if delta <= 0 { delta = rating2New - rating2 diff --git a/pkg/server/locales/bgammon.pot b/pkg/server/locales/bgammon.pot index 9d810bf..ccee516 100644 --- a/pkg/server/locales/bgammon.pot +++ b/pkg/server/locales/bgammon.pot @@ -7,8 +7,10 @@ msgstr "" "Language: \n" "X-Generator: xgotext\n" -msgid "%s (%d points)" -msgstr "" +msgid "%[1]s (%[2]d point)" +msgid_plural "%[1]s (%[2]d points)" +msgstr[0] "" +msgstr[1] "" msgid "%s accepted double." msgstr "" @@ -22,8 +24,10 @@ msgstr "" msgid "%s is online." msgstr "" -msgid "%s offers a double (%d points)." -msgstr "" +msgid "%[1]s offers a double (%[2]d point)." +msgid_plural "%[1]s offers a double (%[2]d points)." +msgstr[0] "" +msgstr[1] "" msgid "%s resigned." msgstr "" @@ -49,8 +53,10 @@ msgstr "" msgid "Declined double offer." msgstr "" -msgid "Double offered to opponent (%d points)." -msgstr "" +msgid "Double offered to opponent (%d point)." +msgid_plural "Double offered to opponent (%d points)." +msgstr[0] "" +msgstr[1] "" msgid "Due to ongoing abuse, registration is disabled. Please try again later." msgstr "" @@ -166,11 +172,10 @@ msgstr "" msgid "The server is shutting down. Reason:" msgstr "" -msgid "The server is shutting down in 1 minute. Reason:" -msgstr "" - -msgid "The server is shutting down in %d minutes. Reason:" -msgstr "" +msgid "The server is shutting down in %d minute. Reason:" +msgid_plural "The server is shutting down in %d minutes. Reason:" +msgstr[0] "" +msgstr[1] "" msgid "Unknown command: %s" msgstr "" diff --git a/pkg/server/server.go b/pkg/server/server.go index ce70f21..04fa037 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -571,13 +571,10 @@ func (s *server) handleShutdown() { s.clientsLock.Lock() for _, sc := range s.clients { - switch minutes { - case 0: + if minutes == 0 { sc.sendBroadcast(gotext.GetD(sc.language, "The server is shutting down. Reason:")) - case 1: - sc.sendBroadcast(gotext.GetD(sc.language, "The server is shutting down in 1 minute. Reason:")) - default: - sc.sendBroadcast(gotext.GetD(sc.language, "The server is shutting down in %d minutes. Reason:", minutes)) + } else { + sc.sendBroadcast(gotext.GetND(sc.language, "The server is shutting down in %d minute. Reason:", "The server is shutting down in %d minutes. Reason:", minutes, minutes)) } sc.sendBroadcast(s.shutdownReason) sc.sendBroadcast(gotext.GetD(sc.language, "Please finish your match as soon as possible.")) diff --git a/pkg/server/server_command.go b/pkg/server/server_command.go index f9d9a85..9667378 100644 --- a/pkg/server/server_command.go +++ b/pkg/server/server_command.go @@ -282,7 +282,7 @@ func (s *server) handleFirstCommand(cmd serverCommand, keyword string, params [] g.addClient(cmd.client) matchName := string(g.name) if g.Points > 1 { - matchName = gotext.GetD(cmd.client.language, "%s (%d points)", g.name, g.Points) + matchName = gotext.GetND(cmd.client.language, "%[1]s (%[2]d point)", "%[1]s (%[2]d points)", int(g.Points), g.name, g.Points) } cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Rejoined match: %s", matchName)) } @@ -612,7 +612,7 @@ COMMANDS: s.gamesLock.Unlock() matchName := string(g.name) if g.Points > 1 { - matchName = gotext.GetD(cmd.client.language, "%s (%d points)", g.name, g.Points) + matchName = gotext.GetND(cmd.client.language, "%[1]s (%[2]d point)", "%[1]s (%[2]d points)", int(g.Points), g.name, g.Points) } cmd.client.sendNotice(fmt.Sprintf(gotext.GetD(cmd.client.language, "Joined match: %s"), matchName)) if spectator { @@ -678,8 +678,8 @@ COMMANDS: clientGame.DoubleOffered = true clientGame.NextPartialTurn(opponent.playerNumber) - cmd.client.sendNotice(fmt.Sprintf(gotext.GetD(cmd.client.language, "Double offered to opponent (%d points)."), clientGame.DoubleValue*2)) - clientGame.opponent(cmd.client).sendNotice(fmt.Sprintf(gotext.GetD(clientGame.opponent(cmd.client).language, "%s offers a double (%d points)."), cmd.client.name, clientGame.DoubleValue*2)) + cmd.client.sendNotice(gotext.GetND(cmd.client.language, "Double offered to opponent (%d point).", "Double offered to opponent (%d points).", int(clientGame.DoubleValue*2), clientGame.DoubleValue*2)) + clientGame.opponent(cmd.client).sendNotice(fmt.Sprintf(gotext.GetND(clientGame.opponent(cmd.client).language, "%s offers a double (%d point).", "%s offers a double (%d points).", int(clientGame.DoubleValue*2)), cmd.client.name, clientGame.DoubleValue*2)) clientGame.eachClient(func(client *serverClient) { if client.json {