Skip to content

Commit

Permalink
Move translatable strings into a resource file
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Mar 22, 2024
1 parent a0d98b6 commit 9ed6c42
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
10 changes: 5 additions & 5 deletions BoosterManager/Boosters/BoosterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal void AddBooster(uint gameID, BoosterType type) {
void handler() {
try {
if (!BoosterInfos.TryGetValue(gameID, out Steam.BoosterInfo? boosterInfo)) {
Bot.ArchiLogger.LogGenericError(String.Format("Can't craft boosters for {0}", gameID));
Bot.ArchiLogger.LogGenericError(String.Format(Strings.BoosterUncraftable, gameID));

return;
}
Expand All @@ -118,7 +118,7 @@ void handler() {
}

if (!BoosterHandler.AllowCraftUnmarketableBoosters && !MarketableApps.AppIDs.Contains(gameID)) {
Bot.ArchiLogger.LogGenericError(String.Format("Won't craft unmarketable boosters for {0}", gameID));
Bot.ArchiLogger.LogGenericError(String.Format(Strings.BoosterUnmarketable, gameID));

return;
}
Expand Down Expand Up @@ -203,11 +203,11 @@ private void VerifyCraftBoosterError(Booster booster) {
// For any error we get, we'll need to refresh the booster page and see if the AvailableAtTime has changed to determine if we really failed to craft
void handler() {
try {
Bot.ArchiLogger.LogGenericInfo(String.Format("An error was encountered when trying to craft a booster from {0}, trying to resolve it now", booster.GameID));
Bot.ArchiLogger.LogGenericInfo(String.Format(Strings.BoosterCreationError, booster.GameID));

if (!BoosterInfos.TryGetValue(booster.GameID, out Steam.BoosterInfo? newBoosterInfo)) {
// No longer have access to craft boosters for this game (game removed from account, or sometimes due to very rare Steam bugs)
BoosterHandler.PerpareStatusReport(String.Format("No longer able to craft boosters from {0} ({1})", booster.Info.Name, booster.GameID));
BoosterHandler.PerpareStatusReport(String.Format(Strings.BoosterUnexpectedlyUncraftable, booster.Info.Name, booster.GameID));
RemoveBooster(booster.GameID);
CheckIfFinished(booster.Type);

Expand All @@ -228,7 +228,7 @@ void handler() {
return;
}

Bot.ArchiLogger.LogGenericInfo(String.Format("Booster from {0} was not created, retrying", booster.GameID));
Bot.ArchiLogger.LogGenericInfo(String.Format(Strings.BoosterCreationRetry, booster.GameID));
} finally {
OnBoosterInfosUpdated -= handler;
}
Expand Down
10 changes: 5 additions & 5 deletions BoosterManager/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,11 @@ internal static class Commands {
}

if (!uint.TryParse(appIDAsText, out uint appID)) {
return FormatBotResponse(bot, String.Format(Strings.ErrorIsInvalid, nameof(appIDAsText)));
return FormatBotResponse(bot, String.Format(ArchiSteamFarm.Localization.Strings.ErrorIsInvalid, nameof(appIDAsText)));
}

if (!ulong.TryParse(contextIDAsText, out ulong contextID)) {
return FormatBotResponse(bot, String.Format(Strings.ErrorIsInvalid, nameof(contextIDAsText)));
return FormatBotResponse(bot, String.Format(ArchiSteamFarm.Localization.Strings.ErrorIsInvalid, nameof(contextIDAsText)));
}

if (String.IsNullOrEmpty(itemIdentifierAsText)) {
Expand Down Expand Up @@ -1285,7 +1285,7 @@ internal static class Commands {
}

if (!bot.IsConnectedAndLoggedOn) {
return FormatBotResponse(bot, Strings.BotNotConnected);
return FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.BotNotConnected);
}

return await MarketHandler.RemovePendingListings(bot).ConfigureAwait(false);
Expand All @@ -1299,7 +1299,7 @@ internal static class Commands {
Bot? bot = Bot.GetBot(botName);

if (bot == null) {
return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, botName)) : null;
return access >= EAccess.Owner ? FormatStaticResponse(String.Format(ArchiSteamFarm.Localization.Strings.BotNotFound, botName)) : null;
}

return await ResponseRemovePendingListings(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID)).ConfigureAwait(false);
Expand Down Expand Up @@ -1379,7 +1379,7 @@ internal static class Commands {

(bool success, string message) = await bot.Actions.SendInventory(appID: appID, contextID: contextID, targetSteamID: targetSteamID, filterFunction: item => itemIdentifiers.Any(itemIdentifier => itemIdentifier.IsItemMatch(item))).ConfigureAwait(false);

return FormatBotResponse(bot, success ? message : String.Format(Strings.WarningFailedWithError, message));
return FormatBotResponse(bot, success ? message : String.Format(ArchiSteamFarm.Localization.Strings.WarningFailedWithError, message));
}

private static async Task<string?> ResponseSendItemToBot(EAccess access, ulong steamID, string senderBotNames, ItemIdentifier itemIdentifier, bool? marketable = null, string? recieverBotName = null) {
Expand Down
12 changes: 8 additions & 4 deletions BoosterManager/Handlers/InventoryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ internal static async Task<string> GetItemCount(Bot bot, uint appID, ulong conte
inventory = await bot.ArchiWebHandler.GetInventoryAsync(appID: appID, contextID: contextID).Where(item => itemIdentifier.IsItemMatch(item)).ToHashSetAsync().ConfigureAwait(false);
} catch (Exception e) {
bot.ArchiLogger.LogGenericException(e);
return Commands.FormatBotResponse(bot, Strings.WarningFailed);
return Commands.FormatBotResponse(bot, ArchiSteamFarm.Localization.Strings.WarningFailed);
}

(uint tradable, uint untradable) items = (0,0);
Expand All @@ -219,9 +219,13 @@ internal static async Task<string> GetItemCount(Bot bot, uint appID, ulong conte
}
}

return Commands.FormatBotResponse(bot, String.Format("Tradable: {0:N0}{1}", items.tradable,
(items.untradable) == 0 ? "" : String.Format("; Untradable: {0:N0}", items.untradable))
);
string response = String.Format(Strings.ItemsCountTradable, String.Format("{0:N0}", items.tradable));

if (items.untradable > 0) {
response += String.Format("; {0}", String.Format(Strings.ItemsCountUntradable, String.Format("{0:N0}", items.untradable)));
}

return Commands.FormatBotResponse(bot, response);
}
}
}
12 changes: 6 additions & 6 deletions BoosterManager/Handlers/MarketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ internal static async Task<string> RemovePendingListings(Bot bot) {
(Steam.MarketListingsResponse? marketListings, _) = await WebRequest.GetMarketListings(bot).ConfigureAwait(false);

if (marketListings == null || marketListings.ListingsToConfirm == null || !marketListings.Success) {
return "Failed to load Market Listings";
return Strings.MarketListingsFetchFailed;
}

if (marketListings.ListingsToConfirm.Count == 0) {
return "No pending market listings found";
return Strings.PendingListingsNotFound;
}

HashSet<ulong> pendingListingIDs = new();
Expand All @@ -108,14 +108,14 @@ internal static async Task<string> RemovePendingListings(Bot bot) {
if (listing == null) {
bot.ArchiLogger.LogNullError(listing);

return "Failed to load Market Listings";
return Strings.MarketListingsFetchFailed;
}

ulong? listingid = listing["listingid"]?.ToString().ToJsonObject<ulong>();
if (listingid == null) {
bot.ArchiLogger.LogNullError(listingid);

return "Failed to load Market Listings";
return Strings.MarketListingsFetchFailed;
}

pendingListingIDs.Add(listingid.Value);
Expand All @@ -131,10 +131,10 @@ internal static async Task<string> RemovePendingListings(Bot bot) {
}

if (failedToRemove != 0) {
return String.Format("Successfully removed {0} pending market listings, failed to remove {1} listings", pendingListingIDs.Count - failedToRemove, failedToRemove);
return String.Format(Strings.PendingListingsRemovedFailed, pendingListingIDs.Count - failedToRemove, failedToRemove);
}

return String.Format("Successfully removed {0} pending market listings", pendingListingIDs.Count);
return String.Format(Strings.PendingListingsRemovedSuccess, pendingListingIDs.Count);
}

internal static async Task<string> FindAndRemoveListings(Bot bot, List<ItemIdentifier> itemIdentifiers) {
Expand Down
16 changes: 16 additions & 0 deletions BoosterManager/Localization/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,20 @@
<value>Bot has {0} incoming trades</value>
<comment>{0} will be replaced by a number</comment>
</data>
<data name="PendingListingsNotFound" xml:space="preserve">
<value>No pending market listings found</value>
<comment/>
</data>
<data name="PendingListingsRemovedFailed" xml:space="preserve">
<value>Successfully removed {0} pending market listings, failed to remove {1} listings</value>
<comment>{0} will be replaced by a number, {1} will be replaced by a number</comment>
</data>
<data name="PendingListingsRemovedSuccess" xml:space="preserve">
<value>Successfully removed {0} pending market listings</value>
<comment>{0} will be replaced by a number</comment>
</data>
<data name="BoosterUnmarketable" xml:space="preserve">
<value>Won't craft unmarketable boosters for {0}</value>
<comment>{0} will be replaced by an appID</comment>
</data>
</root>

0 comments on commit 9ed6c42

Please sign in to comment.