Today short entry about the multilingual pages. I will be based on the files. Resx. The mechanism is built into the same platform, but the net will describe how and what solved in practice.
ResourceHelper
It is our object is to facilitate the collection of auxiliary files. Resx. It is also responsible for initialization of ResourceManager that is the main subject of the page. NET that allows you to manage resources. Class itself is not complicated. In addition to the init method has only one method that takes a string value from our resource files. Class it looks like this: public static
ResourceHelper class
{private static ResourceManager public static void Initialize (ResourceManager ResourceManager)
{
Check.Argument.IsNotNull (ResourceManager, "ResourceManager"); _resourceManager = ResourceManager;
} public static string GetErrorMessage (string key) {CreateResourceManager public ResourceManager ()
string errorMessage = _resourceManager.GetString (key);
if (errorMessage == null) throw new ArgumentException
(_resourceManager.GetString (ResourceKey.Common.InvalidMessage));
return errorMessage;}
class itself is static. As you can see here there is also a class named ResourceKey. This class has all the information about the names of the variables in the files. Resx. I just do not have to always enter a string, just use an auxiliary class and in case of a change in only one place it will be necessary. Such a little easier:) In addition to the projections of newly added files. Resx is also a factory which generates all the appropriate ResourceManager which subsequently initiate our helper. It looks very simple: public class
ResourceManagerFactory: IResourceManagerFactory
{private ResourceManager
_resourceManager;
public ResourceManagerFactory ()
} {
{if (null == _resourceManager)
_resourceManager = new ResourceManager ("mForum.Resources.ErrorsAndExceptions.ErrorMessages" Assembly.GetExecutingAssembly ());
_resourceManager return;
}}
Sam ResourceManager constructor takes two arguments. 1 is the name of the class that was generated with the creation of a file. Resx. The second is a library which is located in the file.
contrast in views have accepted a little different approach when it comes to resources. Resources standardly that is internal are only available from the library but for me all the resources associated with the presentation layer will cause the public to what we can directly refer to the file. resx with our views.
In addition to these changes, of course, I added tests related to our ResourceHelperem.
0 comments:
Post a Comment