Locbaml 如何发挥作用?

发布于 2024-10-16 09:49:18 字数 687 浏览 5 评论 0原文

我创建了一个 WPF 测试项目,一个窗口,其中有一个按钮。然后,我卸载了该项目并修改了 csproj 以包含以下 en-US。重建后,构建文件夹现在包含一个名为 en-US 的子文件夹,并且包含一个名为 WpfLocalizationTest.resources.dll 的文件。到目前为止一切都清楚了。

然后我下载了 Locbaml 的源代码并构建了它。 (无法在任何地方找到二进制下载,请自行查找。)

然后我将 Locbaml.exe 复制到 en-US 文件夹并尝试了以下操作。

locbaml /parse WpfLocalizationTest.resources.dll /out:test.csv

这会导致错误“无法加载文件或程序集 WpfLocalizationTest.resources.dll 或其依赖项之一”。尝试加载格式不正确的程序。”

在 obj\x86\Debug 文件夹中,有一个名为 WpfLocalizationTest.g.en-US.resources 的文件。我尝试对此运行 locbaml,但结果是相同的。

locbaml 应该如何使用? MSDN 上充满了愚蠢的示例,但没有一个有效。 locbaml 真的是 Microsoft 想要的 WPF 应用程序本地化方式吗?或者他们是否为这项工作找到了合适的工具?

I created a WPF test project, single Window with a single button in it. I then unloaded the project and modified the csproj to contain the following <UICulture>en-US</UICulture>. After rebuilding the build folder now contains a subfolder named en-US and it contains a file called WpfLocalizationTest.resources.dll. All clear so far.

Then I downloaded the source code for Locbaml and built it. (Couldn't find a binary download anywhere, go figure.)

Then I copied the Locbaml.exe to the en-US folder and tried the following.

locbaml /parse WpfLocalizationTest.resources.dll /out:test.csv

This results in an error 'Could not load file or assembly WpfLocalizationTest.resources.dll or one of its dependencies. An attempt was made to load a program with an incorrect format.'

In the obj\x86\Debug folder there's a file called WpfLocalizationTest.g.en-US.resources. I tried running locbaml on that, but the result was the same.

How is locbaml supposed to be used? MSDN is full of cockamamie samples, none of which work. Is locbaml really how Microsoft intends WPF apps to be localized? Or have they come up with proper tools for the job?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花之痕靓丽 2024-10-23 09:49:18

当我继续搜索时,我在 Stackoverflow 上找到了另一个链接。我们最初收到的编译错误与未针对 .Net4.0 设置过时的 LocBaml 项目有关。这就是为什么我无法从 DLL 生成 CSV,而不得不直接访问资源文件。请点击此链接了解更多详细信息。 .net wpf4 应用程序的 Locbaml 本地化

此链接提供指向 .net 4 的链接编译后的二进制文件允许您直接进入 dll,使用 LocBaml 生成 CSV。

As I continue to search I found another link here on Stackoverflow. The compile errors we were originally receiving were related to an outdated LocBaml project not being set for .Net4.0. This is why I was unable to generate teh CSV from the DLL and had to go straight at the resource file. Follow this link for more details. Locbaml localization of .net wpf4 application

This link provides a link to .net 4 binaries which once compilied allow you to go straight at the dll to generate the CSV using LocBaml.

誰ツ都不明白 2024-10-23 09:49:18

只是我今天早上提取笔记的更新。希望这能帮助您走得更远。

项目编译完成后,将 LocBaml.exe 复制到生成生成的项目目录:在我的实例中,我将文件复制到 E:\localiztion_sample\localiztion_sample\obj\x86\Release

这是棘手的部分,因为build 不包含 bin 目录中的所有 DLL 文件(telerik 控件和其他程序集)。结果我进入 bin\release\ 并将所有 DLL 和资源文件从那里复制到 obj\x86\Release 目录中。对于提示我覆盖的文件,我查看文件大小或创建日期是否存在差异,如果没有,我会跳过这些对象的副本。

注意:为了生成 CSV,我必须从 bin 目录复制 dll 和资源文件并将它们放在 obj 目录中。忽略此步骤将导致 CSV 文件被创建但未填充数据。

将必要的文件复制到该目录后,您将解析位于 Release 目录中的 .resource 文件。

在我的项目中,资源文件位于:

E:\localiztion_sample\localiztion_sample\obj\x86\Release

文件名标题为:localiztion_sample.g.en-US.resources

注意: 这是不同的来自微软网站上的说明。 Microsoft 声明您应该对位于 en-US 目录中的 dll 文件运行 LocBaml 工具。然而,经过多次尝试和研究,我发现这实际上导致了 32 位和 64 位版本之间的许多兼容性问题,而且根本无法正常工作。

在阅读 wpf4 unleashed 以及在线论坛时,建议改为指向 *.gen.en-Us.resources 文件。 * = 项目名称和 gen.en-Us 反映了选择的开发语言

在 VS 命令中,直到您需要输入以下

LocBaml /parse filename.resources /out:sample-en.csv

注意: 假设您已将 LocBaml 文件复制到该文件所在的根目录,并且您正在以系统管理员身份运行命令提示符。为了便于使用,我将命令提示符中的工作目录更改为 VS 项目目录

对于我的示例项目,该命令如下所示:

*LocBaml /parse localization_sample.g.en-US.resources /out:sample-en.csv*

这然后命令生成 CSV 文件,该文件充当当前项目的定义

据我所知,我能够修改文件并重新生成 dll,但我无法在应用程序中更改区域性,所以我仍在创作这件作品。一旦我开始工作,我就会重新发布。

Just an update I pulled my notes this morning. Hopefully this will help get you a bit further along.

Once the project has been compiled copy the LocBaml.exe to the project directory where the build has been generated : In my instance I copied the file to E:\localiztion_sample\localiztion_sample\obj\x86\Release

This is the tricky part in that the build did not contain all the DLL files from the bin directory (telerik controls and other assemblies). As a result I went to bin\release\ and copied all the DLL and resource files from there into the obj\x86\Release directory. For files where I was prompted to overwrite I looked to see if there was a difference in filesize or date created and if not I skipped the copy for these objects.

NOTE: In order for me to generate the CSV I had to copy dll and resource files from the bin directory and place them in the obj directory. Omitting this step will result in the CSV file being created but not populated with data.

Once you have copied the necessary files to the directory you will then parse the .resource file located within the Release directory.

In my project the resource file was located at:

E:\localiztion_sample\localiztion_sample\obj\x86\Release

And the file name was titled: localiztion_sample.g.en-US.resources

Note: this is different from the instruction on the Microsoft website. Microsoft states that you should run the LocBaml tool on the dll file located within the en-US directory. However after multiple attempts and research I found that this in fact caused a number of problems with compatibility between 32 and 64-bit builds as well as it just flat out not working.

In reading through wpf4 unleashed as well as online forums it is suggested to instead point to the *.gen.en-Us.resources file. * = the project name and gen.en-Us reflects the development language chosen

Within the VS command untility you will then need to enter the following

LocBaml /parse filename.resources /out: sample-en.csv

Notes: It is assumed that you have copied the LocBaml file to the root directory where this file exists and that you are running the command prompt as system administrator. For ease of use I changed the working directory within the command prompt to the VS project directory

For my sample project the command looked as:

*LocBaml /parse localization_sample.g.en-US.resources /out: sample-en.csv*

This command then generates the CSV file which acts as a definition of the current project

This was as far as I got I was able to modify teh file and regenerate the dll but I was not able to get the culture to change within the application so I am still working on this piece. I'll reposte once I get it working.

薄荷港 2024-10-23 09:49:18

1) 卸载要本地化的项目

2) 编辑项目 .cproj 文件

3) 在最后一个属性组的末尾添加属性组

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>   
</PropertyGroup>   

en-GB

4) 重新加载项目并编译,这将在 bin\debug 位置的 en-GB 文件夹内创建一个附属程序集“yourlibrary.resources.dll”,该程序集将是默认程序集。

5) 打开 Properties\AssemblyInfo.cs 文件并取消注释此行 [程序集:NeutralResourcesLanguage("en-GB", UltimateResourceFallbackLocation.Satellite)] 这是一个后备附属程序集。我们需要此条目,否则对于 wpf 应用程序,它会引发 app.xaml.cs 无法加载的异常

6) 从命令提示符运行此命令,该命令使用 msbuild 生成 UID C:\Windows\Microsoft.NET\Framework64\v4.0.30319 \MSBuild /t:updateuid 。 \yourlibrary.csproj,打开 xaml 文件并检查您的控件,所有元素上都会有 UID。

7) 从 https://github.com/JeremyDurnell/locbaml 下载locabaml.exe源代码工具

8 ) 将 locabaml.exe 文件复制到 \yourprojectname\bin\debug 文件夹

9) 我们现在将为法语创建一个附属程序集。首先,我们需要解析默认的卫星程序集并将内容写入 csv 文件,如下所示

10:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild /parse C:\yourprojectname\bin\Debug\yourlibrary。 resources.dll /out:C:\yourprojectname\bin\Debug\yourlibrary.resources_FR.csv

11) 打开 yourlibrary.resources_FR.csv 进行必要的翻译

12) 现在我们需要使用命令行创建一个法语附属程序集

13) C: \Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild /生成 C:\yourprojectname\bin\Debug\yourlibrary.Resources.dll /trans: C:\yourprojectname\bin\Debug\yourlibrary.resources_FR.csv /out: C:\yourprojectname\bin\Debug\temp /cul:fr-FR

14) 上面的命令将在 \bin\debug 位置创建一个文件夹 fr-FR

15) 将您的计算机区域设置切换为 french(France)

16) 在代码集本地化为 Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;

17) 编译并运行应用程序,您将在控件上看到翻译后的文本

1) Unload project you want to localise

2) Edit Project .cproj file

3) Add property group at the end of the last property group

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>   
</PropertyGroup>   

en-GB

4) Reload project and compile this would create a satellite assembly "yourlibrary.resources.dll" inside en-GB folder at bin\debug location, this assembly would be the default assembly.

5) Open Properties\AssemblyInfo.cs file and uncomment this line [assembly: NeutralResourcesLanguage("en-GB", UltimateResourceFallbackLocation.Satellite)] this is a fallback satellite assembly. And we need this entry otherwise for wpf application it throws exception around app.xaml.cs couldn't load

6) From command prompt run this command which uses msbuild to generate UID C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild /t:updateuid . \yourlibrary.csproj, open xaml file and check your controls there would be UID on all elements.

7) Download locabaml.exe source code tool from https://github.com/JeremyDurnell/locbaml

8) Copy locabaml.exe file to the \yourprojectname\bin\debug folder

9) we would now create an satellite assembly for french. First we need to parse the default satellite assembly and write out the contents to a csv file as shown here

10:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild /parse C:\yourprojectname\bin\Debug\yourlibrary.resources.dll /out:C:\yourprojectname\bin\Debug\yourlibrary.resources_FR.csv

11) Open yourlibrary.resources_FR.csv make necessary translations

12) Now we need to create a satellite assembly in french using command line

13) C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild /generate C:\yourprojectname\bin\Debug\yourlibrary.Resources.dll /trans: C:\yourprojectname\bin\Debug\yourlibrary.resources_FR.csv /out:C:\yourporjectname\bin\Debug\temp /cul:fr-FR

14) The command above would create a folder fr-FR at \bin\debug location

15) Switch your computer region settings to french(France)

16) In the code set localisation to Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;

17) Compile and run application you would see translated text on the controls

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文