一个简单的 iOS 工具,用于使用微软 Azure 认知服务进行文本翻译
在 Azure 认知服务上注册,可遵循此链接中的步骤:Azure 认知服务 并获取 azure 翻译密钥和令牌。
Import the "RMKAzureTranslator.h" file into your App Delegate file
Create a pointer for a String containing the obtained azure Key
Call the "initWithAzureKey" method in didFinishLaunchingWithOptions function with the above created pointer.
#import <RMKAzureTranslator/RMKAzureTranslator.h>
static NSString *const RMKAzureTranslatorKey = <Insert-your-azureKey-here>;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[RMKAzureTranslator initWithAzureKey:RMKAzureTranslatorKey];
return YES;
}
将 "RMKAzureTranslator.h" 文件导入 ViewController,调用 "translateString" 方法,传入要翻译的文本、源字符串的源 ISO 语言代码。– 如果语言未知,请将其设置为 nil,工具将自动检测,以及所需输出的目标 ISO 语言代码。
[[RMKAzureTranslator sharedInstance] translateString:@"Hello, my name is Rekha"
fromLanguage:@"en" toLanguage:@"fr" onCompletion:^(NSString *translatedString, NSError *error)
{
if(error)
{
NSLog(@"%@",error);
}
else
{
NSLog(@"%@",translatedString);
}
}]
运行应用
将以下行添加到您的 Podfile 中
pod 'RMKAzureTranslator'
FGTranslator 使用以下项目:
RMKAzureTranslator 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。