History: MultiLangVsNetCodeAnalysisCodeFix

Preview of version: 9

Multi-Language for Visual Studio

Code Analysis and Code Fix

Starting with Version 7.2, Multi-Language for Visual Studio contains a code analysis and several associated code fixes.

What does it check?

Every code analysis checks a rule. Lets start by looking at what the rule is.

Every string in your source code should be either

  1. localized or
  2. marked as not requiring localization (hidden)

Why is this important?

In particular, why is it important to mark strings which do not require localization?

This is important for two reasons:

It's the programmer's job

Your source code probably contains some strings which require localization, but it will probably contain some strings which should not be localized. In fact, it may contain strings which must not be localized, because doing so would break the functionality of the program.

Figuring out which strings require localization, and which do not, is best performed by the original programmer.

You only want to do it once

After version 1 of your program has been localized and released, you are probably going to make some changes and at some point release a version 2.

Version 2 probably contains some new strings which require localization.

If you had previously (in version 1) marked the strings which do not require localization, then it will be fairly easy to find any new strings added in version 2.

If you did not mark the strings which do not require localization, then you might end up looking at every one of them again, to decide whether or not it requires localization.

What is a code analysis?


A code analysis is a rule that is applied in the background. If the rule is violated, then the code which violates the rule is underlined with a wavy green line.

Image

There is some general information about code analyzers on this page.

What is a code fix?


A code fix is a change that can be made to your code, so that the rule is satisfied. There may be one or more code fixes for any rule.

Image

The code fixes appear in the menu below the light bulb icon. This appears in the left hand margin, or next to the code, if you hold the mouse pointer over the code with the wavy green line.

When is the Multi-Language code analysis active?


The code analysis is active on any project which is already using Multi-Language.

Multi-Language adds a project database file (usually ProjectName_ml.xml) to the project, so the code analysis should be active if this file is present in the project.

In addition, the code analysis must be enabled in the project settings dialog ........

It is not necessary to scan the project using the the Multi-Language tool window.

What exactly does the Multi-Language Code-Analysis check?


The code analysis checks the strings and interpolated strings in the source code files (C# and VB).

For each string, it checks whether it is "hidden" ...

Strings containing no letters

Strings which do not contain any letters are ignored.

For example ".", "100" or " ".

Strings in ignored modules
In Multi-Language, you can mark a complete file as ignored. In this case, the code analysis will ignore all strings in the file.
Attribute parameters

In the current version (7.02.0004) attribute parameters are ignored, because a necessary code fix has not yet been implemented.

This will be changed in a future version.

Parameters to ...

Parameters to certain special functions are ignored, in particular:

  • ml.ml_string() (C#)
  • ml_string() (VB)
  • ml.GetString()
  • Debug.WriteLine()


This list may be expanded in future.

Strings in a hidden block

You can define a hidden block using the comments MLHIDEON and MLHIDEOFF, for example

//MLHIDEON
private string templatefile = "template.cs" ;
private string logfile      = "logfile.txt" ;
private string helpfile     = "helpfile.chm" ;
//MLHIDEOFF

Any string in a hidden block is ignored.

Strings in double brackets

This is a special syntax used by Multi-Language to hide a single string, for example:

public string junk()
{
  string hello = (("Hello World")) ;
  return hello ;
}

Strings in double brackets are ignored.

Lines with the MLHIDE comment

The usual way to hide a string using Multi-Language is to add the comment MLHIDE to the end of the line, for example:

public string junk()
{
  string hello = "Hello World" ;    //MLHIDE
  return hello ;
}

Any string on a line with this comment is ignored.

Blocked functions

All strings in certain blocked functions are ignored, in particular:

  • InitializeComponent
  • ml_UpdateControls


This list may be expanded in future.

Actually, it only really makes sense to ignore the function InitializeComponent in WinForms projects (and not WPF) so this might also be changed.

Strings localized using IStringLocalizer

ASP.NET Core supports a method of localization using a "localizer" object with the interface IStringLocalizer. This uses the original text string as resource-key to for the localized text.

The parameter to the localizer object is ignored..


Any string which is not ignored for one of the reasons listed above violates the rule.

What code fixes are available?


There are generally three possible code fixes:

  • hide the string in double brackets
  • hide the string using the comment MLHIDE
  • localize the string


In each case, a preview window shows the exact code change, before it is made.

History

Information Version
Thu 13 of May, 2021 21:27 GMT Phil 18
Sat 04 of Jul, 2020 11:23 GMT Phil 17
Sat 04 of Jul, 2020 11:08 GMT Phil 16
Sat 04 of Jul, 2020 08:05 GMT Phil 15
Sat 04 of Jul, 2020 08:04 GMT Phil 14
Sat 04 of Jul, 2020 08:03 GMT Phil 13
Sat 04 of Jul, 2020 07:38 GMT Phil 12
Sat 04 of Jul, 2020 07:06 GMT Phil 11
Mon 29 of Jun, 2020 21:11 GMT Phil 10
Mon 29 of Jun, 2020 20:44 GMT Phil 9
Mon 29 of Jun, 2020 20:30 GMT Phil 8
Mon 29 of Jun, 2020 20:23 GMT Phil 7
Mon 29 of Jun, 2020 19:58 GMT Phil 6
Sun 28 of Jun, 2020 21:44 GMT Phil 5
Sun 28 of Jun, 2020 21:25 GMT Phil 4
Sun 28 of Jun, 2020 21:06 GMT Phil 3
Sun 28 of Jun, 2020 20:34 GMT Phil 2
Sun 28 of Jun, 2020 18:14 GMT Phil 1