Develop a language manager based on key-value pairs Lauguagemanager

Source: Internet
Author: User

Develop a language manager based on key-value pairs Lauguagemanager

In the process of developing UI framework, we will use the internationalization of language, especially after our game project is bigger, the company is not only satisfied with the domestic market, may be released to the United States, Japan and other countries. At this time the internationalization of language will be particularly important, of course, internationalization is not only refers to the language of the nationalization, but also includes the internationalization of audio and many other aspects. Here we mainly explain the internationalization of language.

Generally speaking, we will put all the language information in the configuration file, when we are in the domestic market we can use Chinese, when we publish to the United States can use the English configuration file. :

Configuration file in English:

Configuration file for Chinese:

These are usually stored in the configuration table as key-value pairs. We need to parse the configuration file into the dictionary collection. Parsing of JSON files http://www.cnblogs.com/MoRanQianXiao/p/7899821.html.

The full implementation code is as follows:

namespaceuifromwork{ Public classLauguagemanager {#regionSingle-Case modePrivate StaticLauguagemanager _instance =NULL;  Public StaticLauguagemanager Instance {Get            {                if(_instance = =NULL) {_instance=NewLauguagemanager (); }                return_instance; }        }        #endregion        #regionfield and attribute definitions/** * Cached collection of languages **/        Privatedictionary<string,string> _diclauguagecache =Newdictionary<string,string>(); #endregion        #regionDefinition of a constructor functionPrivateLauguagemanager () {//initializing a collection of language cachesInitlauguagecache (); }        #endregion        #regionDefinition of public methods Public stringShowtext (stringLauguageid) {            //Checking of parameters            if(string. IsNullOrEmpty (Lauguageid))return NULL; //Query Processing            if(_diclauguagecache! =NULL&& _diclauguagecache.count >=1)            {                stringresult =NULL; _diclauguagecache.trygetvalue (Lauguageid, outresult); if(Result! =NULL)                {                    returnresult; }            }            //Throwing Custom Exceptions            Throw NewJsonanlysisexception (string. Format ("{0}/showtext ()/query is null! Parameter:lauguageid: {1}", GetType (), Lauguageid)); }        #endregion        #regionDefinition of private methodsPrivate voidInitlauguagecache () {iconfigmanagerable config=NewConfigmanagerbyjson ("Json\\lauguagejsonconfig"); if(Config! =NULL) {_diclauguagecache=CONFIG.            appsetting; }        }        #endregion    }//Class_end}

Develop a language manager based on key-value pairs Lauguagemanager

Related Article

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.