最终用户想要动态添加语言到他的网站
我们必须使用 C# 在 ASP.NET 中为客户构建一个活动注册网站。 要求之一是客户希望使用 Excel 文件自行向其网站添加新的外语。我知道如何在 Visual Studio 中制作多语言网站,但我不知道如何在代码中基于 excel 文件生成资源文件。 我还注意到 VS 生成了第二个名为 Resource.en.designer.cs 的文件,但我也找不到任何如何生成该文件的文档。
顺便说一句,最终用户与 IT 无关。不过(显然)他知道如何处理Excel。
任何帮助表示赞赏!
约里
编辑: !Robert Levy 提供了一个好方法! 操作方法:
第 1 步: 读取 Excel 文件(使用 OleDBAdapter 对我来说是最好的方法,因为您可以使用列标题等) 将语言写入以下格式的 txt 文件: 键=翻译 没有空格或其他任何东西
第 2 步: 在您的计算机上找到 ResGen.exe(它随 Visual Studio 一起提供,因此请查找类似 c:\program files\visual studio\sdk 的位置...但是我找到了它 @ C:\Program Files (x86)\Microsoft SDKs\Windows\ v7.0A\Bin\ResGen.exe)
第 3 步:
使用 Process.Start("resgen.exe") 调用 exe 提示:使用 ProcesStartInfo 进行简单的参数和首选项设置
(第 4 步:)
将文件移动到您想要的位置(我发现 App_GlobalResources 工作得很好)
第 5 步:
将用户 currentUIculture 设置为您想要的文化!
We have to build an event registration website for our client in ASP.NET using C#.
One of the requirements is that the client wants to add new foreign languages to his website himself using en excel file. I know how to make a website multilingual in Visual Studio, but I have no idea how to generate a resource file based on an excel file in code.
I also noticed VS generates a second file called Resource.en.designer.cs but I can't find any documentation how to generate that file either.
btw, the enduser is anything but IT-related. He knows his way around excel though (obviously).
Any help is appreciated!
Yoeri
EDIT:
!Robert Levy Provided a good method!
HOW TO:
STEP 1:
Read the excel file (using an OleDBAdapter was the best method for me, as you can use column headers etc)
Write the language to a txt file in this format:
KEY=TRANSLATION
no spaces or anything else
STEP 2:
Locate ResGen.exe on your computer (it comes with Visual Studio, so look somewhere like c:\program files\visual studio\sdk... however I found it @ C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe)
STEP 3:
Invoke the exe with Process.Start("resgen.exe")
hint: use ProcesStartInfo for easy argument and preferences settings
(STEP 4:)
Move the file to your desired location (I find the App_GlobalResources works perfectly)
STEP 5:
Set the user currentUIculture to your desired culture!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ResGen.exe 将为您编译资源文件。您可以让他以该工具使用的格式提供文本文件,也可以编写您自己的代码从 Excel 中提取以生成文本文件。然后只需调用此 EXE 并部署新生成的资源 DLL。我假设您已经知道如何从资源文件中读取内容并根据用户偏好使用适当的文件。
http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx
ResGen.exe will compile resource files for you. You could either get him to deliver text files in the format used by that tool or write your own code that extracts from excel to generate the text files. Then just invoke this EXE and deploy your newly generated resource DLL. I am assuming you already know how to read things from resource files and use the appropriate one based on user preference.
http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx
这可能是您希望使用数据库资源而不是简单的 resx 文件的地方。用 Excel 数据填充数据库表比将其转换为标准 resx 文件更容易(如果 MS 决定修改文件格式,将来可能会出现问题)。
因此,我建议您编写自己的 ResourceReader ,它将从数据库加载字符串 (它也可以直接从 Excel 加载,但出于多种原因我不推荐这种方法)。
This is probably one place where you would like to use resources from database rather than simple resx files. It would be easier just to populate database table(s) with Excel data than transforming it to standard resx file (it could be a problem in the future if MS decided to modify file format).
So I would suggest you to write your own ResourceReader which would load strings from database (it could load it directly from Excel as well, but for many reasons I wouldn't recommend this method).
您应该询问您的最终用户,他们是否真的需要“即时”获取另一种语言,以及他们希望添加多少种语言。
否则,通过电子邮件将 Excel 文件发送给您并手动创建资源文件可能是迄今为止最便宜的解决方案......
You should ask your end-user if they really have to get another language 'on the fly' and how many languages they expect they are going to add.
Otherwise, e-mailing the Excel file to you and manually creating the resource file might be by far the cheapest solution....