/// <summary> /// Gets the localized string. /// </summary> /// <param name="moduleName">Name of the module.</param> /// <param name="msgId">The MSG id.</param> /// <param name="cultureName">Name of the culture.</param> /// <param name="args">The args.</param> /// <returns>The result will never be null.</returns> /// <exception cref="ArgumentNullException">Will be throw if <paramref name="msgId"/> is null.</exception> /// <exception cref="ArgumentException">Will be throw if <paramref name="msgId"/> is empty.</exception> /// <exception cref="ArgumentNullException">Will be throw if <paramref name="cultureName"/> is null.</exception> /// <exception cref="ArgumentException">Will be throw if <paramref name="cultureName"/> is empty.</exception> public LocalizedString GetLocalizedString(string moduleName, string msgId, string cultureName, params object[] args) { if (msgId == string.Empty) { throw new ArgumentException(); } if (msgId == null) { throw new ArgumentNullException(); } if (cultureName == string.Empty) { throw new ArgumentException(); } if (cultureName == null) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(moduleName)) { moduleName = "core"; } CultureInfo culture = new CultureInfo(cultureName); CultureDictionary cultureDictionary = this.LoadCulture(moduleName, culture); if (cultureDictionary.Translations == null) { return(new LocalizedString(msgId, msgId, args)); } string genericKey = ("|" + msgId).ToLowerInvariant(); if (cultureDictionary.Translations.ContainsKey(genericKey)) { LocalizedString r = new LocalizedString(cultureDictionary.Translations[genericKey], msgId, args); return(r); } this.logger.WarnFormat("There is no value with the specified msgIf:'{0}'", msgId); return(new LocalizedString(msgId, msgId, args)); }
private CultureDictionary LoadCulture(string moduleName, CultureInfo culture) { string key = string.Format("Dictionary.Culture:{0}.Module{1}", culture.Name, moduleName); CultureDictionary cachedObject = this.cacheProvider.Get <CultureDictionary>(key); if (cachedObject == null) { cachedObject = new CultureDictionary { Culture = culture, Translations = this.LoadTranslations(moduleName, culture) }; this.cacheProvider.Put(key, cachedObject, TimeSpan.FromDays(1)); } return(cachedObject); }