diff --git a/src/dotnetCampus.Localizations.Analyzer/Generators/CodeTransforming/LocalizationCodeTransformer.cs b/src/dotnetCampus.Localizations.Analyzer/Generators/CodeTransforming/LocalizationCodeTransformer.cs index 15a8ef0..3fe4952 100644 --- a/src/dotnetCampus.Localizations.Analyzer/Generators/CodeTransforming/LocalizationCodeTransformer.cs +++ b/src/dotnetCampus.Localizations.Analyzer/Generators/CodeTransforming/LocalizationCodeTransformer.cs @@ -110,6 +110,9 @@ public string ToImplementationCodeText(string rootNamespace, string ietfLanguage var code = template.Content .Replace($"namespace {template.Namespace};", $"namespace {rootNamespace}.Localizations;") .Replace($"class {nameof(LocalizationValues)}", $"class {nameof(LocalizationValues)}_{typeName}") + .Replace( + $" : ILocalized_Root", + $" : ILocalized_Root{string.Concat(EnumerateConvertTreeNodeToInterfaceNames(Tree.Children).Select(x => $",\n ILocalized_Root_{x}"))}") .Replace("""IetfLanguageTag => "default";""", $"""IetfLanguageTag => "{ietfLanguageTag}";"""); var lines = LocalizationItems.Select(x => ConvertKeyValueToValueCodeLine(x.Key, x.Value)); code = TemplateRegexes.FlagRegex.Replace(code, string.Concat(lines)); @@ -121,6 +124,26 @@ private string ConvertKeyValueToValueCodeLine(string key, string value) return $"\n {{ \"{key}\", \"{value}\" }},"; } + private IEnumerable EnumerateConvertTreeNodeToInterfaceNames(IEnumerable nodes) + { + foreach (var node in nodes) + { + if (node.Children.Count is 0) + { + // 叶子节点,不提供接口。 + } + else + { + // 非叶子节点,提供接口。 + yield return string.Join("_", node.FullIdentifierKey); + foreach (var child in EnumerateConvertTreeNodeToInterfaceNames(node.Children)) + { + yield return child; + } + } + } + } + #endregion #region Helpers