<#@ 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>(allText); #> namespace Wino.Domain { public class Translator { private static global::Wino.Domain.Translations.WinoTranslationDictionary _dictionary; public static global::Wino.Domain.Translations.WinoTranslationDictionary Resources { get { if (_dictionary == null) { _dictionary = new global::Wino.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',' '); #> /// /// <#= beautifiedComment #> /// public static string <#= allowedPropertyName #> => Resources.GetTranslatedString(@"<#= key.Key #>"); <# } #> } }