# frozen_string_literal: true module DjiMqttConnect # https://developer.dji.com/doc/cloud-api-tutorial/en/feature-set/dock-feature-set/hms.html module Translations module_function def load_translations! I18n.load_path += Dir[File.expand_path(File.join(__dir__, "../../config/locales/*.yml"))] end def aircraft_in_the_sky_hms_event_code_message(code:, sensor_index:, component_index:) I18n.translate( "fpv_tip_#{code}_in_the_sky", alarmid: code, index: sensor_index + 1, component_index: component_index + 1, battery_index: battery_position(sensor_index), scope: "dji_mqtt_connect.hms_event_codes", default: code ) end def aircraft_hms_event_code_message(code:, sensor_index:, component_index:) I18n.translate( "fpv_tip_#{code}", alarmid: code, index: sensor_index + 1, component_index: component_index + 1, battery_index: battery_position(sensor_index), scope: "dji_mqtt_connect.hms_event_codes", default: code ) end def dock_hms_event_code_message(code:, sensor_index:) I18n.translate( "dock_tip_#{code}", alarmid: code, dock_cover_index: dock_cover_position(sensor_index), charging_rod_index: dock_charging_rod_position(sensor_index), scope: "dji_mqtt_connect.hms_event_codes", default: code ) end def result_message(result) I18n.translate(result, scope: "dji_mqtt_connect.result_codes", default: :default) end def position_name(position) I18n.translate(position, scope: "dji_mqtt_connect.position", default: position) end # If the text contains "%battery_index" and sensor_index is 0, use "left" to replace "%battery_index", otherwise, use "right" to replace. def battery_position(sensor_index) case sensor_index when 0 position_name("left") when 1 position_name("right") else position_name("unknown") end end # If the text contains "%dock_cover_index" and sensor_index is 0, use "left" to replace "%dock_cover_index", otherwise, use "right" to replace. def dock_cover_position(sensor_index) case sensor_index when 0 position_name("left") when 1 position_name("right") else position_name("unknown") end end # If the text contains "%charging_rod_index", when sensor_index is 0, replace "%charging_rod_index" with "front". When sensor_index is 1, use "back" instead. When sensor_index is 2, use "left" instead. When sensor_index is 3, use "right" instead. def dock_charging_rod_position(sensor_index) case sensor_index when 0 position_name("front") when 1 position_name("back") when 2 position_name("left") when 3 position_name("right") else position_name("unknown") end end end end