Terms of Service"的本地化解决方案-6ren"> Terms of Service"的本地化解决方案-我有这个应用程序,在注册屏幕上的复选框旁边应该是一个句子:我同意公司服务条款。 服务条款部分应该是可点击的,以便用户能够进入 ToS 屏幕(尽管用户永远不会这样做)。 问题是,这个应用程序将是多语言的-6ren">
gpt4 book ai didi

ios - "I agree to the Company Terms of Service"的本地化解决方案

转载 作者:行者123 更新时间:2023-11-30 11:05:41 26 4
gpt4 key购买 nike

我有这个应用程序,在注册屏幕上的复选框旁边应该是一个句子:我同意公司服务条款服务条款部分应该是可点击的,以便用户能够进入 ToS 屏幕(尽管用户永远不会这样做)。

问题是,这个应用程序将是多语言的,因此所有文本都应该本地化。这就是为什么简单的 String + Button 解决方案不起作用:

ㅁ我同意公司服务条款

서비스 용약관에 동의합니다

在英语中,这个可点击部分(粗体文本)位于句子的末尾,而在韩语中,它位于句子的开头。在某些其他语言中,它可能位于中间。

问题:我该如何解决这个问题?有一些优雅的方法来做到这一点吗?两个 Storyboard?

最佳答案

我就是这样做的:

let attributes: [NSMutableAttributedString.Key : Any] = [
.font: UIFont.systemFont(ofSize: 15),
.foregroundColor: UIColor.init(red: 240/255, green: 230/255, blue: 239/255, alpha: 1)
]

let attributedString = NSMutableAttributedString(string: "tos_string".localized, attributes: attributes)
let rangeTOS = (attributedString.string as NSString).range(of: "tos_string_TOS".localized)
let rangePP = (attributedString.string as NSString).range(of: "tos_string_PP".localized)

attributedString.addAttribute(NSAttributedString.Key.link, value: "https://www.example.com/resources/pages/terms.html", range: rangeTOS)
attributedString.addAttribute(NSAttributedString.Key.link, value: "https://www.example.com/resources/pages/privacy.html", range: rangePP)


let linkAttributes: [NSAttributedString.Key : Any] = [
NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.init(red: 240/255, green: 166/255, blue: 202/255, alpha: 1),
]

textView.linkTextAttributes = linkAttributes
textView.attributedText = attributedString
textView.delegate = self

其中tos_string、tos_string_TOStos_string_PP是:

"tos_string" = "I agree to the Company Terms of Service and Privacy Policy";
"tos_string_TOS" = "Terms of Service";
"tos_string_PP" = "Privacy Policy";

Localized.strings

谢谢@Larme 的指导!

关于ios - "I agree to the Company <clickable>Terms of Service</clickable>"的本地化解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52763025/

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