Some Thoughts On String Interpolation [l10n, restricting access, AA]
kdevel
kdevel at vogtner.de
Thu Oct 26 11:18:46 UTC 2023
**Localization**
A few days ago this example was posted in the "Learn" group [1]:
```d
writeln(i"You drink $coffees cups a day and it gives you
$(coffees + iq) IQ");
```
A German version would read
```d
writeln(i"Sie trinken $coffees Tassen Kaffee am Tag. Dadurch
erhöht sich Ihr IQ auf $(coffees + iq).");
```
How could the language version be selected (at runtime)? BTW: Is
there a "D way of localization"?
**Restricting Access**
What about
```d
writeln(i"You drink $coffees cups a day and it gives you
$(password) IQ");
```
How is it prevented that the person doing the localization puts
arbitrary variable or code references into the localized strings?
Is this attack vector already known? And if so: Has it been named?
**Accessing Fields Of A Struct**
Having data in a struct Variable `s`
```d
struct S {
string value;
}
S s;
```
would this work out-of-the-box?:
```d
with (s) writeln(i"The name in s is $(value)");
```
**Accessing Elements Of An AA**
```d
string[string] aa;
aa["name"] = "value";
writeln (i"The name in s is $(aa[\"name\"])"
```
That typing is laborious. Isn't there a way to bind the
expression to the keys of the AA?
**Nesting**
Should it nest? How deep? What is the syntax?
```d
writeln(i"does this work $(a + \"$(b)\" + c)");
```
*to be continued*
[1]
https://forum.dlang.org/post/rkevblyfgvmvmsuhtqmr@forum.dlang.org
More information about the Digitalmars-d
mailing list