프롬프트 도감 › No.1812
앱 언어 선택 기능 만들기
App Localization Setup
iOS 앱에서 폰 설정과 상관없이 사용자가 고른 언어로 화면을 바꾸는 기능을 만들어 줘요. 처음 실행할 때 언어 선택 화면과 AI 답변 언어 전달까지 포함해요.
이럴 때 iOS 앱 다국어 지원, SwiftUI 연습, 앱 설정 화면 만들기
도구 ChatGPT · Claude · Gemini
프롬프트
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.
Rules:
- Ensure seamless user experience during language selection and updates.
- Test functionality for both English and Turkish languages.팁
- 영어·터키어 자리에 쓸 언어로 바꿔요
- ${selected_language} 는 앱 변수 이름으로 맞춰요
출처
권리: CC0 (f/prompts.chat). 자유 사용. 기여자: ahmettzorlutuna.