-
Notifications
You must be signed in to change notification settings - Fork 11
Features: String References in String Formatting
Rudy Huyn edited this page Aug 1, 2019
·
1 revision
When using String Formatting, you can replace one or many parameters by a reference to another string in your .resw file. This feature will simplify your localizations and save you from having to translate the same string several times in your resource file.
Resw:
Key | Value | Comment |
---|---|---|
AndroidApplicationName | Contoso for Android | |
DownloadAndroidApp | Click here to download {0}! | #Format[AndroidApplicationName()] |
In this example, ReswPlus will format the string DownloadAndroidApp
with the value of AndroidApplicationName
Code generated:
public static string DownloadOurApp
{
get
{
return string.Format(_resourceLoader.GetString("DownloadOurApp"), "Microsoft Store");
}
}
Usage:
<TextBlock Text="{x:Bind strings:Resources.DownloadAndroidApp}" />
Result:
Click here to download Contoso for Android
You can combine String references with all other string formatting features provided by ReswPlus like Literal Strings or parameters.
Resw:
Key | Value | Comment |
---|---|---|
AndroidApplicationName | Contoso for Android | |
DownloadApp | Hi {0}! Do you want to download {1}? | #Format[String username, AndroidApplicationName()] |
Code generated:
public static string AndroidApplicationName
{
get
{
return _resourceLoader.GetString("AndroidApplicationName");
}
}
public static string DownloadAndroidApp
{
get
{
return string.Format(_resourceLoader.GetString("DownloadAndroidApp"), AndroidApplicationName);
}
}
Usage:
<TextBox x:Name="UsernameTextbox" Header="Username" Text="Roger" />
<TextBlock Text="{x:Bind strings:Resources.WelcomeDownloadApp(UsernameTextbox.Text), Mode=OneWay}" />
Result: