/// <summary> /// Localizes the specified WPF element and its children. /// <para>The localization is performed according /// <see cref="InstallerRuntime.Localize(string)"/> localization behavior.</para> /// </summary> /// <returns></returns> public static InstallerRuntime Localize(this InstallerRuntime runtime, DependencyObject parent) { string translate(string text) => runtime.Localize(text.Trim('[', ']')) .TrimStart('&'); // trim buttons text "&Next" bool isLocalizable(string text) => text.StartsWith("[") && text.EndsWith("]"); parent .GetChildrenOfType <TextBlock>() .Where(x => isLocalizable(x.Text)) .ForEach(x => x.Text = translate(x.Text)); parent .GetChildrenOfType <Button>() .Where(x => isLocalizable(x.Content.ToString())) .ForEach(x => x.Content = translate(x.Content.ToString())); return(runtime); }
/// <summary> /// Localizes the specified WPF element and its children. /// <para>The localization is performed according /// <see cref="InstallerRuntime.Localize(string)"/> localization behavior.</para> /// </summary> /// <returns></returns> public static InstallerRuntime Localize(this InstallerRuntime runtime, DependencyObject parent) { bool isLocalizable(string text) => text != null && text.StartsWith("[") && text.EndsWith("]"); string translate(string text) => text.LocalizeWith(runtime.Localize) .Replace("&&", "{amp}") // clean `&Next` and `I &accept...` .Replace("&", "") .Replace("{mp}", "&"); parent .GetChildrenOfType <TextBlock>() .Where(x => isLocalizable(x.Text)) .ForEach(x => x.Text = translate(x.Text)); parent .GetChildrenOfType <ContentControl>() .Where(x => isLocalizable(x.Content?.ToString())) .ForEach(x => x.Content = translate(x.Content.ToString())); return(runtime); }