若是出現上述Issue, 打開項目AssemblyInfo.cs文件,加入以下代碼片斷,而後重複Step 2.
[assembly: NeutralResourcesLanguage("en-US")]
三、新建資源文件,添加資源,而後修改訪問修改符爲Public.
四、添加翻譯語言
右鍵項目,選擇以下所示的菜單項添加」翻譯語言「
而後選擇應用需支持的語言便可
以下所示,已經成功添加中文支持。
五、若是在資源文件 .resx中添加了新項或是作了其餘修改,需編譯項目,而後在項目中選擇全部的xls文件,右鍵」生成機器翻譯「。
以下所示,正在翻譯。
六、翻譯完成以後,就能夠在本來的Login.resx下方找到對應的語言的資源文件。
打開對應的資源 文件,若是沒有成功翻譯,從新編譯項目便可。
這樣資源文件就翻譯好了。
七、但機器翻譯並不十分徹底,如需手動修改,只需修改相應的xlf文件(不是生成的.resx文件,切記),從新編譯便可。如我想把上圖所示的"登陸"修改成」登錄「,就沒怎樣操做呢?
在項目中雙擊」zh-Hans.xlf「文件,打開文件進行編輯
而後直接修改要修改的部分便可,修改完成以後單擊保存按鈕。
從新編譯項目,發現資源文件已經修改
八、在項目中引用資源
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:accountResource="clr-namespace:WpfApplication2.Resource.Account"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="{x:Static accountResource:Login.BtnLogIn}"></Button>
</Grid>
</Window>
九、設定應用UI語言
public partial class App : Application
{
private CultureInfo cultureOverride = new CultureInfo("zh-Hans");
public App()
{
Thread.CurrentThread.CurrentUICulture = cultureOverride;
Thread.CurrentThread.CurrentCulture = cultureOverride;
}
}
而後運行程序,效果如圖所示