Merge pull request #2962 from marek-safar/referencesource-submodule-move
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / CategoryNameMap.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing 
5 {
6     using System;
7     using System.Collections.Generic;
8
9     // <summary>
10     // Helper class that looks up (and keeps a map of) category names and their localized versions.
11     // </summary>
12     internal static class CategoryNameMap 
13     {
14
15         private static Dictionary<string, string> _cache = new Dictionary<string, string>();
16
17         // <summary>
18         // Gets the localized value of the specified category name.  If the input string
19         // is already localized, it won't be found in Cider's resources and, hence, it
20         // will be returned as is.
21         //
22         // Note that we pull category names from CategoryAttributes which already look up
23         // the localized version for common categories, such as "Misc", "Layout" and "Appearance",
24         // by default. This method just takes care of the few others that are WPF-specific and that
25         // we want to be localized as well.
26         // </summary>
27         // <param name="categoryName">Category name to look up</param>
28         // <returns>Translated version of the category name or the original name if not found.</returns>
29         public static string GetLocalizedCategoryName(string categoryName) 
30         {
31             if (categoryName == null)
32             {
33                 return null;
34             }
35
36             string localizedCategoryName;
37             if (_cache.TryGetValue(categoryName, out localizedCategoryName))
38             {
39                 return localizedCategoryName;
40             }
41
42             localizedCategoryName = GetLocalizedWPFCategoryName(categoryName) ?? categoryName;
43             _cache[categoryName] = localizedCategoryName;
44             return localizedCategoryName;
45         }
46
47         private static string GetLocalizedWPFCategoryName(string categoryName) 
48         {
49             return (string)System.Activities.Presentation.Internal.Properties.Resources.ResourceManager.GetString(string.Concat("PropertyCategory", categoryName.Replace(' ', '_')));
50         }
51     }
52 }