示例#1
0
        /// <summary>
        /// Gets a resource string for a given resource key.
        /// </summary>
        /// <param name="resourceKey">The resource key.</param>
        /// <param name="fallbackToExampleValue">If <c>true</c>, and the resource key is not found, the method will return the example value that
        /// comes with the resource key. If <c>false</c>, the method will return <c>Null</c> in this case.</param>
        /// <returns>The resource string corresponding to the given resource key.</returns>
        public string GetString(StringResourceKey resourceKey, bool fallbackToExampleValue)
        {
            string cu = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

            if (!_resourceManagersByLanguage.TryGetValue(cu, out var mgr))
            {
                string resName = string.Format("{0}.{1}.{2}", _resourcePath, cu, _resourceName);
                mgr = null;
                try
                {
                    mgr = new System.Resources.ResourceManager(resName, _assemblyContainingTheResources);
                }
                catch (Exception)
                {
                }
                _resourceManagersByLanguage.Add(cu, mgr); // add the manager even if it is null -> this then indicates that no such resource localization exists.
            }

            string result;

            mgr = _resourceManagersByLanguage[cu];
            if (null != mgr && null != (result = mgr.GetString(resourceKey.Key)))
            {
                return(result);
            }

            if (null != (result = _defaultResourceMgr.GetString(resourceKey.Key)))
            {
                return(result);
            }

            return(resourceKey.ExampleStringValue);
        }
示例#2
0
		/// <summary>
		/// Gets a resource string for a given resource key.
		/// </summary>
		/// <param name="resourceKey">The resource key.</param>
		/// <param name="fallbackToExampleValue">If <c>true</c>, and the resource key is not found, the method will return the example value that
		/// comes with the resource key. If <c>false</c>, the method will return <c>Null</c> in this case.</param>
		/// <returns>The resource string corresponding to the given resource key.</returns>
		public string GetString(StringResourceKey resourceKey, bool fallbackToExampleValue)
		{
			System.Resources.ResourceManager mgr;

			string cu = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

			if (!_resourceManagersByLanguage.TryGetValue(cu, out mgr))
			{
				string resName = string.Format("{0}.{1}.{2}", _resourcePath, cu, _resourceName);
				mgr = null;
				try
				{
					mgr = new System.Resources.ResourceManager(resName, _assemblyContainingTheResources);
				}
				catch (Exception)
				{
				}
				_resourceManagersByLanguage.Add(cu, mgr); // add the manager even if it is null -> this then indicates that no such resource localization exists.
			}

			string result;
			mgr = _resourceManagersByLanguage[cu];
			if (null != mgr && null != (result = mgr.GetString(resourceKey.Key)))
				return result;

			if (null != (result = _defaultResourceMgr.GetString(resourceKey.Key)))
				return result;

			return resourceKey.ExampleStringValue;
		}
示例#3
0
 /// <summary>
 /// Gets a resource string for a given resource key.
 /// </summary>
 /// <param name="resourceKey">The resource key.</param>
 /// <returns>The resource string corresponding to the given resource key.</returns>
 public string GetString(StringResourceKey resourceKey)
 {
     return(GetString(resourceKey, true));
 }
示例#4
0
		/// <summary>
		/// Gets a resource string for a given resource key.
		/// </summary>
		/// <param name="resourceKey">The resource key.</param>
		/// <returns>The resource string corresponding to the given resource key.</returns>
		public string GetString(StringResourceKey resourceKey)
		{
			return GetString(resourceKey, true);
		}