Custom App Localization Architecture with AI Integration

Description

App Localization Architecture with AI Integration

This prompt helps you build a robust localization system for your SwiftUI application that operates independently of the operating system settings. You will get a complete structure for language management and seamless integration with LLMs.

Who is this prompt for?

  • SwiftUI Developers: looking to provide in-app language switching options.
  • AI Enthusiasts: integrating AI assistants that need to respond in the user's preferred language.
  • Project Managers: for rapid deployment of multilingual solutions in new markets.

Key Benefits

  • Full Autonomy: UI localization doesn't rely on global iPhone settings.
  • Dynamic Updates: The interface updates instantly upon selection without app restarts.
  • AI Context: Automatically passes language preferences into API system prompts.
  • Clean Code: Utilizes modern ObservableObject and String Catalogs for scalability.
>_ Prompt
Act as an App Localization Expert. You are tasked with setting up a user-preference-based localization architecture in an application independent of the phone's system language.

Your task includes:
1. **LanguageManager Class**: Create a `LanguageManager` class using the `ObservableObject` protocol. Store the user's selected language in `UserDefaults`, with the default language set to 'en' (English). Display a selection screen on the first launch.
2. **Global Locale Override**: Wrap the entire `ContentView` structure in your SwiftUI app with `.environment(\ .locale, .init(identifier: languageManager.selectedLanguage))` to trigger translations based on the selected language in `LanguageManager`.
3. **Onboarding Language Selection**: If no language has been selected previously, show a stylish 'Language Selection' screen with English and Turkish options on app launch. Save the selection immediately and transition to the main screen.
4. **AI (LLM) Integration**: Add the user's selected language as a parameter in AI requests (API calls). Update the system prompt to: 'User's preferred language: ${selected_language}. Respond in this language.'
5. **String Catalogs**: Integrate `.stringxcatalog` into your project and add all existing hardcoded strings in English (base) and Turkish.
6. **Dynamic Update**: Ensure that changing the language in settings updates the UI without restarting the app.
7. **User Language Change**: Allow users to change the app's language dynamically at any time.
Categories:
Models:
Output format: