The Problem with Default Enum Labels in Multilingual Apps
Enums in Rails are stored as integers and provide methods to retrieve their symbolic names. However, if you are developing an application in multiple languages, showing raw enum values like "active", "inactive", or "banned" is not user-friendly for non-English users.
Example: Default Enum Labels in English
class User < ApplicationRecord
enum :status, { active: 0, inactive: 1, banned: 2 }
end
user = User.new(status: :active)
puts user.status # => "active"
Now, let's say we want to display the status in French (e.g., "Actif"
instead of "active"
). Without I18n, we would have to manually map these values, which is inefficient.