61 lines
2.0 KiB
Plaintext
61 lines
2.0 KiB
Plaintext
<#@ template debug="true" hostspecific="true" language="C#" #>
|
|
<#@ assembly name="System.Core" #>
|
|
<#@ assembly name="System.Text.Json" #>
|
|
<#@ assembly name="System.Memory" #>
|
|
<#@ assembly name="System" #>
|
|
<#@ import namespace="System.Text.Json" #>
|
|
<#@ import namespace="System" #>
|
|
<#@ assembly name="NetStandard" #>
|
|
<#@ import namespace="System.Linq" #>
|
|
<#@ import namespace="System.Text" #>
|
|
<#@ import namespace="System.Collections.Generic" #>
|
|
<#@ import namespace="System.IO" #>
|
|
<#@ output extension="Designer.cs" #>
|
|
<# string filename = this.Host.ResolvePath("Translations/en_US/resources.json");
|
|
var allText = File.ReadAllText(filename);
|
|
var resourceKeys = JsonSerializer.Deserialize<Dictionary<string, string>>(allText);
|
|
#>
|
|
|
|
namespace Wino.Core.Domain
|
|
{
|
|
public class Translator
|
|
{
|
|
private static global::Wino.Core.Domain.Translations.WinoTranslationDictionary _dictionary;
|
|
|
|
public static global::Wino.Core.Domain.Translations.WinoTranslationDictionary Resources
|
|
{
|
|
get
|
|
{
|
|
if (_dictionary == null)
|
|
{
|
|
_dictionary = new global::Wino.Core.Domain.Translations.WinoTranslationDictionary();
|
|
}
|
|
|
|
return _dictionary;
|
|
}
|
|
}
|
|
<#
|
|
|
|
string[] escapeChars = new string[] { " ", ";", "@", "$", "&", "(",")","-","#",":","!","'","?","{","}","," };
|
|
|
|
foreach (var key in resourceKeys)
|
|
{
|
|
// Generate proper allowed variable name by C#
|
|
var allowedPropertyName = escapeChars.Aggregate(key.Key, (c1, c2) => c1.Replace(c2, string.Empty));
|
|
|
|
// There might be null values for some keys. Those will display as (null string) in the Comment;
|
|
// The actual translation for the key will be the key itself at runtime.
|
|
var beautifiedValue = key.Value == null ? "(null string)" : key.Value;
|
|
|
|
// We need to trim the line ending literals for comments.
|
|
var beautifiedComment = beautifiedValue.Replace('\r',' ').Replace('\n',' ');
|
|
#>
|
|
|
|
/// <summary>
|
|
/// <#= beautifiedComment #>
|
|
/// </summary>
|
|
public static string <#= allowedPropertyName #> => Resources.GetTranslatedString(@"<#= key.Key #>");
|
|
<# } #>
|
|
}
|
|
}
|