From d315a0c9f5bd244eb72c88c0c4753c7224e3cd02 Mon Sep 17 00:00:00 2001 From: JasonGrass Date: Mon, 27 Oct 2025 16:55:47 +0800 Subject: [PATCH] =?UTF-8?q?toml=20=E6=88=96=20yaml=20=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=97=B6=EF=BC=8C=E4=B8=BB=E5=8A=A8=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E7=BC=96=E8=AF=91=E5=BC=82=E5=B8=B8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Generators/StringsGenerator.cs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/dotnetCampus.Localizations.Analyzer/Generators/StringsGenerator.cs b/src/dotnetCampus.Localizations.Analyzer/Generators/StringsGenerator.cs index c1139d7..69659e2 100644 --- a/src/dotnetCampus.Localizations.Analyzer/Generators/StringsGenerator.cs +++ b/src/dotnetCampus.Localizations.Analyzer/Generators/StringsGenerator.cs @@ -58,22 +58,31 @@ private void Execute(SourceProductionContext context, ((AnalyzerConfigOptionsPro foreach (var pair in allLocalizationModels) { var (ietfLanguageTag, group) = (pair.Key, pair.Value); - var transformer = new LocalizationCodeTransformer(group); - var code = transformer.ToProviderCodeText(localizationType.Namespace, ietfLanguageTag); - context.AddSource($"Strings.{ietfLanguageTag}.g.cs", SourceText.From(code, Encoding.UTF8)); - - if (string.Equals(ietfLanguageTag, referenceLanguageTag, StringComparison.OrdinalIgnoreCase)) + try { - var interfaceCode = transformer.ToInterfaceCodeText(localizationType); - context.AddSource($"{nameof(ILocalizedValues)}.g.cs", SourceText.From(interfaceCode, Encoding.UTF8)); + var transformer = new LocalizationCodeTransformer(group); + + var code = transformer.ToProviderCodeText(localizationType.Namespace, ietfLanguageTag); + context.AddSource($"Strings.{ietfLanguageTag}.g.cs", SourceText.From(code, Encoding.UTF8)); + + if (string.Equals(ietfLanguageTag, referenceLanguageTag, StringComparison.OrdinalIgnoreCase)) + { + var interfaceCode = transformer.ToInterfaceCodeText(localizationType); + context.AddSource($"{nameof(ILocalizedValues)}.g.cs", SourceText.From(interfaceCode, Encoding.UTF8)); - var immutableImplementationCode = transformer.ToImplementationCodeText(localizationType, false); - context.AddSource("LocalizedValues.immutable.g.cs", SourceText.From(immutableImplementationCode, Encoding.UTF8)); + var immutableImplementationCode = transformer.ToImplementationCodeText(localizationType, false); + context.AddSource("LocalizedValues.immutable.g.cs", SourceText.From(immutableImplementationCode, Encoding.UTF8)); - var notifiableImplementationCode = transformer.ToImplementationCodeText(localizationType, true); - context.AddSource("LocalizedValues.notifiable.g.cs", SourceText.From(notifiableImplementationCode, Encoding.UTF8)); + var notifiableImplementationCode = transformer.ToImplementationCodeText(localizationType, true); + context.AddSource("LocalizedValues.notifiable.g.cs", SourceText.From(notifiableImplementationCode, Encoding.UTF8)); + } } + catch (Exception ex) + { + context.ReportUnknownError(ex.Message); + } + } } }