我正在尝试使用rails 5.2.4在我的本地环境的控制台中执行一些代码
我有宝石
gem 'google-cloud-translate'我想在本地翻译一个字符串,我做到了:
parent = @client.class.location_path ENV['CLOUD_PROJECT_ID'], 'us-central1'
response = @client.translate_text ["madrid"], "en", parent
response.translations.first.translated_text但是我得到了这个错误;(对于我的生产环境,使用Heroku控制台,我没有得到相同代码的任何错误)
+[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.发布于 2021-09-08 11:17:29
你可以使用谷歌推荐的Ruby client library来根据你的需求进行翻译。
下面是我用来执行转换的代码:
require "google/cloud/translate/v2"
translate = Google::Cloud::Translate::V2.new(
project_id: "< PROJECT ID >",
credentials: "< Change to your key.json file path >"
)
translation = translate.translate "Hello world!", to: "la"
puts (translation.text); 输出:
蒙杜斯万岁!
https://stackoverflow.com/questions/69086295
复制相似问题