本地化图像的最佳方法

Iru*_*dji 12 ruby-on-rails internationalization

在i18n rails应用程序中本地化图像(按钮和其他内容)的最佳方法是什么?

Sim*_*tti 26

我通常在每个路径或图像名称中注入语言环境名称.在第一种情况下,为不同的区域设置创建不同的文件夹

/public/images/en/file.png
/public/images/it/file.png

image_tag("#{I18n.locale}/file.png")
Run Code Online (Sandbox Code Playgroud)

在第二种情况下

/public/images/file.it.png
/public/images/file.en.png

image_tag("file.#{I18n.locale}.png")
Run Code Online (Sandbox Code Playgroud)

我通常更喜欢第二种解决方案,因为有许多资产我不需要本地化,我经常需要将翻译/公共资产保存在同一文件夹中以利用配置模式.