Skip to content

Commit

Permalink
Enable special parser for localized resources (#188)
Browse files Browse the repository at this point in the history
* Enable special parser for localized resources

* Add resw parser override to loc task

* Add parser to other task
  • Loading branch information
EricJohnson327 authored and cinnamon-msft committed Jul 18, 2023
1 parent 210ed19 commit 80ab83a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 48 deletions.
4 changes: 2 additions & 2 deletions build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ stages:
authId: $(TouchdownAppId)
authKey: $(TouchdownAppKey)
resourceFilePath: |
**\en-US\*.resw
**\en-US\*.resw;P:466
**\en-US\PDP.xml
outputDirectoryRoot: LocOutput
localizationTarget: true
Expand All @@ -94,7 +94,7 @@ stages:
authId: $(TouchdownAppId)
authKey: $(TouchdownAppKey)
resourceFilePath: |
**\en-US\*.resw
**\en-US\*.resw;P:466
localizationTarget: false
appendRelativeDir: true
pseudoSetting: Included
Expand Down
1 change: 1 addition & 0 deletions src/GithubPlugin/GithubPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="MessageFormat" Version="6.0.2" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.4" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.1" />
Expand Down
29 changes: 5 additions & 24 deletions src/GithubPlugin/Helpers/TimeSpanHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
using System.Text.Json.Nodes;
using DevHome.Logging;
using Jeffijoe.MessageFormat;

namespace GitHubPlugin.Helpers;
internal class TimeSpanHelper
Expand All @@ -13,42 +14,22 @@ public static string TimeSpanToDisplayString(TimeSpan timeSpan, Logger? log = nu
return Resources.GetResource("WidgetTemplate_Now", log);
}

if (timeSpan.TotalSeconds < 2)
{
return $"1 {Resources.GetResource("WidgetTemplate_SecondAgo", log)}";
}

if (timeSpan.TotalMinutes < 1)
{
return $"{timeSpan.Seconds} {Resources.GetResource("WidgetTemplate_SecondsAgo", log)}";
}

if (timeSpan.TotalMinutes < 2)
{
return $"1 {Resources.GetResource("WidgetTemplate_MinuteAgo", log)}";
return MessageFormatter.Format(Resources.GetResource("WidgetTemplate_SecondsAgo", log), new { seconds = timeSpan.Seconds });
}

if (timeSpan.TotalHours < 1)
{
return $"{timeSpan.Minutes} {Resources.GetResource("WidgetTemplate_MinutesAgo", log)}";
}

if (timeSpan.TotalHours < 2)
{
return $"1 {Resources.GetResource("WidgetTemplate_HourAgo", log)}";
return MessageFormatter.Format(Resources.GetResource("WidgetTemplate_MinutesAgo", log), new { minutes = timeSpan.Minutes });
}

if (timeSpan.TotalDays < 1)
{
return $"{timeSpan.Hours} {Resources.GetResource("WidgetTemplate_HoursAgo", log)}";
}

if (timeSpan.TotalDays < 2)
{
return $"1 {Resources.GetResource("WidgetTemplate_DayAgo", log)}";
return MessageFormatter.Format(Resources.GetResource("WidgetTemplate_HoursAgo", log), new { hours = timeSpan.Hours });
}

return $"{timeSpan.Days} {Resources.GetResource("WidgetTemplate_DaysAgo", log)}";
return MessageFormatter.Format(Resources.GetResource("WidgetTemplate_DaysAgo", log), new { days = timeSpan.Days });
}

internal static string DateTimeOffsetToDisplayString(DateTimeOffset? dateTime, Logger? log)
Expand Down
28 changes: 6 additions & 22 deletions src/GithubPlugin/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -327,42 +327,26 @@
<value>Items in widget will appear in chronological order from when the pull request or issue was last updated</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_DayAgo" xml:space="preserve">
<value>day ago</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_DaysAgo" xml:space="preserve">
<value>days ago</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_HourAgo" xml:space="preserve">
<value>hour ago</value>
<value>{days, plural, =1 {# day ago} other {# days ago}}</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_HoursAgo" xml:space="preserve">
<value>hours ago</value>
<value>{hours, plural, =1 {# hour ago} other {# hours ago}}</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_MinuteAgo" xml:space="preserve">
<value>minute ago</value>
<data name="WidgetTemplate_MinutesAgo" xml:space="preserve">
<value>{minutes, plural, =1 {# minute ago} other {# minutes ago}}</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_MinutesAgo" xml:space="preserve">
<value>minutes ago</value>
<data name="WidgetTemplate_SecondsAgo" xml:space="preserve">
<value>{seconds, plural, =1 {# second ago} other {# seconds ago}}</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_Now" xml:space="preserve">
<value>now</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_SecondAgo" xml:space="preserve">
<value>second ago</value>
<comment>Shown in Widget</comment>
</data>
<data name="WidgetTemplate_SecondsAgo" xml:space="preserve">
<value>seconds ago</value>
<comment>Shown in Widget</comment>
</data>
<data name="Widget_Template/ReviewRequestedFrom" xml:space="preserve">
<value>Review requested from</value>
<comment>Shown in Widget</comment>
Expand Down

0 comments on commit 80ab83a

Please sign in to comment.