Module: DynamicLocalizationConcern

Extended by:
ActiveSupport::Concern
Included in:
Api::Partner::ReservationSummarySerializer
Defined in:
app/serializers/concerns/dynamic_localization_concern.rb

Overview

Concern for handling dynamic localization in serializers

This concern provides methods to dynamically translate static data that was stored with translations from sync time, ensuring the data is displayed in the current user's language preference.

## Problem Solved Previously, service type titles and reservation statuses were being saved with static translations (e.g., “Dine In” in English) during the summary sync process, rather than being dynamically localized based on the current user's language preference.

## Usage Examples

### Basic Usage in Serializers

class MySerializer < BaseSerializer
  include DynamicLocalizationConcern

  attribute :package_type do |object|
    MySerializer.localize_package_type_data(object.payment_summary_data&.dig('package_type'))
  end

  attribute :reservation_status do |object|
    MySerializer.localize_reservation_status_data(object.reservation_status_data)
  end
end

### For Other Serializers with Similar Issues This concern can be used in other serializers that have similar localization issues:

  • Api::Partner::ReservationSerializer (reservation_status attribute)

  • Api::Dashboard::V2::ReservationSerializer (reservation_status attribute)

  • Any serializer that uses dine_in_status_partner or partner_status_property methods

## Supported Translations

### Service Types

  • dine_in → I18n.t('service_type.dine_in')

  • delivery → I18n.t('service_type.delivery')

  • pick_up → I18n.t('service_type.pick_up')

### Reservation Statuses

  • pending_arrival → I18n.t('views.booking.pending_arrival')

  • arrived → I18n.t('views.booking.arrived')

  • cancelled → I18n.t('views.booking.canceled')

  • cancel_modified → I18n.t('views.booking.cancel_modified')

  • no_show → I18n.t('views.booking.no_show')

  • refund → I18n.t('views.booking.refund')

  • pending_confirmation → I18n.t('views.booking.pending_confirmation')

  • rejected → I18n.t('views.booking.rejected')

  • order_being_prepared → I18n.t('views.booking.order_being_prepared')

## Language Support All methods support the full range of available locales:

  • English (en)

  • Thai (th)

  • Chinese (cn)