예제 #1
0
        /// <summary>
        /// Get localized property value of a plugin
        /// </summary>
        /// <param name="descriptor">Plugin descriptor</param>
        /// <param name="localizationService">Localization service</param>
        /// <param name="propertyName">Name of the property</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="returnDefaultValue">A value indicating whether to return default value (if localized is not found)</param>
        /// <returns>Localized value</returns>
        public static string GetLocalizedValue(this PluginDescriptor descriptor, ILocalizationService localizationService, string propertyName, int languageId = 0, bool returnDefaultValue = true)
        {
            if (localizationService == null)
            {
                throw new ArgumentNullException("localizationService");
            }

            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            if (propertyName == null)
            {
                throw new ArgumentNullException("name");
            }

            string systemName   = descriptor.SystemName;
            string resourceName = string.Format("Plugins.{0}.{1}", propertyName, systemName);
            string result       = localizationService.GetResource(resourceName, languageId, false, "", true);

            if (String.IsNullOrEmpty(result) && returnDefaultValue)
            {
                result = descriptor.TryGetPropertyValue(propertyName) as string;
            }

            return(result);
        }