towerops/GETTEXT_MIGRATION_NOTES.md
2026-02-02 13:00:27 -06:00

4.3 KiB

Gettext Migration Progress Notes

Current Status: Phase 2 Nearly Complete

Completed Phases

  1. Phase 1: Infrastructure - DONE (previous session)

    • Created gettext helpers with domain-specific functions
    • Set up pot files for each domain
    • Created mix populate_english task
  2. Phase 2: Equipment Features - DONE

    • DeviceLive.Index: device discovery, reordering, error messages
    • DeviceLive.Show: backup messages, permission errors
    • DeviceLive.Form: device CRUD operations
    • AlertLive.Index: alert acknowledgment messages
    • SiteLive.Show: site discovery messages
    • SiteLive.Form: site CRUD and SNMP/agent propagation
    • All equipment tests passing (7/7)
  3. Phase 2: Admin Features - DONE

    • Admin.UserLive.Index: user deletion messages
    • Admin.OrgLive.Index: organization deletion messages
    • UserAuth: impersonation start/stop messages (3 strings)
    • All admin tests passing (87 tests)
  4. Phase 2: Core Components - DONE

    • ConsentPrompt component migrated:
      • Modal title, policy review message
      • Policy acceptance labels
      • Consent disclaimer text
      • Accept button text
  5. Phase 2: Auth Flash Messages (user_auth.ex) - DONE

    • Migrated ALL remaining auth messages in user_auth.ex:
      • Plug functions: require_sudo_mode, require_authenticated_user, require_superuser
      • load_current_organization (3 messages)
      • LiveView on_mount callbacks (all auth-related messages)
    • Added use Gettext, backend: ToweropsWeb.Gettext to user_auth.ex
    • Added import ToweropsWeb.GettextHelpers to user_auth.ex

🔄 Remaining Work

Still Need to Migrate

  1. UserSettingsLive session management (lib/towerops_web/live/user_settings_live/session_manager.ex):

    • Line 16: "Mobile device removed successfully."
    • Line 20: "Failed to remove mobile device."
    • Line 39: "Failed to update alert preferences."
  2. Policy consent message (lib/towerops_web/user_auth.ex):

    • Line 659: "Thank you for accepting the updated policies."
  3. Other scattered flash messages - Need to grep for remaining untranslated strings

Final Steps (Phase 3)

  1. Extract new strings: mix gettext.extract
  2. Populate English: mix populate_english
  3. Run full test suite: mix test
  4. Run precommit: mix precommit
  5. Commit final changes
  6. Update design document status

Git Commits So Far

  1. 89a076f - Equipment features + sudo mode test fixes
  2. a995e62 - Admin features migration
  3. 2ef154e - Core components (consent prompt)
  4. PENDING - Auth flash messages (user_auth.ex - just completed, not committed yet)

Files Modified (Not Yet Committed)

  • lib/towerops_web/user_auth.ex - All auth flash messages migrated to t_auth()

Next Steps to Resume

  1. Migrate remaining 4 flash messages:

    • session_manager.ex (3 messages)
    • user_auth.ex line 659 (1 message)
  2. Run mix gettext.extract && mix populate_english

  3. Test everything:

    mix test
    mix precommit
    
  4. Commit the auth messages:

    mix format && git add -A && git commit -m "feat: migrate authentication flash messages to gettext"
    
  5. Migrate final remaining messages and create final commit

  6. Update todo list to mark phase complete

Helper Functions Reference

  • t_equipment(msg) - Equipment domain (devices, sites, alerts, agents)
  • t_admin(msg) - Admin domain (user management, org management, impersonation)
  • t_auth(msg) - Auth domain (login, TOTP, sudo mode, permissions)
  • gettext(msg) - Default domain (generic UI strings)

All helpers support interpolation: t_equipment("Device %{name} created", name: device.name)

User Question Answered

Agent WebSocket Connection Issue: User tried connecting agent to http://localhost:4000 but got WebSocket errors.

Solution provided:

  • Agent auto-converts http://localhost:4000 to ws://localhost:4000/socket/agent/websocket
  • Suggested troubleshooting:
    1. Verify Phoenix running with mix phx.server
    2. Test WebSocket with wscat -c ws://localhost:4000/socket/agent/websocket
    3. Create valid agent token in UI at /agents
    4. Run agent with debug: RUST_LOG=debug cargo run -- --api-url http://localhost:4000 --token <token>
  • Common issues: expired token, Phoenix not running, wrong port

Design Document Location

docs/plans/2026-02-02-gettext-internationalization-design.md