1
我使用Ruby on Rails製作了一個阿拉伯語Web應用程序,我如何將time_ago_in_words函數的結果轉換爲阿拉伯語言?如何將time_ago_in_words func的值轉換爲我的語言?
或者我應該寫我自己的功能?
我使用Ruby on Rails製作了一個阿拉伯語Web應用程序,我如何將time_ago_in_words函數的結果轉換爲阿拉伯語言?如何將time_ago_in_words func的值轉換爲我的語言?
或者我應該寫我自己的功能?
如果你看看distance_of_time_in_words
方法的文檔,其中time_ago_in_words
引擎蓋下使用,你會看到,你可以通過自定義轉換查找一個scope
選項:
隨着
scope
選項,你可以定義Rails的自定義範圍將翻譯爲 。例如,您可以在您的語言環境中定義以下內容(例如en.yml)。
datetime: distance_in_words: short: about_x_hours: one: 'an hour' other: '%{count} hours'
見github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml爲 更多的例子。
那麼這將導致以下:
from_time = Time.now distance_of_time_in_words(from_time, from_time + 50.minutes, scope: 'datetime.distance_in_words.short') # => "an hour" distance_of_time_in_words(from_time, from_time + 3.hours, scope: 'datetime.distance_in_words.short') # => "3 hours"