Extract translation strings.

This commit is contained in:
Matthias Mailänder
2022-08-29 20:56:25 +02:00
committed by Gustas
parent dfd5a960ed
commit 0b67b5bfae
42 changed files with 1819 additions and 410 deletions

View File

@@ -25,6 +25,78 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class ReplayBrowserLogic : ChromeLogic
{
[TranslationReference("time")]
static readonly string Duration = "duration";
[TranslationReference]
static readonly string Singleplayer = "singleplayer";
[TranslationReference]
static readonly string Multiplayer = "multiplayer";
[TranslationReference]
static readonly string Today = "today";
[TranslationReference]
static readonly string LastWeek = "last-week";
[TranslationReference]
static readonly string LastFortnight = "last-fortnight";
[TranslationReference]
static readonly string LastMonth = "last-month";
[TranslationReference]
static readonly string ReplayDurationVeryShort = "replay-duration-very-short";
[TranslationReference]
static readonly string ReplayDurationShort = "replay-duration-short";
[TranslationReference]
static readonly string ReplayDurationMedium = "replay-duration-medium";
[TranslationReference]
static readonly string ReplayDurationLong = "replay-duration-long";
[TranslationReference]
static readonly string RenameReplayTitle = "rename-replay-title";
[TranslationReference]
static readonly string RenameReplayPrompt = "rename-replay-prompt";
[TranslationReference]
static readonly string RenameReplayAccept = "rename-replay-accept";
[TranslationReference]
static readonly string DeleteReplayTitle = "delete-replay-title";
[TranslationReference("replay")]
static readonly string DeleteReplayPrompt = "delete-replay-prompt";
[TranslationReference]
static readonly string DeleteReplayAccept = "delete-replay-accept";
[TranslationReference]
static readonly string DeleteAllReplaysTitle = "delete-all-replays-title";
[TranslationReference("count")]
static readonly string DeleteAllReplaysPrompt = "delete-all-replays-prompt";
[TranslationReference]
static readonly string DeleteAllReplaysAccept = "delete-all-replays-accept";
[TranslationReference("file")]
static readonly string ReplayDeletionFailed = "replay-deletion-failed";
[TranslationReference]
static readonly string Players = "players";
[TranslationReference("team")]
static readonly string TeamNumber = "team-number";
[TranslationReference]
static readonly string NoTeam = "no-team";
static Filter filter = new Filter();
readonly Widget panel;
@@ -101,7 +173,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
var replayDuration = new CachedTransform<ReplayMetadata, string>(r =>
$"Duration: {WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds)}");
modData.Translation.GetString(Duration, Translation.Arguments("time", WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds))));
panel.Get<LabelWidget>("DURATION").GetText = () => replayDuration.Update(selectedReplay);
SetupFilters();
@@ -153,8 +225,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var options = new List<(GameType GameType, string Text)>
{
(GameType.Any, ddb.GetText()),
(GameType.Singleplayer, "Singleplayer"),
(GameType.Multiplayer, "Multiplayer")
(GameType.Singleplayer, modData.Translation.GetString(Singleplayer)),
(GameType.Multiplayer, modData.Translation.GetString(Multiplayer))
};
var lookup = options.ToDictionary(kvp => kvp.GameType, kvp => kvp.Text);
@@ -186,10 +258,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var options = new List<(DateType DateType, string Text)>
{
(DateType.Any, ddb.GetText()),
(DateType.Today, "Today"),
(DateType.LastWeek, "Last 7 days"),
(DateType.LastFortnight, "Last 14 days"),
(DateType.LastMonth, "Last 30 days")
(DateType.Today, modData.Translation.GetString(Today)),
(DateType.LastWeek, modData.Translation.GetString(LastWeek)),
(DateType.LastFortnight, modData.Translation.GetString(LastFortnight)),
(DateType.LastMonth, modData.Translation.GetString(LastMonth))
};
var lookup = options.ToDictionary(kvp => kvp.DateType, kvp => kvp.Text);
@@ -222,10 +294,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var options = new List<(DurationType DurationType, string Text)>
{
(DurationType.Any, ddb.GetText()),
(DurationType.VeryShort, "Under 5 min"),
(DurationType.Short, "Short (10 min)"),
(DurationType.Medium, "Medium (30 min)"),
(DurationType.Long, "Long (60+ min)")
(DurationType.VeryShort, modData.Translation.GetString(ReplayDurationVeryShort)),
(DurationType.Short, modData.Translation.GetString(ReplayDurationShort)),
(DurationType.Medium, modData.Translation.GetString(ReplayDurationMedium)),
(DurationType.Long, modData.Translation.GetString(ReplayDurationLong))
};
var lookup = options.ToDictionary(kvp => kvp.DurationType, kvp => kvp.Text);
@@ -393,13 +465,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var directoryName = Path.GetDirectoryName(r.FilePath);
var invalidChars = Path.GetInvalidFileNameChars();
ConfirmationDialogs.TextInputPrompt(
"Rename Replay",
"Enter a new file name:",
ConfirmationDialogs.TextInputPrompt(modData,
RenameReplayTitle,
RenameReplayPrompt,
initialName,
onAccept: newName => RenameReplay(r, newName),
onCancel: null,
acceptText: "Rename",
acceptText: RenameReplayAccept,
cancelText: null,
inputValidator: newName =>
{
@@ -421,15 +493,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Action<ReplayMetadata, Action> onDeleteReplay = (r, after) =>
{
ConfirmationDialogs.ButtonPrompt(
title: "Delete selected replay?",
text: $"Delete replay '{Path.GetFileNameWithoutExtension(r.FilePath)}'?",
ConfirmationDialogs.ButtonPrompt(modData,
title: DeleteReplayTitle,
text: DeleteReplayPrompt,
textArguments: Translation.Arguments("replay", Path.GetFileNameWithoutExtension(r.FilePath)),
onConfirm: () =>
{
DeleteReplay(r);
after?.Invoke();
},
confirmText: "Delete",
confirmText: DeleteReplayAccept,
onCancel: () => { });
};
@@ -458,9 +531,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return;
}
ConfirmationDialogs.ButtonPrompt(
title: "Delete all selected replays?",
text: $"Delete {list.Count} replays?",
ConfirmationDialogs.ButtonPrompt(modData,
title: DeleteAllReplaysTitle,
text: DeleteAllReplaysPrompt,
textArguments: Translation.Arguments("count", list.Count),
onConfirm: () =>
{
foreach (var replayMetadata in list)
@@ -469,7 +543,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (selectedReplay == null)
SelectFirstVisibleReplay();
},
confirmText: "Delete All",
confirmText: DeleteAllReplaysAccept,
onCancel: () => { });
};
}
@@ -500,7 +574,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
catch (Exception ex)
{
TextNotificationsManager.Debug("Failed to delete replay file '{0}'. See the logs for details.", replay.FilePath);
TextNotificationsManager.Debug(modData.Translation.GetString(ReplayDeletionFailed, Translation.Arguments("file", replay.FilePath)));
Log.Write("debug", ex.ToString());
return;
}
@@ -636,7 +710,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var noTeams = players.Count() == 1;
foreach (var p in players)
{
var label = noTeams ? "Players" : p.Key == 0 ? "No Team" : $"Team {p.Key}";
var label = noTeams ? modData.Translation.GetString(Players) : p.Key > 0
? modData.Translation.GetString(TeamNumber, Translation.Arguments("team", p.Key))
: modData.Translation.GetString(NoTeam);
teams.Add(label, p);
}
@@ -685,7 +762,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void WatchReplay()
{
if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay))
if (selectedReplay != null && ReplayUtils.PromptConfirmReplayCompatibility(selectedReplay, modData))
{
cancelLoadingReplays = true;