I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...
我们如何为 macOS 应用添加国际化和多语言支持
- Get link
- X
- Other Apps
By
Errong Leng
-
我们如何为 macOS 应用添加国际化和多语言支持
支持多语言对于拓展全球用户至关重要。本文将以我们的 macOS 应用 iTrans 为例,介绍我们如何通过 Swift 和 Xcode 实现国际化(i18n)和中文本地化。
1. 审查所有用户可见文本
第一步是查找代码中所有用户可见的字符串。我们在 SwiftUI 视图、模型和操作符中搜索所有硬编码文本。
2. 提取待本地化字符串
我们将所有硬编码字符串替换为支持本地化的 API:
- 在 SwiftUI 中,
Text视图使用LocalizedStringKey。 - 其他字符串使用
NSLocalizedString。
Text(LocalizedStringKey("Unlock your iPhone"))
// 或
NSLocalizedString("Untitled", comment: "File with no name")
3. 创建本地化文件
我们为每种支持的语言创建了 Localizable.strings 文件:
en.lproj/Localizable.strings—— 英文zh-Hans.lproj/Localizable.strings—— 简体中文
英文示例:
"Unlock your iPhone" = "Unlock your iPhone";
中文示例:
"Unlock your iPhone" = "解锁你的 iPhone";
4. 将本地化文件添加到 Xcode 工程
为了让 Xcode 识别本地化文件:
- 我们通过项目导航器将
Localizable.strings文件添加到工程。 - 在文件检查器中,启用本地化并勾选所有支持的语言。
5. 测试本地化效果
Xcode 让我们可以轻松测试不同语言下的应用效果:
- 在 Scheme 编辑器中,将应用语言设置为“简体中文”并运行应用。
- 我们还验证了所有界面文本在英文和中文下都能正确显示。
6. 效果展示
通过以上步骤,我们的应用现已完整支持英文和中文。所有用户可见文本都已本地化,用户切换语言体验流畅。
结论:
在 Swift 和 Xcode 中实现国际化非常直接。只需遵循最佳实践:提取所有用户可见文本、使用本地化 API、为每种语言维护 .strings 文件并充分测试。这样你的应用就能面向全球用户。
❤️ Support This Blog
If this post helped you, you can support my writing with a small donation. Thank you for reading.
Popular Posts
Cross compile tensorflow for armv7l targets via bazel
By
三好Daddy
-
react-native : communicate between react-native JS and WebView component
By
三好Daddy
-
APIs: window.postMessage in WebView , post a message to react-native JS . onMessage callback in react-native JS , receive a message from WebView . injectjavascript , Function that accepts a string that will be passed to the WebView and executed immediately as JavaScript. injectedjavascript , Set this to provide JavaScript that will be injected into the web page when the view loads. onMessage A function that is invoked when the webview calls window.postMessage. Setting this property will inject a postMessage global into your webview, but will still call pre-existing values of postMessage. window.postMessage accepts one argument, data, which will be available on the event object, event.nativeEvent.data. data must be a string. Sample code import React, { Component } from 'react'; import { Button, Platform, StyleSheet, Text, View, WebView, } from 'react-native'; var WEBVIEW_REF = 'webview'; export default class App extends Component<...
A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android
By
Errong Leng
-
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...
Comments
Post a Comment