Skip to content

Commit

Permalink
Fix resource name area prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Sep 21, 2020
1 parent b88664b commit 012f87b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ThisAssembly.Strings/CSharp.sbntxt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{{~ for value in $0.Values ~}}
{{~ if!(value.HasFormat) ~}}
{{- summary value ~}}
public static string {{ value.Name }} => Strings.GetResourceManager("{{ $1 }}").GetString("{{ value.Prefix + value.Name }}");
public static string {{ value.Name }} => Strings.GetResourceManager("{{ $1 }}").GetString("{{ $0.Prefix + value.Name }}");
{{~ else ~}}
{{~ if value.IsIndexedFormat ~}}
{{- summary value ~}}
Expand All @@ -32,7 +32,7 @@
{{- end -}})
=> string.Format(
CultureInfo.CurrentCulture,
Strings.GetResourceManager("{{ $1 }}").GetString("{{ value.Prefix + value.Name }}"),
Strings.GetResourceManager("{{ $1 }}").GetString("{{ $0.Prefix + value.Name }}"),
{{ for arg in value.Format -}}
arg{{- arg -}}{{- if !for.last -}}, {{ end }}{{- end -}});
{{~ else if value.IsNamedFormat ~}}
Expand All @@ -45,7 +45,7 @@
CultureInfo.CurrentCulture,
Strings
.GetResourceManager("{{ $1 }}")
.GetString("{{ value.Prefix + value.Name }}")
.GetString("{{ $0.Prefix + value.Name }}")
{{- for arg in value.Format }}
.Replace("{{ arg }}", "{{ for.index }}"){{- end -}},
{{ for arg in value.Format -}}
Expand Down
9 changes: 9 additions & 0 deletions src/ThisAssembly.Tests/Rendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ namespace ThisAssemblyTests
{
public class Rendering
{
public void LoadAndRender()
{
var root = ResourceFile.Load(@"Resources.resx", "Strings");
var model = new Model(root, "MyAssembly.Resources");
var template = Template.Parse(File.ReadAllText("CSharp.sbntxt"));

Console.WriteLine(template.Render(model, member => member.Name));
}

public void Render()
{
var template = Template.Parse(File.ReadAllText("CSharp.sbntxt"));
Expand Down
6 changes: 6 additions & 0 deletions src/ThisAssembly.Tests/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Foo_Bar_Baz" xml:space="preserve">
<value>Value</value>
</data>
<data name="Foo_Hey" xml:space="preserve">
<value>Hey</value>
</data>
<data name="Indexed" xml:space="preserve">
<value>Hello {0}, {1}. Should we call you {0}?</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator></Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

Expand Down

0 comments on commit 012f87b

Please sign in to comment.