I want to propose a useful modification to the ResourceStringProvider I'm currently using.
/// <summary>
/// Get a localized string for a model property
/// </summary>
/// <param name="model">Model being localized</param>
/// <param name="propertyName">Property to get string for</param>
/// <returns>Translated string</returns>
public string GetModelString(Type model, string propertyName)
{
var result = GetString(Format(model, propertyName));
return string.IsNullOrEmpty(result) ? GetString(Format(propertyName)) : result;
}
/// <summary>
/// Get a localized metadata for a model property
/// </summary>
/// <param name="model">Model being localized</param>
/// <param name="propertyName">Property to get string for</param>
/// <param name="metadataName">Valid names are: Watermark, Description, NullDisplayText, ShortDisplayText.</param>
/// <returns>Translated string</returns>
/// <remarks>
/// Look at <see cref="ModelMetadata"/> to know more about the meta data
/// </remarks>
public string GetModelString(Type model, string propertyName, string metadataName)
{
var result = GetString(Format(model, propertyName, metadataName));
return string.IsNullOrEmpty(result) ? GetString(Format(propertyName, metadataName)) : result;
}
This simply provides a default fallback to retrieve model property display names and metadata.
->MyModel_FullName = Full name
if not found, checks for:
->FullName = Full name
This still allows for overriding the defaults which is a win-win situation.
I want to propose a useful modification to the ResourceStringProvider I'm currently using.
This simply provides a default fallback to retrieve model property display names and metadata. ->MyModel_FullName = Full name if not found, checks for: ->FullName = Full name
This still allows for overriding the defaults which is a win-win situation.
Thanks for your contribution :)