diff --git a/app/controllers/concerns/telegram/admin_commands.rb b/app/controllers/concerns/telegram/admin_commands.rb index d22414d..67e4e67 100644 --- a/app/controllers/concerns/telegram/admin_commands.rb +++ b/app/controllers/concerns/telegram/admin_commands.rb @@ -7,7 +7,7 @@ def channels!(*args) # Проверяем права доступа unless current_user&.is_admin? Rails.logger.warn "Unauthorized access attempt to /channels by user #{current_user&.username}" - respond_with :message, text: I18n.t('telegram_bot.channels.list.admin_only') + respond_with :message, text: I18n.t('telegram_bot.channels.admin_list.admin_only') return end @@ -22,7 +22,7 @@ def channels!(*args) channels_with_subscribers = get_channels_with_subscribers(page, per_page) if channels_with_subscribers[:channels].empty? - respond_with :message, text: I18n.t('telegram_bot.channels.list.empty') + respond_with :message, text: I18n.t('telegram_bot.channels.admin_list.empty') return end @@ -44,7 +44,7 @@ def channels!(*args) # Callback query для пагинации списка каналов def channels_page_callback_query(page = nil) unless current_user&.is_admin? - answer_callback_query(I18n.t('telegram_bot.channels.list.admin_only')) + answer_callback_query(I18n.t('telegram_bot.channels.admin_list.admin_only')) return end @@ -58,7 +58,7 @@ def channels_page_callback_query(page = nil) channels_with_subscribers = get_channels_with_subscribers(page, per_page) if channels_with_subscribers[:channels].empty? - edit_message :text, text: I18n.t('telegram_bot.channels.list.empty') + edit_message :text, text: I18n.t('telegram_bot.channels.admin_list.empty') return end @@ -125,7 +125,7 @@ def build_channels_list_message(channels_data) total_count = channels_data[:total_count] message_parts = [] - message_parts << "📊 Список каналов в системе (всего: #{total_count})" + message_parts << I18n.t('telegram_bot.channels.admin_list.title', count: total_count) message_parts << '' channels.each_with_index do |channel, index| @@ -160,7 +160,7 @@ def build_channels_list_message(channels_data) # Добавляем информацию о пагинации if total_pages > 1 message_parts << '' - message_parts << "Страница #{current_page} из #{total_pages}" + message_parts << I18n.t('telegram_bot.channels.admin_list.pagination_info', current: current_page, total: total_pages) end message_parts.join("\n") @@ -182,19 +182,19 @@ def format_subscribers_count(count) count = count.to_i if count == 0 - '0 подписчиков' + I18n.t('telegram_bot.channels.admin_list.subscribers', count: 0) elsif count == 1 '1 подписчик' elsif count >= 2 && count <= 4 "#{count} подписчика" elsif count >= 5 && count <= 20 - "#{count} подписчиков" + I18n.t('telegram_bot.channels.admin_list.subscribers', count: count) elsif count % 10 == 1 "#{count} подписчик" elsif count % 10 >= 2 && count % 10 <= 4 "#{count} подписчика" else - "#{count} подписчиков" + I18n.t('telegram_bot.channels.admin_list.subscribers', count: count) end end @@ -203,7 +203,7 @@ def format_last_post_time(last_post_at) return 'Нет постов' unless last_post_at time_ago = time_ago_in_words(last_post_at) - "Последний пост: #{time_ago}" + "#{I18n.t('telegram_bot.channels.admin_list.last_post')} #{time_ago}" end # Создает клавиатуру для списка каналов @@ -220,7 +220,7 @@ def build_channels_list_keyboard(channels_data, current_page) # Кнопка "Предыдущая" if current_page > 1 nav_buttons << callback_button( - '← Предыдущая', + I18n.t('telegram_bot.channels.admin_list.previous_page'), "channels_page:#{current_page - 1}" ) end @@ -228,7 +228,7 @@ def build_channels_list_keyboard(channels_data, current_page) # Кнопка "Следующая" if current_page < total_pages nav_buttons << callback_button( - 'Следующая →', + I18n.t('telegram_bot.channels.admin_list.next_page'), "channels_page:#{current_page + 1}" ) end @@ -236,7 +236,7 @@ def build_channels_list_keyboard(channels_data, current_page) buttons << nav_buttons if nav_buttons.any? # Кнопка закрытия - buttons << [ callback_button('✖️ Закрыть', 'close_channels_list:') ] + buttons << [ callback_button(I18n.t('telegram_bot.channels.admin_list.close'), 'close_channels_list:') ] inline_keyboard(*buttons) end @@ -244,11 +244,11 @@ def build_channels_list_keyboard(channels_data, current_page) # Callback query для закрытия списка каналов def close_channels_list_callback_query(*) unless current_user&.is_admin? - answer_callback_query(I18n.t('telegram_bot.channels.list.admin_only')) + answer_callback_query(I18n.t('telegram_bot.channels.admin_list.admin_only')) return end - answer_callback_query('Список каналов закрыт') + answer_callback_query(I18n.t('telegram_bot.channels.admin_list.closed')) # Удаляем сообщение или заменяем его на простое сообщение begin diff --git a/app/controllers/concerns/telegram/subscription_commands.rb b/app/controllers/concerns/telegram/subscription_commands.rb index ebdb626..8697c41 100644 --- a/app/controllers/concerns/telegram/subscription_commands.rb +++ b/app/controllers/concerns/telegram/subscription_commands.rb @@ -76,7 +76,7 @@ def confirm_remove_callback_query(channel_id) # Построить текст списка подписок def build_subscriptions_list(subscriptions) - text = "#{I18n.t('telegram_bot.channels.list.title')}\n\n" + text = "#{I18n.t('telegram_bot.channels.list.title', count: subscriptions.count)}\n\n" text += "#{I18n.t('telegram_bot.channels.list.total', count: subscriptions.count)}\n\n" subscriptions.each do |subscription| diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 7240315..48571ff 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -180,7 +180,7 @@ ru: confirm_remove: "Удалить %{channel} из подписок?" remove_success: "Канал %{channel} удалён из подписок" - list: + admin_list: title: "📊 Список каналов в системе (всего: %{count})" admin_only: "🚫 У вас нет прав для выполнения этой команды. Доступно только администраторам." empty: "📭 В системе пока нет каналов." diff --git a/test/controllers/telegram/admin_commands_test.rb b/test/controllers/telegram/admin_commands_test.rb index 20b81fc..8922fd2 100644 --- a/test/controllers/telegram/admin_commands_test.rb +++ b/test/controllers/telegram/admin_commands_test.rb @@ -255,7 +255,7 @@ def create_test_subscriptions message_content = extract_message_content(@bot.requests) assert_not_nil message_content - assert_includes message_content[:text], I18n.t('telegram_bot.channels.list.admin_only') + assert_includes message_content[:text], I18n.t('telegram_bot.channels.admin_list.admin_only') end test 'channels list shows message with available channels' do