Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable localization for LibraryImportGenerator #67107

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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