I want to Localize an AttributedString from my Storyboard but XCode only localizes plain text strings. Is it possible?

huangapple go评论59阅读模式
英文:

I want to Localize an AttributedString from my Storyboard but XCode only localizes plain text strings. Is it possible?

问题

我创建了一个新项目来测试我的真实场景,事情很简单。我在Storyboard上有一个UILabel,它被选择为Attributed,并更改了一些属性,如字体和前景颜色,以模拟我的实际情况。然后,我添加了一个新的UILabel,但这次选择为普通文本。然后,我选择了将Storyboard本地化为英语和西班牙语的选项,但生成的字符串文件只包含了普通文本类型的文本,忽略了Attributed 类型的文本。

我尝试了从头开始生成一个新的Storyboard,使用最新版本的XCode,但仍然不起作用。

我是否遗漏了什么?

英文:

I've created a new project to test my real scenario, the thing is simple. I have a UILabel on my Storyboard selected as Attributed and changed some attributes like font and foreground color in order to simulate my real case. Then, added a new UILabel but this time selected as a plain text. From there, I've selected the option to localize the Storyboard in English and Spanish but the resulting String files just contain the text of UILabel plain type, leaving out the Attributed ones.

I want to Localize an AttributedString from my Storyboard but XCode only localizes plain text strings. Is it possible?

I want to Localize an AttributedString from my Storyboard but XCode only localizes plain text strings. Is it possible?

I've tried to generate a new storyboard from start, using the most recent version of XCode but stills not working.

Is there something that i’m missing?

答案1

得分: 0

不,你没有遗漏任何东西。这都很简单:不要这样做。如果你想本地化要通过属性字符串显示的文本,你需要在代码中构建属性字符串,调用 NSLocalizedString(或其他方法)来获取本地化文本,并同样在代码中将其显示在界面上。

(更好的方法是,不要使用故事板,这是另一天的话题。)

英文:

No, you're not missing anything. It's all pretty simple: Don't Do That. If you want to localize text to be displayed via an attributed string, you'll have to build that attributed string in code, calling NSLocalizedString (or whatever) to obtain the localized text, and get it into the interface in code as well.

(Even better, save yourself a headache and don't use storyboards. But that's for another day.)

huangapple
  • 本文由 发表于 2023年3月31日 03:45:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定