ruby-on-rails – Rails distance_of_time_in_words返回“en,abo
发布时间:2020-12-17 04:26:55 所属栏目:百科 来源:网络整理
导读:我有一个奇怪的问题,希望有人知道问题是什么…… 使用distance_of_time_in_words(以及因此time_ago_in_words)不返回实际时间距离.相反,它返回的内容包括“en,about_x_hours”或“en,x_minutes”. 模式是正确的,如: time_ago_in_words(50.minutes.ago) = "en
我有一个奇怪的问题,希望有人知道问题是什么……
使用distance_of_time_in_words(以及因此time_ago_in_words)不返回实际时间距离.相反,它返回的内容包括“en,about_x_hours”或“en,x_minutes”. 模式是正确的,如: time_ago_in_words(50.minutes.ago) => "en,about_x_hours" time_ago_in_words(3.minutes.ago) => "en,x_minutes" 但是,为什么它在显示“x”而不是实际数字,“_”而不是空格,以及“en”,在所有这些的开头?! 解决方法
这会通过I18n-gem返回一个字符串来翻译….尝试以下内容:
# I18n.localize(string) I18n.l time_ago_in_words(3.minutes.ago) 然后添加(如果不存在) # config/locales/en.yml en: datetime: distance_in_words: ... less_than_x_minutes: one: "less than a minute" other: "less than %{count} minutes" x_minutes: one: "1 minute" other: "%{count} minutes" about_x_hours: one: "about 1 hour" other: "about %{count} hours" .... 并确保在en.yml中包含以下(可能是自定义的)数据: http://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml 请告诉我它是否有效.. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |