Skip to content

Commit d73b879

Browse files
alan-nullmichaellwest
authored andcommitted
#1310 | Incorrect context language in script
1 parent 82bbb73 commit d73b879

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

src/Spe.Sitecore8/Services/SpeJobOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public static implicit operator SpeJobOptions(JobOptions options)
5757
{
5858
return new SpeJobOptions(options.JobName, options.Category, options.SiteName, options.Method.Object, options.Method.Method.Name)
5959
{
60-
WriteToLog = options.WriteToLog
60+
WriteToLog = options.WriteToLog,
61+
ClientLanguage = options.ClientLanguage
6162
};
6263
}
6364
}

src/Spe.Sitecore92/Services/SpeJobOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public static implicit operator SpeJobOptions(DefaultJobOptions options)
5757
{
5858
return new SpeJobOptions(options.JobName, options.Category, options.SiteName, options.Method.Object, options.Method.Method.Name)
5959
{
60-
WriteToLog = options.WriteToLog
60+
WriteToLog = options.WriteToLog,
61+
ClientLanguage = options.ClientLanguage
6162
};
6263
}
6364
}

src/Spe/Client/Applications/PowerShellRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ protected virtual void UpdateProgress(ClientPipelineArgs args)
422422
else
423423
{
424424
Subtitle.Text = showStatus
425-
? $"<span class=\'status\'>{Texts.PowerShellRunner_UpdateProgress_Status_} {status}</span>"
425+
? $"<span class=\'status\'>{Texts.PowerShellRunner_UpdateProgress_Status_.Translate()} {status}</span>"
426426
: "<span class='status'> </span>";
427427
}
428428
if (args.Parameters["RecordType"] == ProgressRecordType.Completed.ToString())
@@ -451,15 +451,15 @@ protected virtual void UpdateProgress(ClientPipelineArgs args)
451451
if (secondsRemaining > -1)
452452
sb.AppendFormat(
453453
"<span class='timeRemaining'><span class='label'>" +
454-
Texts.PowerShellRunner_UpdateProgress_Time_remaining_ +
454+
Texts.PowerShellRunner_UpdateProgress_Time_remaining_.Translate() +
455455
"</span> {0:c}</span><br/>",
456456
new TimeSpan(0, 0, 0, secondsRemaining));
457457
}
458458

459459
if (!string.IsNullOrEmpty(args.Parameters["CurrentOperation"]))
460460
{
461461
sb.AppendFormat("<span class='operation'><span class='label'>" +
462-
Texts.PowerShellRunner_UpdateProgress_Operation_ +
462+
Texts.PowerShellRunner_UpdateProgress_Operation_.Translate() +
463463
"</span> {0}</span>",
464464
args.Parameters["CurrentOperation"]);
465465
}

src/Spe/Core/Extensions/StringExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,14 @@ public static bool HasWord(this string value, params string[] words)
7979
{
8080
return words.Any(word => value.IndexOf(word, StringComparison.OrdinalIgnoreCase) > -1);
8181
}
82+
83+
public static string Translate(this string value)
84+
{
85+
if (!string.IsNullOrWhiteSpace(value))
86+
{
87+
return Sitecore.Globalization.Translate.Text(value);
88+
}
89+
return value;
90+
}
8291
}
8392
}

src/Spe/Core/Host/ScriptingHostUserInterface.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private void WriteToLog(string message, LogLevel level)
4848
{
4949
if (!IsOutputLoggingEnabled) return;
5050

51-
switch(level)
51+
switch (level)
5252
{
5353
case LogLevel.Debug:
5454
PowerShellLog.Debug(message);
@@ -63,7 +63,7 @@ private void WriteToLog(string message, LogLevel level)
6363
case LogLevel.Warning:
6464
PowerShellLog.Warn(message);
6565
break;
66-
}
66+
}
6767
}
6868

6969
/// <summary>
@@ -112,7 +112,7 @@ public override SecureString ReadLineAsSecureString()
112112
job.MessageQueue.PutMessage(new ShowMultiValuePromptMessage(options, "600", "200",
113113
"Sitecore PowerShell Extensions", " ", string.Empty, string.Empty, string.Empty, false, null, null,
114114
host.SessionKey));
115-
var values = (object[]) job.MessageQueue.GetResult() ?? new object[] {string.Empty};
115+
var values = (object[])job.MessageQueue.GetResult() ?? new object[] { string.Empty };
116116

117117
return ToSecureString(((Hashtable)values[0])["Value"] as string);
118118
}
@@ -152,7 +152,7 @@ public override void WriteLine(string value)
152152

153153
public override void WriteErrorLine(string value)
154154
{
155-
155+
156156
var splitter = new BufferSplitterCollection(OutputLineType.Error, value, RawUI.BufferSize.Width,
157157
PrivateData.ErrorForegroundColor,
158158
PrivateData.ErrorBackgroundColor, true);
@@ -176,14 +176,14 @@ public override void WriteProgress(long sourceId, ProgressRecord record)
176176
var message = Message.Parse(this, "ise:updateprogress");
177177
message.Arguments.Add("Activity", record.Activity);
178178
message.Arguments.Add("ActivityId", record.ActivityId.ToString(CultureInfo.InvariantCulture));
179-
message.Arguments.Add("CurrentOperation", record.CurrentOperation);
180-
message.Arguments.Add("StatusDescription", record.StatusDescription);
179+
message.Arguments.Add("CurrentOperation", Sitecore.Globalization.Translate.Text(record.CurrentOperation));
180+
message.Arguments.Add("StatusDescription", Sitecore.Globalization.Translate.Text(record.StatusDescription));
181181
message.Arguments.Add("ParentActivityId", record.ParentActivityId.ToString(CultureInfo.InvariantCulture));
182182
message.Arguments.Add("PercentComplete", record.PercentComplete.ToString(CultureInfo.InvariantCulture));
183183
message.Arguments.Add("RecordType", record.RecordType.ToString());
184184
message.Arguments.Add("SecondsRemaining", record.SecondsRemaining.ToString(CultureInfo.InvariantCulture));
185185
var sheerMessage = new SendMessageMessage(message, false);
186-
186+
187187
var jobManager = TypeResolver.ResolveFromCache<IJobManager>();
188188
var job = jobManager.GetContextJob();
189189
if (job != null)
@@ -224,7 +224,7 @@ public override Dictionary<string, PSObject> Prompt(string caption, string messa
224224

225225
var secureOptions = new Dictionary<string, bool>();
226226

227-
for (var i=0 ; i < descriptions.Count; i++)
227+
for (var i = 0; i < descriptions.Count; i++)
228228
{
229229
var description = descriptions[i];
230230
var isSecure = description.ParameterTypeName.Contains("SecureString");
@@ -244,13 +244,13 @@ public override Dictionary<string, PSObject> Prompt(string caption, string messa
244244
string.IsNullOrEmpty(caption) ? "Sitecore PowerShell Extensions" : caption,
245245
string.IsNullOrEmpty(message) ? " " : message, string.Empty, string.Empty, string.Empty, false,
246246
null, null, host.SessionKey));
247-
var values = (object[]) job.MessageQueue.GetResult();
247+
var values = (object[])job.MessageQueue.GetResult();
248248

249249
return values?.Cast<Hashtable>()
250250
.ToDictionary(value => value["Name"].ToString(),
251251
value =>
252252
secureOptions[value["Name"].ToString()]
253-
? PSObject.AsPSObject(ToSecureString((string) value["Value"]))
253+
? PSObject.AsPSObject(ToSecureString((string)value["Value"]))
254254
: PSObject.AsPSObject(value["Value"]));
255255
}
256256

@@ -281,7 +281,7 @@ public override PSCredential PromptForCredential(string caption, string message,
281281

282282
public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices,
283283
int defaultChoice)
284-
{
284+
{
285285
if (!CheckSessionCanDoInteractiveAction(nameof(PromptForChoice))) return -1;
286286

287287

@@ -298,14 +298,14 @@ public override int PromptForChoice(string caption, string message, Collection<C
298298
var job = jobManager.GetContextJob();
299299

300300
Context.Site = Factory.GetSite(job.Options.SiteName);
301-
var lineWidth = choices.Count*80 + 140;
302-
var strLineWidth = lineWidth/8;
301+
var lineWidth = choices.Count * 80 + 140;
302+
var strLineWidth = lineWidth / 8;
303303
var lineHeight = 0;
304304
foreach (var line in message.Split('\n'))
305305
{
306-
lineHeight += 1 + line.Length/strLineWidth;
306+
lineHeight += 1 + line.Length / strLineWidth;
307307
}
308-
lineHeight = Math.Max(lineHeight*21 + 130,150);
308+
lineHeight = Math.Max(lineHeight * 21 + 130, 150);
309309
var jobUiManager = TypeResolver.Resolve<IJobMessageManager>();
310310
var dialogResult = jobUiManager.ShowModalDialog(parameters, "ConfirmChoice",
311311
lineWidth.ToString(CultureInfo.InvariantCulture), lineHeight.ToString(CultureInfo.InvariantCulture));
@@ -339,7 +339,7 @@ public virtual bool CheckSessionCanDoInteractiveAction(string operation, bool th
339339
var message = string.IsNullOrEmpty(operation)
340340
? "Non interactive session cannot perform an interactive operation."
341341
: $"Non interactive session cannot perform an interactive '{operation}' operation.";
342-
342+
343343
PowerShellLog.Debug(message);
344344

345345
if (throwException)

0 commit comments

Comments
 (0)