Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallbacks for model properties - ResourceStringProvider #3

Closed
shelakel opened this issue Feb 13, 2012 · 1 comment
Closed

Fallbacks for model properties - ResourceStringProvider #3

shelakel opened this issue Feb 13, 2012 · 1 comment

Comments

@shelakel
Copy link

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.

Thanks for your contribution :)

@jgauffin
Copy link
Owner

->MyModel_FullName = Full name
if not found, checks for:
->CommonPrompts_FullName = Full name

The repositories works the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants