我们可以使用全球化宝石对模型中的文本字段进行全球化。为了全球化(翻译)员工的“指定”属性,我们在employee模型中使用translates :designation,employee.translations为employee对象打印翻译(每个受支持的地区有一个对象,并在相应的区域设置中指定)。
我有一个模型特定的属性(雇员的图像),这是一个回形针附件。需要使图像全球化,这样employee.image将为默认区域设置(:en)提供实际图像,employee.image.translations将返回图像的所有翻译(每个受支持的区域设置有一个图像/回形针附件)
如何使rails中的回形针附件全球化?
发布于 2015-05-15 12:10:59
当我们向Employee模型添加回形针附件image时,会添加一组属性。我没有尝试翻译回形针附件,而是在父员工model.The属性中添加了这些属性的转换,这些属性被添加为image_file_name, image_content_type, image_file_size and image_file_updated_at。所以,添加
translates :image_file_name, :image_content_type,
:image_file_size, :image_file_updated_at使用这些附加列为employee模型运行必要的转换表迁移有助于使回形针附件全球化。
现在,employee.translations将为每个受支持的地区返回一个对象,每个对象都将为相应的区域设置返回designation, image_file_name, image_content_type, image_file_size and image_file_updated_at。
https://stackoverflow.com/questions/30240195
复制相似问题