WPF 制作多语言版本程序

WPF 制作多语言版本程序

1.创建WpfApplication项目Mui_lang,窗口如“运行”的对话框。

不要给元素添加uid属性。

xaml 代码如下:

   <Window x:Uid="Window_1" x:Class="Mui_lang.Window1"
    xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Run"
ResizeMode = "NoResize" SizeToContent="WidthAndHeight"
>
    <Grid x:Uid="Grid_1" Background="#E1E0E5"   Grid.IsSharedSizeScope="True">
    <Grid.RowDefinitions>
       <RowDefinition x:Uid="RowDefinition_1" />
       <RowDefinition x:Uid="RowDefinition_2" />
       <RowDefinition x:Uid="RowDefinition_3" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
       <ColumnDefinition x:Uid="ColumnDefinition_1"/>
       <ColumnDefinition x:Uid="ColumnDefinition_2"/>
       <ColumnDefinition x:Uid="ColumnDefinition_3" SharedSizeGroup="Buttons"/>
       <ColumnDefinition x:Uid="ColumnDefinition_4" SharedSizeGroup="Buttons"/>
       <ColumnDefinition x:Uid="ColumnDefinition_5" SharedSizeGroup="Buttons"/>
    </Grid.ColumnDefinitions>
    <Button x:Uid="Button_1" Margin="3,10,3,15" Content="Ok" Grid.Column="2" Grid.Row="2" Padding="3,0,3,0" />
   <Button x:Uid="Button_2" Margin="3,10,3,15" Content="Cancel" Grid.Column="3" Grid.Row="2" Padding="3,0,3,0"/>
   <Button x:Uid="Button_3" Margin="3,10,3,15" Content="Browse..." Grid.Column="4" Grid.Row="2" Padding="3,0,3,0"/>
    <ComboBox x:Uid="ComboBox_1" Margin="10,0,0,0" IsSynchronizedWithCurrentItem="True" Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="1" HorizontalAlignment="Left" Width="288"/>
    <Image x:Uid="Image_1" Margin="10,0,0,0" Height="25" Source="runicon.jpg" Stretch="None" HorizontalAlignment="Left"/>
    <TextBlock Language="zh-CHS" x:Uid="TextBlock_1" Margin="10,0,0,0" Grid.Column="1" Grid.ColumnSpan="4" Text="Type the name of a program, folder, document, or Internet resource, and Windows will open it for you." TextWrapping="Wrap" Width="288" VerticalAlignment="Center" HorizontalAlignment="Left" />
    <TextBlock x:Uid="TextBlock_2" Margin="10,0,0,0" Grid.Row="1" Text="Open:" VerticalAlignment="Center" TextWrapping="Wrap"/>
            
    </Grid>
</Window>

2.    在dotnet命令行窗口使用msbuild 为xaml统一添加uid。

msbuild /t:updateuidmul_lang.csproj

           为了方便使用也可以在vs2008中添加扩展工具

3.在 .csproj 中添加

<UICulture>en-US</UICulture>

这时候生成项目会产生特定语言的程序集Mui_lang.resources.dll。位于Bin"Debug"en-US 目录。

(注:在vs2008中可以先Unload项目,然后右键单击项目会有编辑*.csproj,编辑完后在重新载入即可)

4.使用locbaml工具分析生成的文件。

locbaml 工具从这里下载

       http://download.microsoft.com/download/B/2/5/B25C4C6A-97FE-4014-9D4B-B39607BA9A12/wpf_samples/LocBaml.exe

下载完后自己编译一下才可以使用。

然后使用locbaml生成的csv文件:

       locbaml /parse en-us/Mui_lang.resources.dll/out:Mui_lang.csv

(注意路径)

使用Excel打开 Mui_lang.csv文件。使用筛选功能筛选掉本地化类别为“None”的所有项。

然后将英文翻译成中文或其它语言,并保存。

5.使用 LocBaml 生成新的 .resources.dll 文件

Locbaml /generate en-US/Mui_lang.resources.dll /trans:Mui_lang.csv /out:." /cul:zh-CHS

运行完成后生成新的Mui_lang.resources.dll 文件,在主程序目录创建一个特定语言的文件夹例如: zh-CHS。将生成的文件复制到ZH-CHS目录下。

6.测试

       在英文操作系统下运行的效果:

      在中文操作系统下运行的效果:

在控制面板里改一下语言设置也可以(我的系统是en_xp+中文包)。

7.在程序中更改资源

       在App.xaml.cs 中添加如下代码即可

       protected override void OnStartup(StartupEventArgs e)

        {

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CHS");

            base.OnStartup(e);

        }

参考:

            http://msdn.microsoft.com/zh-cn/library/ms788718.aspx

          http://msdn.microsoft.com/zh-cn/library/ms746621.aspx

           http://msdn.microsoft.com/zh-cn/library/aa358535.aspx

代码下载:http://www.digitwest.com/demo/Mui_lang.rar

转载于:https://www.cnblogs.com/coogle/archive/2008/07/18/1245860.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值