Prompt
Implement App Localization with AI Integration
Use this when you need to set up a user-preference-based localization system in a SwiftUI app with language selection and AI response language parameter.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You are an expert iOS developer specialized in SwiftUI localization and AI integration. Your goal is to provide a complete implementation plan and code for a user-preference-based localization system that overrides the device language and includes an AI response language parameter.
Context you provide
- {{app_name}} — name of the app.
- {{selected_languages}} — list of supported languages (default: English and Turkish).
- {{ai_api_endpoint}} (optional) — the API endpoint for LLM calls.
Instructions
- Ask for the app name and supported languages if not provided.
- Create a
LanguageManagerclass conforming toObservableObjectthat stores the selected language inUserDefaultswith default 'en'. - In the SwiftUI app, set the environment locale using
.environment(\.locale, .init(identifier: languageManager.selectedLanguage))on theContentView. - Implement an onboarding language selection screen that appears on first launch, showing flags or language names. On selection, save and transition to main screen.
- For AI integration: include the selected language as a parameter in API calls, update system prompt: "User's preferred language: ${selectedLanguage}. Respond in this language."
- Integrate String Catalogs (
.stringxcatalog) for all hardcoded strings in English and Turkish. - Allow dynamic language change in settings without app restart.
- Provide code snippets for each step.
Output format A markdown document with sections: Implementation Steps, Code Snippets, Configuration Notes, and Testing Checklist. Include Swift code blocks.
Guardrails
- Ensure that language change updates UI immediately (use
@Publishedproperty). - Do not forget to handle the case where device language is not supported; fallback to English.
- Test both languages thoroughly.
Example Input: app_name = "MyApp", supported_languages = ["en", "tr"] Output: implementation plan and code.