/// <summary> /// Translate required component of the slip /// </summary> /// <param name="component"></param> /// <param name="location"></param> /// <returns></returns> private string GetLocalizedComponent(SlipComponent component, Locale location, Lang language) { string localePath = GetLocalePath(location); Func <string, string> getFilePath = (name) => { string result = Directory.GetFiles(localePath).FirstOrDefault(x => string.Equals(new FileInfo(x).Name, name, StringComparison.InvariantCultureIgnoreCase)); if (string.IsNullOrWhiteSpace(result)) { throw new FileNotFoundException($"{localePath}/{name}"); } return(result); }; string componentFile = getFilePath($"{component.GetCode()}.html"); string dictionaryFile = getFilePath("dictionary.json"); FileInfo fi = new FileInfo(componentFile); string html = File.ReadAllText(fi.FullName); JsonDocument doc = System.Text.Json.JsonDocument.Parse(File.ReadAllText(dictionaryFile)); JsonElement translations; if (doc.RootElement.TryGetProperty(Path.GetFileNameWithoutExtension(fi.Name), out translations)) { var dict = translations.GetProperty(language.GetDescription().ToUpper()); for (int i = 0; i < dict.GetArrayLength(); i++) { string[] split = Regex.Matches(dict[i].GetString(), @"\[.*?\]").Cast <Match>().Select(m => m.Value).ToArray(); if (split.Length == 2) { html = html.Replace(split[0].Replace("[", "$").Replace("]", "$"), split[1].Replace("[", "").Replace("]", "")); } } } return(html); }
protected Decorator(SlipComponent baseComponent) { m_BaseComponent = baseComponent; }
public DuplicateSlipDecorator(SlipComponent baseComponent) : base(baseComponent) { }