示例#1
0
        /// <summary>
        /// Gets a resource string based on the specified ResourceKey property.
        /// </summary>
        /// <param name="ResourceKey">A string representing a ResourceKey.</param>
        /// <param name="LanguageID">Language identifier</param>
        /// <param name="LogIfNotFound">A value indicating whether to log error if locale string resource is not found</param>
        /// <returns>A string representing the requested resource string.</returns>
        public static string GetLocaleResourceString(string ResourceKey, int LanguageID, bool LogIfNotFound)
        {
            string result = string.Empty;

            if (ResourceKey == null)
            {
                ResourceKey = string.Empty;
            }
            ResourceKey = ResourceKey.Trim().ToLowerInvariant();
            LocaleStringResourceDictionary resources = LocaleStringResourceManager.GetAllResourcesByLanguageID(LanguageID);

            if (resources.ContainsKey(ResourceKey))
            {
                LocaleStringResource lsr = resources[ResourceKey];
                if (lsr != null)
                {
                    result = lsr.ResourceValue;
                }
            }
            if (String.IsNullOrEmpty(result))
            {
                result = ResourceKey;
                if (LogIfNotFound)
                {
                    LogManager.InsertLog(LogTypeEnum.CommonError, "Resource string is not found", string.Format("Resource string ({0}) is not found. Language ID ={1}", ResourceKey, LanguageID));
                }
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Gets a resource string based on the specified ResourceKey property.
        /// </summary>
        /// <param name="resourceKey">A string representing a ResourceKey.</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="logIfNotFound">A value indicating whether to log error if locale string resource is not found</param>
        /// <param name="defaultValue">Default value</param>
        /// <returns>A string representing the requested resource string.</returns>
        public static string GetLocaleResourceString(string resourceKey, int languageId,
                                                     bool logIfNotFound, string defaultValue)
        {
            string result = string.Empty;

            if (resourceKey == null)
            {
                resourceKey = string.Empty;
            }
            resourceKey = resourceKey.Trim().ToLowerInvariant();
            var resources = LocaleStringResourceManager.GetAllResourcesByLanguageId(languageId);

            if (resources.ContainsKey(resourceKey))
            {
                var lsr = resources[resourceKey];
                if (lsr != null)
                {
                    result = lsr.ResourceValue;
                }
            }
            if (String.IsNullOrEmpty(result))
            {
                if (logIfNotFound)
                {
                    LogManager.InsertLog(LogTypeEnum.CommonError, "Resource string is not found", string.Format("Resource string ({0}) is not found. Language Id ={1}", resourceKey, languageId));
                }

                if (!String.IsNullOrEmpty(defaultValue))
                {
                    result = defaultValue;
                }
                else
                {
                    result = resourceKey;
                }
            }
            return(result);
        }
示例#3
0
 /// <summary>
 /// Exports language pack to XML
 /// </summary>
 /// <param name="languageId">Language identifier</param>
 /// <returns>XML content</returns>
 public static string LanguagePackExport(int languageId)
 {
     return(LocaleStringResourceManager.GetAllLocaleStringResourcesAsXml(languageId));
 }
示例#4
0
 /// <summary>
 /// Imports language pack from XML
 /// </summary>
 /// <param name="languageId">Language identifier</param>
 /// <param name="content">XML content</param>
 public static void LanguagePackImport(int languageId, string content)
 {
     LocaleStringResourceManager.InsertAllLocaleStringResourcesFromXml(languageId, content);
 }