如何在iOS中编程使用语言翻译函数? [Swift 5]

发布于 2025-02-11 16:39:35 字数 586 浏览 1 评论 0 原文

我知道 uitextview ios中的文本菜单中有一个 translate 函数 (例如,请参见从Xamarin中的TextView上的选择菜单中的选项)。

我想自己使用此功能,而无需使用 translate 菜单。例如,我想翻译在 uitextview 中显示的整个句子,而不是仅翻译所选的部分。

我们可以使用特定的 func 吗?我该如何称呼此功能?

I am aware that there is a Translate function in a text menu in UITextView in iOS
(see for example Remove Translate and share options from selection menu on textview in xamarin).

enter image description here

I would like to use this function by myself without using the Translate menu. For example, I would like to translate an entire sentence displayed in a UITextView instead of translating only the selected parts.

Is there a specific func that we can use? How can I call this function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恬淡成诗 2025-02-18 16:39:35

苹果的翻译 api 不可公开提供。

https://develovement.apple.apple.com/forums/thread/650024

您可以使用Google's Googlemlkit/translate 而不是。


在iOS上使用 ML Kit

podfile 中添加 googlemlkit/translate ,通过在终端中运行以下命令。

pod 'GoogleMLKit/Translate', '3.1.0'

阅读 instal & 入门 https://cocoapods.org/ > Cocoapods ,或者您不知道该怎么做。

Google编写了非常好的示例代码。它很简单。
中读取一串文本的字符串。

https://develovelers.google.com/ml-kit/language/language/lageage/translation/translation/ios


信息:

您可能会发现此链接有帮助。

https://maximbilan.medium.com/googletrans.com/googletranslate-apeletranslate-api-api-in-swift-aift-aift-a3664884848848.848

Apple's translate API is not available to the public.

https://developer.apple.com/forums/thread/650024

You can use Google's GoogleMLKit/Translate instead.


Use ML Kit on iOS.

Add GoogleMLKit/Translate in your podfile by running the following command in the terminal.

pod 'GoogleMLKit/Translate', '3.1.0'

Read the Instal & Getting started sections on https://cocoapods.org/ if you have not set cocoapods or you do not know how to do so.

Google has written a very good sample code. It is straight forward.
Read from the Translate a string of text section onwards.

https://developers.google.com/ml-kit/language/translation/ios


info:

You may find this link helpful.

https://maximbilan.medium.com/googletranslate-api-in-swift-a36489a84508

不知在何时 2025-02-18 16:39:35

这可以从ios18获得。请参阅文档在这里

您可以使用 提供翻译表。

如果您需要对翻译的更多控制权,并且需要更多的fucntionition,那么您应该考虑使用 Translations

This is available from iOS18. See docs here.

You can use the translationPresentation to provide a Translation sheet.

If you need more control over the the translation and want more fucntionality than opening a sheet you should look at using the TranslationSession.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文