Skip to content

Commit 7a16088

Browse files
committed
Lower min iOS version of UIKit example to iOS 16 and finish readme
1 parent ffaa8c8 commit 7a16088

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

Examples/TolgeeSwiftUIExample/TolgeeSwiftUIExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
271271
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
272272
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
273+
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
273274
LD_RUNPATH_SEARCH_PATHS = (
274275
"$(inherited)",
275276
"@executable_path/Frameworks",
@@ -297,6 +298,7 @@
297298
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
298299
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
299300
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
301+
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
300302
LD_RUNPATH_SEARCH_PATHS = (
301303
"$(inherited)",
302304
"@executable_path/Frameworks",

Examples/TolgeeSwiftUIExample/TolgeeSwiftUIExample/ContentView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ struct ContentView: View {
2424

2525
// Use the SDK directly
2626
// note: the locale param is only used for SwiftUI preview purposes
27-
Text(Tolgee.shared.translate("My name is %@ and I have %lld apples", "John", 3, locale: locale))
27+
if #available(iOS 18.4, *) {
28+
Text(Tolgee.shared.translate("My name is %@ and I have %lld apples", "John", 3, locale: locale))
29+
} else {
30+
Text(Tolgee.shared.translate("My name is %@ and I have %lld apples", "John", 3))
31+
}
2832
}
2933
.padding()
3034
}

README.md

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,54 @@ let nameAndAge = Tolgee.shared.translate("My name is %@ and I'm %lld years old",
128128
129129
### 🔧 SwiftUI Integration
130130

131-
Tolgee is designed to work great with SwiftUI and SwiftUI previews.
131+
Tolgee works great with SwiftUI, including previewing views in different localizations using SwiftUI previews.
132132

133+
You can use the `TolgeeText` component which will automatically use the injected locale on iOS 18.4+
133134
```swift
134135
import SwiftUI
135136
import Tolgee
136137

137138
struct ContentView: View {
138-
@State private var userName = "Alice"
139-
@State private var itemCount = 5
139+
var body: some View {
140+
TolgeeText("welcome_title")
141+
}
142+
}
143+
144+
#Preview("English") {
145+
ContentView()
146+
.environment(\.locale, Locale(identifier: "en"))
147+
}
148+
149+
#Preview("Czech") {
150+
ContentView()
151+
.environment(\.locale, Locale(identifier: "cs"))
152+
}
153+
```
154+
155+
or use a version of the `translate` method that accepts `locale` param on iOS 18.4 and newer. The older implementation will fall back to the system language.
156+
157+
```swift
158+
struct ContentView: View {
159+
@Environment(\.locale) var locale
140160

141161
var body: some View {
142-
VStack {
143-
// Simple text translation
144-
TolgeeText("welcome_title")
145-
146-
// Text with arguments
147-
TolgeeText("hello_user", userName)
148-
149-
// Text with pluralization
150-
TolgeeText("item_count", itemCount)
162+
if #available(iOS 18.4, *) {
163+
Text(Tolgee.shared.translate("welcome_title", locale: locale))
164+
} else {
165+
Text(Tolgee.shared.translate("welcome_title"))
151166
}
152167
}
153168
}
169+
170+
#Preview("English") {
171+
ContentView()
172+
.environment(\.locale, Locale(identifier: "en"))
173+
}
174+
175+
#Preview("Czech") {
176+
ContentView()
177+
.environment(\.locale, Locale(identifier: "cs"))
178+
}
154179
```
155180

156181
### Reactive Updates
@@ -183,8 +208,16 @@ struct ContentView: View {
183208
```
184209

185210
### Swizzling of Apple's APIs
186-
Tolgee optionally supports swizzling of `Bundle.localizedString`, which is being used by `NSLocalizedString` function. In order to enable swizzling, set enviromental variable `TOLGEE_ENABLE_SWIZZLING=true` in your scheme settings. Refer to our UIKit example.
211+
Tolgee optionally supports swizzling of `Bundle.localizedString`, which is being used by `NSLocalizedString` function. In order to enable swizzling, set enviromental variable `TOLGEE_ENABLE_SWIZZLING=true` in your scheme settings. Refer to our UIKit example to see it in action.
187212

213+
Following calls will then be backed by the Tolgee SDK:
214+
```swift
215+
Bundle.main.localizedString(forKey: "welcome_message")
216+
NSLocalizedString("welcome_message", comment: "")
217+
```
218+
219+
> [!NOTE]
220+
> Plural strings are currently not supported and will fall back to using the string bundled with the app.
188221
189222
## 🌐 Advanced Features
190223

0 commit comments

Comments
 (0)