Project notes---WPF multi-language scenario

Source: Internet
Author: User
Tags i18n

Recently due to friends invited to help an open-source game "plug" to do a i18n solution, just as WPF did, before the relevant experience, on the busy one weeks finally settled, has been submitted to the author, now here to do a share.

Here, share my personal fork. GitHub Address: Https://github.com/Cuiyansong/Hearthstone-Deck-Tracker

What is i18n

In simple terms, it is multi-lingual, why multilingual is called i18n, please refer to the epilogue.

How to Achieve

In fact, the implementation of multiple languages on WPF is similar to WinForm, which is to replace the Software runtime resources (Resource). And WPF has a somewhat more innate advantage in this area---xaml, where you do not want to detail the evolution of XAML to WinForm, and here is to emphasize that having XAML makes WPF interface binding more advantageous.

Compared to many WPF multi-language scenarios, Wpflocalizeextension has more advantages, of course, there are some shortcomings, this is something, here I choose to use the latter to show you.

This article does not discuss the principle in depth, directly describes how to apply.

1. Introducing WPFLocalizeExtension.dll, we recommend that you search for wpflocalizeextension with NuGet, and then install it sequentially. (Not with NuGet?) Point here)

2. WPFLocalizeExtension.dll relies on XAML Markup Extensions for more features such as the implementation of dynamic binding at design time, and interested readers can search by themselves. This is where the open source framework is different from other ways of being powerful.

3. Add the following information in the MainWindow.xaml citation:

Description: Designcultrue= "en-US", this is the default English setting, other languages can be changed such as ZH-CN

defaultdictonary= "Strings" This is a prefix that is bound to a multilingual file <name>.<language>.resx

defaultassembly= "Hearthstone Deck Tracker" This is the assembly name.

4. Binding interface Visual elements:

There are 3 ways to bind, please refer to here, I chose {lex:loc ABC} this way.

5. Add multi-language files

Add a folder to your project, such as name "Langs", and then add Strings.zh-cn.resx, String.de-de.resx, Strings.resx, these files are system-type resource files, I believe you see the suffix resx will know how to add J.

Finally, the addition of multi-lingual information, the emphasis here: These files must be the same key value (a bit wordy!). )

This interface is as long as the content = {Lex:loc ACTION} is available. (The content here can bind strings as long as they are text types, such as header, text, content, and so on for some controls)

6. Runtime Switch Language Update interface:

WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.Culture = System.Globalization.CultureInfo.GetCultureInfo ("ZH-CN");

In the software, the user-set language can be saved in the setting file, and then the current cultrue is set at each form_load.

7. Codebehind in multi-language key:

Of course, in addition to the UI can be dynamically bound, the program can also bind the prompt message key.

Var MSG = lang.getlocalizedstring ("Error_info");
         Public Static stringGetlocalizedstring (stringKeystringresourceFileName ="Strings",BOOLAddspaceafter =false)        {            varLocalizedString =String.Empty; //Build up the fully-qualified name of the key            varAssemblyName =System.Reflection.Assembly.GetExecutingAssembly (). GetName ().            Name; varFullKey = AssemblyName +":"+ resourceFileName +":"+key; varLocextension =Newlocextension (FullKey); Locextension.resolvelocalizedvalue ( outlocalizedstring); //Add a space to the end, if requested            if(addspaceafter) {localizedstring+=" "; }            returnlocalizedstring; }

More

1. Insufficient: The resource file will generate multiple Resource.dll in the root directory under the corresponding language directory, folder appears too much, at present I have not found a solution, if anyone has a solution please inform.

https://github.com/Epix37/Hearthstone-Deck-Tracker/pull/426

2. There are also layout designs for special languages such as Arabic and Hebrew in multiple languages that are not covered in the article.

Http://www.oschina.net/translate/building-multilingual-wpf-applications

Reference

I18n:http://baike.baidu.com/link?url=4a1hnzart1w0tiqy7hiviy-x8_ N7o9nllnjrrx2dxnneinz4vbnt9zrdbszglpaj-lsxf73zqjy74ezss7v-bq

WPF localizeextension official website: http://wpflocalizeextension.codeplex.com/

NuGet Configuration and use: http://blog.sina.com.cn/s/blog_674da3040101sv0o.html

Translation: Http://www.oschina.net/translate/building-multilingual-wpf-applications

Original: Http://www.codeproject.com/Articles/38751/Building-Multilingual-WPF-Applications

Project notes---WPF multi-language scenario

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.