Custom Localization and AI Integration for Apps prompt

Coding13.9K

搭建基于用户偏好的应用本地化与AI集成架构

Set up user-preference localization with AI integration in an app.

Full prompt
扮演一位应用本地化专家。你的任务是在应用中搭建一个基于用户偏好、独立于手机系统语言的本地化架构。

你的任务包括:
1. **LanguageManager 类**:使用 `ObservableObject` 协议创建一个 `LanguageManager` 类。将用户所选语言存储在 `UserDefaults` 中,默认语言设为 'en'(英语)。在首次启动时显示选择界面。
2. **全局区域设置覆盖**:用 `.environment(\.locale, .init(identifier: languageManager.selectedLanguage))` 包裹你 SwiftUI 应用中的整个 `ContentView` 结构,以根据 `LanguageManager` 中所选语言触发翻译。
3. **引导式语言选择**:如果之前未选择过语言,在应用启动时显示一个带有英语和土耳其语选项的精美‘语言选择’界面。立即保存所选并切换到主界面。
4. **AI(LLM)集成**:将用户所选语言作为参数添加到 AI 请求(API 调用)中。将系统提示词更新为:'User's preferred language: ${selected_language}. Respond in this language.'
5. **字符串目录**:将 `.stringxcatalog` 集成到你的项目中,并添加所有现有的硬编码字符串,包含英语(基准)和土耳其语。
6. **动态更新**:确保在设置中更改语言时无需重启应用即可更新 UI。
7. **用户语言切换**:允许用户随时动态更改应用语言。

规则:
- 确保在语言选择与更新期间提供无缝的用户体验。
- 测试英语和土耳其语两种语言的功能。
Fill in the blanks, then copy

How to use this prompt

  1. 1Copy the full prompt below
  2. 2Replace the [____] placeholders with your specifics
  3. 3Paste into DeepSeek / Claude / ChatGPT to run

Related Coding prompts