gpt4 book ai didi

ios - 从 Storyboard 中本地化属性化的 UITextView

转载 作者:IT王子 更新时间:2023-10-29 08:11:21 25 4
gpt4 key购买 nike

我正在使用 Storyboard 并有一个 View ,其中我对一些 UITextView 进行了子类化。

我的问题是我正在使用 ibtool --generate-strings-file 从 Storyboard中提取字符串以进行本地化,然后在另一个 Storyboard文件上使用 ibtool -write应用翻译后的字符串。

当我使用 ibtool 时,ibtool --generate-strings-file 命令会忽略任何具有属性文本的 UITextView,并从生成的字符串文件中忽略。

是否可以从 Storyboard 中提取属性文本以进行本地化?

最佳答案

在 Xcode 6.1 上,最好的方法是将 TextView 的属性文本复制到“BASE”RTF 文本(例如使用 TextEdit 或直接从 XCode > New File > ressources > RTF)。

通过 TextEdit 方式,您需要将文本导入到您的项目中。显然,如果您是通过 Xcode 完成的,则无需导入任何内容。

然后只需使用实用程序面板找到“本地化...”按钮,它就会为您完成。

要导入正确的版本只需执行(例如在 viewWillAppear 中),

 NSURL *url = [[NSBundle mainBundle] URLForResource:[fileName stringByDeletingPathExtension] withExtension:[fileName pathExtension]];
NSError *error;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithFileURL:url
options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType}
documentAttributes:nil
error:&error];

[_originalMessage setAttributedText:attributedString];

Swift 4 更新:

var attrString: NSAttributedString?
let fileUrl: URL = Bundle.main.url(forResource: "mytextfile", withExtension: ".rtf")!

do {
attrString = try NSAttributedString(url: fileUrl, options: [.documentType:NSAttributedString.DocumentType.rtf], documentAttributes: nil)
} catch {
// Somebody do something!!
}

关于ios - 从 Storyboard 中本地化属性化的 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14459860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com