[ASP. 5] localization-easy-to-use localization-globalization information

Source: Internet
Author: User

This article is a simple introduction to the localization solution:

    • Microsoft.Framework.Globalization.CultureInfoCache Engineering
    • Cultureinfogenerator Engineering


The Cultureinfocache project is the same as its name, cushioning the CultureInfo of each region. The project has only one class (divided into two parts of the class), and are super simple, below we will briefly introduce the following:

Cultureinfocache: The core buffer class. External storm leak static method: CultureInfo GetCultureInfo (string name), can be based on local language code (such as CN, EN, etc.) to obtain local CultureInfo.

 Public Static Partial classCultureinfocache {Private Static ReadOnlyconcurrentdictionary<string, cacheentry> _cache =Newconcurrentdictionary<string, cacheentry>();  Public StaticCultureInfo GetCultureInfo (stringname) {            if(Name = =NULL|| !knownculturenames.contains (name)) {                return NULL; }            varEntry = _cache. Getoradd (name, n =            {                Try                {                    return NewCacheEntry (Cultureinfo.readonly (NewCultureInfo (n))); }                Catch(culturenotfoundexception) {return NewCacheEntry (cultureInfo:NULL);            }            }); returnentry.        CultureInfo; }        Private classCacheEntry { Publiccacheentry (CultureInfo CultureInfo) {CultureInfo=CultureInfo; }             PublicCultureInfo CultureInfo {Get; } }}cultureinfocache
Cultureinfocache Part1
  Public Static Partial classCultureinfocache { Public Static ReadOnlyhashset<string> knownculturenames =Newhashset<string>        {            #regionCulture"ar",            .........            "Zh-cht"            #endregion        }; }
Cultureinfocache Part2
    • Internal system using concurrentdictionary<string, cacheentry> for data cache
    • Concurrentdictionary is a thread-safe dictionary table and the dictionary<,> function is similar
    • CacheEntry is actually the encapsulation of CultureInfo, and is only used internally
    • Getoradd method: If the dictionary contains, return directly, if not included, after creation. The first parameter is the lookup parameter, and the second is the Func parameter, which is used to create the.
    • Knownculturenames: The language CultureInfo used to store the current environment support. (related to operating system,. NET environment)
    • Because the knownculturenames needs to be generated dynamically, the two parts are separated.


The function of this project is to generate Microsoft.Framework.Globalization.CultureInfoCache Part2, to be honest, I think this project is a problem in architecture. Does it regenerate the code every time? However, the existing source code is like this, I just follow the existing logic to share to everyone.

There are problems with this solution, and the following two problems need to be modified manually:

    • Modify the constructor to give the default value when Appenvironment is null.
 Public Program (iapplicationenvironment appenvironment)        {            null"cultureinfogenerator"  : appenvironment.applicationname;             NULL "" : Appenvironment.applicationbasepath;        }
    • Modify the Outputfilepath path:. /microsoft.framework.globalization.cultureinfocache/cultureinfolist.cs to.. /microsoft.framework.globalization.cultureinfocache/cultureinfolist.cs.
var 0 ? args[0". /microsoft.framework.globalization.cultureinfocache/cultureinfolist.cs");

After the modification, run the project directly, and you will find that the CultureInfoList.cs file in the Microsoft.Framework.Globalization.CultureInfoCache solution has been changed.

This document also deserves our attention, which is the correspondence between the version and the. NET Environment

 Private Static stringCheckfor45dotversion (intReleasekey) {            if(Releasekey >=393273)            {                return "4.6 RC or later"; }            if((Releasekey >=379893))            {                return "4.5.2 or later"; }            if((Releasekey >=378675))            {                return "4.5.1 or later"; }            if((Releasekey >=378389))            {                return "4.5 or later"; }            //This line should never execute. A Non-null release key should mean//That 4.5 or later is installed.            return "No 4.5 or later version detected"; }

[ASP. 5] localization-easy-to-use localization-globalization information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.