是否可以将大型本地化字符串交换到它们自己的文件中?
目前我正在使用 MonoTouch 完成我的第一个 iPhone 应用程序。通过“*.lproj”文件夹进行的本地化按预期工作。
拥有 UIWebView
显示一些用户指南,我使用 LoadHtmlString()
方法填充此指南。 (即不需要互联网连接)。
由于文本有点长,我不希望将其放置在“Localized.strings”文件中,而是交换到一个完全独立的文件中(因为我也在为 Windows .NET 应用程序执行此操作):
< img src="https://i.sstatic.net/iH65g.png" alt="MonoTouch 中的项目结构">
在上面的屏幕截图中,我会在每种语言文件夹中都有一个“help.html”文件,并调用LoadHtmlString
方法以类似于 NSBundle.MainBundle.LocalizedString
的方式从适当的文件中读取。
我的问题:
是否可以拥有每种语言的文件并从 MonoTouch 应用程序中访问它们?
Dimitris 解决方案的后续
基于Dimitris的解决方案,我通过以下代码解决了它:
var localizedHtmlFile = NSBundle.MainBundle.PathForResource("help", "html");
var text = File.ReadAllText(localizedHtmlFile);
helpTextView.LoadHtmlString (text, null);
Currently I'm finishing my very first iPhone application with MonoTouch. Localization through the "*.lproj" folders works as expected.
Having an UIWebView
that displays some user guidelines, I'm populating this one with the LoadHtmlString()
method. (I.e. no internet connection is required).
Since the text is a bit longer, I do not want it to be placed inside the "Localizable.strings" file but being swapped out to a completely separate file (as I'm doing it for Windows .NET applications, too):
In the above screenshot, I would have one "help.html" file inside each language folder and call the LoadHtmlString
method to read from the appropriate file in a way that would be similar to NSBundle.MainBundle.LocalizedString
.
My question:
Is it possible to have per-language files and access them from within a MonoTouch application?
Follow-up to Dimitris' solution
Based on Dimitris' solution, I solved it by this code:
var localizedHtmlFile = NSBundle.MainBundle.PathForResource("help", "html");
var text = File.ReadAllText(localizedHtmlFile);
helpTextView.LoadHtmlString (text, null);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,当然有可能。您可以像这样获取本地化文件的路径:
您可以对各种不同类型的资源(PDF、图像等)使用 PathForResource 方法。第一个参数是文件名,第二个参数是文件扩展名。检查 PathForResource 方法的其他重载以获取更多选项。
Yes, of course it is possible. You can get the path of the localized file like this:
You can use the PathForResource method for various different types of resources (PDFs, images, etc.). The first parameter is the file name and the second one is its extension. Check the other overload of the PathForResource method for more options.