Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Localized Message Issue

$
0
0
Hi Jeremy,

I read the threads showing the implementation of Localized Messages generated through Resources. However, for my project I am fetching the resources from the database on start of the application and then filling up the cache containing the resources' key-value pair.

I used the
.WithLocalizedMessage(() => DisplayResource.GetResourceValue("IMEIRequired"));
This is the DisplayResource Constructor
  public DisplayResource(string value)
            : base(GetResourceValue(value))
        {

        }
And the following is the GetResourceValue method
public static string GetResourceValue(string keyName)
        {
            string lang = string.Empty;
            // string lang = CultureInfo.CurrentCulture.ToString();
            if (HttpContext.Current.Session["languageType"] == null)
            {
                lang = CultureInfo.CurrentCulture.ToString();
                HttpContext.Current.Session["languageType"] = lang;
            }
            else
            {
                lang = HttpContext.Current.Session["languageType"].ToString();
            }


            switch (lang)
            {
                case "en-US":
                    lang = "English";
                    break;
                case "es":
                    lang = "Spanish";
                    break;
                case "fr":
                    lang = "French";
                    break;
                case "pt":
                    lang = "Portuguese";
                    break;
                default:
                    lang = "English";
                    break;
            }
            if (System.Web.HttpContext.Current.Cache["languageList"] != null)
            {
                var k = (System.Web.HttpContext.Current.Cache["languageList"] as List<LanguageModel>).FirstOrDefault(n => n.LanguageKey == keyName && n.LanguageType == lang);
                return Convert.ToString(k.LanguageValue);
            }
            else
                return string.Empty;
        }
But I keep getting this error "Only MemberExpressions an be passed to BuildResourceAccessor, eg () => Messages.MyResource"

How can I achieve localization this way?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>