Skip to content

Commit

Permalink
Enable localization for LibraryImportGenerator (#67107)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Mar 24, 2022
1 parent 5697987 commit 3b17fb8
Show file tree
Hide file tree
Showing 45 changed files with 8,880 additions and 1,564 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project>
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<IsShipping>false</IsShipping>
<!-- We manually enable LibraryImportGenerator for projects in this folder as part of testing. -->
<EnableLibraryImportGenerator>false</EnableLibraryImportGenerator>
<EnableDefaultItems>true</EnableDefaultItems>
<CLSCompliant>false</CLSCompliant>
<ILLinkTrimAssembly>false</ILLinkTrimAssembly>

<!-- Localization -->
<UsingToolXliff>true</UsingToolXliff>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.CodeAnalysis;

namespace Microsoft.Interop.Analyzers
Expand Down Expand Up @@ -33,7 +34,7 @@ public static class Ids

internal static LocalizableResourceString GetResourceString(string resourceName)
{
return new LocalizableResourceString(resourceName, Resources.ResourceManager, typeof(Resources));
return new LocalizableResourceString(resourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
Expand All @@ -27,12 +28,12 @@ public class ConvertToLibraryImportAnalyzer : DiagnosticAnalyzer
public static readonly DiagnosticDescriptor ConvertToLibraryImport =
new DiagnosticDescriptor(
Ids.ConvertToLibraryImport,
GetResourceString(nameof(Resources.ConvertToLibraryImportTitle)),
GetResourceString(nameof(Resources.ConvertToLibraryImportMessage)),
GetResourceString(nameof(SR.ConvertToLibraryImportTitle)),
GetResourceString(nameof(SR.ConvertToLibraryImportMessage)),
Category,
DiagnosticSeverity.Info,
isEnabledByDefault: false,
description: GetResourceString(nameof(Resources.ConvertToLibraryImportDescription)));
description: GetResourceString(nameof(SR.ConvertToLibraryImportDescription)));

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(ConvertToLibraryImport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
// Register code fix
context.RegisterCodeFix(
CodeAction.Create(
Resources.ConvertToLibraryImport,
SR.ConvertToLibraryImport,
cancelToken => ConvertToLibraryImport(
context.Document,
methodSyntax,
Expand All @@ -81,7 +81,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
context.RegisterCodeFix(
CodeAction.Create(
string.Format(Resources.ConvertToLibraryImportWithSuffix, "A"),
string.Format(SR.ConvertToLibraryImportWithSuffix, "A"),
cancelToken => ConvertToLibraryImport(
context.Document,
methodSyntax,
Expand All @@ -94,7 +94,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
context.RegisterCodeFix(
CodeAction.Create(
string.Format(Resources.ConvertToLibraryImportWithSuffix, "W"),
string.Format(SR.ConvertToLibraryImportWithSuffix, "W"),
cancelToken => ConvertToLibraryImport(
context.Document,
methodSyntax,
Expand Down Expand Up @@ -135,7 +135,7 @@ private class CustomFixAllProvider : DocumentBasedFixAllProvider
bool shouldWarn = await TransformCallersOfNoPreserveSigMethod(editor, methodSymbol, fixAllContext.CancellationToken).ConfigureAwait(false);
if (shouldWarn)
{
generatedDeclaration = generatedDeclaration.WithAdditionalAnnotations(WarningAnnotation.Create(Resources.ConvertNoPreserveSigDllImportToGeneratedMayProduceInvalidCode));
generatedDeclaration = generatedDeclaration.WithAdditionalAnnotations(WarningAnnotation.Create(SR.ConvertNoPreserveSigDllImportToGeneratedMayProduceInvalidCode));
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ private static async Task<Document> ConvertToLibraryImport(
bool shouldWarn = await TransformCallersOfNoPreserveSigMethod(editor, methodSymbol, cancellationToken).ConfigureAwait(false);
if (shouldWarn)
{
generatedDeclaration = generatedDeclaration.WithAdditionalAnnotations(WarningAnnotation.Create(Resources.ConvertNoPreserveSigDllImportToGeneratedMayProduceInvalidCode));
generatedDeclaration = generatedDeclaration.WithAdditionalAnnotations(WarningAnnotation.Create(SR.ConvertNoPreserveSigDllImportToGeneratedMayProduceInvalidCode));
}
}

Expand Down Expand Up @@ -221,7 +221,7 @@ private static async Task<SyntaxNode> ConvertMethodDeclarationToLibraryImport(

// Add annotation about potential behavioural and compatibility changes
libraryImportSyntax = libraryImportSyntax.WithAdditionalAnnotations(
WarningAnnotation.Create(string.Format(Resources.ConvertToLibraryImportWarning, "[TODO] Documentation link")));
WarningAnnotation.Create(string.Format(SR.ConvertToLibraryImportWarning, "[TODO] Documentation link")));

// Replace DllImport with LibraryImport
SyntaxNode generatedDeclaration = generator.ReplaceNode(methodSyntax, dllImportSyntax, libraryImportSyntax);
Expand Down
Loading

0 comments on commit 3b17fb8

Please sign in to comment.