-
Notifications
You must be signed in to change notification settings - Fork 11
Features: Macros 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 one of the Macro provided by ReswPlus to automatically insert Date, time, OS version, Application name... in your localization strings.
Macro | Description | Example |
---|---|---|
DATE | Current date | Monday, June 15, 2009 |
SHORT_DATE | Current date | 6/15/2009 |
TIME | Current time, including seconds | 1:45:30 PM |
SHORT_TIME | Current time, only hours/minutes | 1:45 PM |
WEEKDAY | Name of the day | Wednesday |
SHORT_WEEKDAY | Name of the day | Wed |
YEAR | Current year | 2019 |
SHORT_YEAR | Current year | 19 |
LOCALE_NAME | Name of the language | French |
LOCALE_ID | Id of the language | en_US |
LOCALE_TWO_LETTERS | ISO 639-1 code for the language | en |
Macro | Description | Example |
---|---|---|
VERSION | Full version number of the app | 12.4.1.0 |
VERSION_XYZ | Version number of the app: major.minor.rev | 12.4.1 |
VERSION_XY | Version number of the app: major.minor | 12.4 |
VERSION_X | Major version number of the app | 12 |
APP_NAME | Application/site name | ContosoPlus |
Macro | Description | Example |
---|---|---|
ARCHITECTURE | Architecture of the app (not the OS) | x64 |
PUBLISHER_NAME | Name of the publisher | 6Studio |
DEVICE_FAMILY | Type of device | Windows.Desktop |
DEVICE_MODEL | Model of the device | Surface Laptop 2 |
OS_VERSION | Version of the OS | 10.0.18362.116 |
Resw:
Key | Value | Comment |
---|---|---|
AppVersion | version: {0} v{1}. | #Format[APP_NAME, VERSION] |
CopyrightNotice | © {0} - {1}. All rights reserved. | #Format[YEAR, PUBLISHER_NAME] |
will generate the following code:
public static string AppVersion
{
get
{
return string.Format(_resourceLoader.GetString("AppVersion"), ReswPlusLib.Macros.ApplicationName, ReswPlusLib.Macros.AppVersionFull);
}
}
public static string CopyrightNotice
{
get
{
return string.Format(_resourceLoader.GetString("CopyrightNotice"), ReswPlusLib.Macros.Year, ReswPlusLib.Macros.PublisherName);
}
}
Usage:
<TextBlock Text="{x:Bind strings:Resources.CopyrightNotice}" />
<TextBlock Text="{x:Bind strings:Resources.AppVersion}" />
Result:
© 2019 - Contoso. All rights reserved.
version: ContosoApp v1.0.0.0
You can use Macros with literal strings or with parameters.
Resw:
Key | Value | Comment |
---|---|---|
WelcomeMessageDay | Welcome {0}! Have a good {1} | #Format[String username, DAY] |
will generate the following code:
public static string WelcomeMessageDay(string username)
{
return string.Format(_resourceLoader.GetString("WelcomeMessageDay"), username, ReswPlusLib.Macros.WeekDay);
}
Usage:
<TextBox x:Name="UsernameTextBox" Header="Enter username:" Text="Rudy" Margin="0,12,0,0" />
<TextBlock Text="{x:Bind strings:Resources.WelcomeMessageDay(UsernameTextBox.Text), Mode=OneWay}" />
result:
