2011-05-11 337 views

回答

1

我和:debug => :request測試過它:

{:key=>"--", :q=>"To prevent abuse, Google places limits on API requests.\nUsing a valid OAuth 2.0 token or API key allows you to exceed \nanonymous limits by connecting requests back to your project.", :target=>"ru"}

,正如你可以看到它不是創業板故障。所以,to_lang也可以翻譯數組。如果您要寫["one", "two", "three"].to_russian之類的內容,那麼這將是對Google API的一個請求。

UPDATE:

irb(main):001:0> str = "test1\ntest2\ntest3" 
=> "test1\ntest2\ntest3" 
irb(main):002:0> arr = str.split("\n") 
=> ["test1", "test2", "test3"] 
irb(main):003:0> str = arr.join("\n") 
=> "test1\ntest2\ntest3" 
+0

我不知道我有你的想法。你建議用'「\ n」'分割原始文本,並翻譯結果數組?如果是的話,我怎麼知道在哪裏插入''\ n「'? – 2011-05-11 12:57:53

+0

我已經更新了我的答案 – 2011-05-11 13:02:25

+0

翻譯的結果是字符串而不是數組。 ''「\ n」'應該被插入到字符串中...... – 2011-05-11 13:10:15