Forum: Multi-Language Add-In for Visual Studio

Visual Basic 14 String Interpolation Support

Hello,
String interpolation is an easier way of writing strings with expressions in them, like so:

Dim s = $"hello {p.Name} you are {p.Height:0.00}m tall"

See: https://msdn.microsoft.com/en-us/magazine/dn890368.aspx

I would like to suggest to implement the string interpolation support in Multi-Language Add-In.

Thank you,
Filippo Bottega.

Germany

Hi Filipo

firstly, thanks for pointing this feature out, because I had missed it completely. Also the link was a very interesting list of new features in VB.NET.

Although the article was about VB.NET, String Interpolation is a feature of both C# and VB. In principle, Multi-Language should support this feature, but the question is how.

So far as I can tell, there is no way that you can store the string $"hello {p.Name} you are {p.Height:0.00}m tall" as a resource string. It is just shorthand for

Dim s = String.Format ( "hello {0} you are {1:0.00}m tall", p.Name, p.Height )

My only idea is that Multi-Language would convert it back to that format and store the string "hello {0} you are {1:0.00}m tall" as a resource string.

This means that you have no benefit from the new syntax, but if you have already used it, Multi-Language would at least handle it.

What do you think?

Phil


Hi Phil,
thank you for your answer.
What do you think about another solution like this?

Dim s = $"{ml_string(1, "hello ")}{p.Name}{ml_string(2, " you are ")}{p.Height:0.00}{ml_string(3, "m tall")}"

Filippo.

Germany

I don't like that method, because it is difficult to translate.

If you give a translator three separate strings to translate

  • hello
  • you are
  • m tall

there is no way that they can make a good translation of the complete sentence.

There are leading and trailing spaces in the strings. These will get lost if anybody apart from the original programmer does the translation.

You are making an implicit assumption that the order of the elements in the sentence is the same in all languages. In general, this is a dangerous assumption. In a language that you don't know, for example I don't know Japanese, you might have to place the parts of the sentence in a different order.

In my opinion, it is the best practice to give a translator a complete sentence to translate.

Phil

I agree with you but string interpolation is nothing different from string concatenation.
If a developer write:

' Sample 1
dim a = "Pippo"
dim b = "Pluto"
Dim c = a & " like " & b

At this moment Multi-Language Add-In convert it as:

' Sample 2
dim a = ml_string(1, "Pippo")
dim b = ml_string(3, "Pluto")
Dim c = a & ml_string(3, " like ") & b

You can not predict what a developer is writing. Multi-Language Add-In is semantic agnostic.

And if Sample 1 is equivalent to:
dim a = "Pippo"
dim b = "Pluto"
Dim c = $"{a} like {b}"

Sample 2 will be equivalent to:
dim a = ml_string(1, "Pippo")
dim b = ml_string(3, "Pluto")
Dim c = $"{a}{ml_string(3, " like ")}{b}"

Right now you're assuming that a string is a statement in a specific language, but it could be anything.
For this reason I would not worry the meaning of the strings to translate or the order of the elements.

Don't forget also that with string interpolation you may write:

Dim c = $"{$"{$"Pippo"}{$" like "}"}{$"{$"Pluto"}{$" a lot."}"}"

I don't think that converting this statement using Format function is a good idea. (I don't think that this statement is a good statement obviously... biggrin)

In my opinion the best solution is to let the developer choose your solution or mine asking if he want to convert the string interpolation statement or not.

Filippo.


Sorry,
Pippo likes Pluto... redface