Skip to content

Commit 2f40f70

Browse files
updated localization docs and handling
1 parent 860eb73 commit 2f40f70

File tree

7 files changed

+92
-8
lines changed

7 files changed

+92
-8
lines changed

DemoAppSwiftUI/Localizable.strings

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// Copyright © 2020 Stream.io Inc. All rights reserved.
3+
//
4+
5+
"channel.name.and" = "and";
6+
"channel.name.andXMore" = "and %@ more";
7+
"channel.name.missing" = "NoChannel";
8+
"channel.item.empty-messages" = "No messages";
9+
"channel.item.typing-singular" = "is typing ...";
10+
"channel.item.typing-plural" = "are typing ...";
11+
12+
"channel.no-content.title" = "Let's start chatting";
13+
"channel.no-content.message" = "How about sending your first message to a friend?";
14+
"channel.no-content.start" = "Start a chat";
15+
16+
"message.actions.inline-reply" = "Reply";
17+
"message.actions.thread-reply" = "Thread Reply";
18+
"message.actions.edit" = "Edit Message";
19+
"message.actions.copy" = "Copy Message";
20+
"message.actions.delete" = "Delete Message";
21+
"message.actions.delete.confirmation-title" = "Delete Message";
22+
"message.actions.delete.confirmation-message" = "Are you sure you want to permanently delete this message?";
23+
"message.actions.user-unblock" = "Unblock User";
24+
"message.actions.user-block" = "Block User";
25+
"message.actions.user-unmute" = "Unmute User";
26+
"message.actions.user-mute" = "Mute User";
27+
"message.actions.resend" = "Resend";
28+
"message.actions.flag" = "Flag Message";
29+
"message.actions.flag.confirmation-title" = "Flag Message";
30+
"message.actions.flag.confirmation-message" = "Do you want to send a copy of this message to a moderator for further investigation?";
31+
32+
"messageList.typingIndicator.typing-unknown" = "Someone is typing";
33+
34+
"message.threads.reply" = "Thread Reply";
35+
"message.threads.replyWith" = "with %@";
36+
37+
"alert.actions.cancel" = "Cancel";
38+
"alert.actions.delete" = "Delete";
39+
"alert.actions.ok" = "Ok";
40+
"alert.actions.delete-channel-title" = "Delete conversation";
41+
"alert.actions.delete-channel-message" = "Are you sure you want to delete this conversation?";
42+
"alert.error.title" = "Something went wrong.";
43+
"alert.error.message" = "The operation couldn't be completed.";
44+
45+
"message.only-visible-to-you" = "Only visible to you";
46+
"message.deleted-message-placeholder" = "Message deleted";
47+
48+
"composer.title.edit" = "Edit Message";
49+
"composer.title.reply" = "Reply to Message";
50+
"composer.placeholder.message" = "Send a message";
51+
"composer.placeholder.giphy" = "Search GIFs";
52+
"composer.checkmark.direct-message-reply" = "Also send as direct message";
53+
"composer.checkmark.channel-reply" = "Also send in channel";
54+
"composer.picker.title" = "Choose attachment type: ";
55+
"composer.picker.file" = "File";
56+
"composer.picker.media" = "Photo or Video";
57+
"composer.picker.cancel" = "Cancel";
58+
59+
"composer.suggestions.commands.header" = "Instant Commands";
60+
"message.sending.attachment-uploading-failed" = "UPLOADING FAILED";
61+
62+
"message.title.online" = "Available";
63+
"message.title.offline" = "Offline";
64+
"message.title.group" = "%d members, %d online";
65+
66+
"current-selection" = "%d of %d";
67+
68+
"attachment.max-size-exceeded" = "Attachment size exceed the limit.";
69+
"dates.time-ago-seconds-plural" = "last seen %d seconds ago";
70+
"dates.time-ago-seconds-singular" = "last seen just one second ago";
71+
"dates.time-ago-minutes-singular" = "last seen one minute ago";
72+
"dates.time-ago-minutes-plural" = "last seen %d minutes ago";
73+
"dates.time-ago-hours-singular" = "last seen one hour ago";
74+
"dates.time-ago-hours-plural" = "last seen %d hours ago";
75+
"dates.time-ago-days-singular" = "last seen one day ago";
76+
"dates.time-ago-days-plural" = "last seen %d days ago";
77+
"dates.time-ago-weeks-singular" = "last seen one week ago";
78+
"dates.time-ago-weeks-plural" = "last seen %d weeks ago";
79+
"dates.time-ago-months-singular" = "last seen one month ago";
80+
"dates.time-ago-months-plural" = "last seen %d months ago";

Sources/StreamChatSwiftUI/Appearance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Appearance {
2121
}
2222

2323
/// Provider for custom localization which is dependent on App Bundle.
24-
public var localizationProvider: (_ key: String, _ table: String) -> String = { key, table in
24+
public static var localizationProvider: (_ key: String, _ table: String) -> String = { key, table in
2525
Bundle.streamChatUI.localizedString(forKey: key, value: nil, table: table)
2626
}
2727
}

Sources/StreamChatSwiftUI/Generated/L10n.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ internal enum L10n {
226226
// MARK: - Implementation Details
227227

228228
extension L10n {
229+
229230
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
230-
// TODO: Using using Appearance.default prohibits using Appearance injection
231-
let format = Appearance.default.localizationProvider(key, table)
231+
let format = Appearance.localizationProvider(key, table)
232232
return String(format: format, locale: Locale.current, arguments: args)
233233
}
234234
}

Sources/StreamChatSwiftUI/Generated/L10n_template.stencil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ import Foundation
6868
// MARK: - Implementation Details
6969

7070
extension {{enumName}} {
71+
7172
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
72-
// TODO: Using using Appearance.default prohibits using Appearance injection
73-
let format = Appearance.default.localizationProvider(key, table)
73+
let format = Appearance.localizationProvider(key, table)
7474
return String(format: format, locale: Locale.current, arguments: args)
7575
}
7676
}

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
84B288D1274CEDD000DD090B /* GroupNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288D0274CEDD000DD090B /* GroupNameView.swift */; };
141141
84B288D3274D23AF00DD090B /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288D2274D23AF00DD090B /* LoginView.swift */; };
142142
84B288D5274D286500DD090B /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B288D4274D286500DD090B /* LoginViewModel.swift */; };
143+
84EDBC37274FE5CD0057218D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84EDBC36274FE5CD0057218D /* Localizable.strings */; };
143144
/* End PBXBuildFile section */
144145

145146
/* Begin PBXContainerItemProxy section */
@@ -308,6 +309,7 @@
308309
84B288D0274CEDD000DD090B /* GroupNameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupNameView.swift; sourceTree = "<group>"; };
309310
84B288D2274D23AF00DD090B /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
310311
84B288D4274D286500DD090B /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
312+
84EDBC36274FE5CD0057218D /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
311313
/* End PBXFileReference section */
312314

313315
/* Begin PBXFrameworksBuildPhase section */
@@ -397,6 +399,7 @@
397399
84B288CE274C545900DD090B /* CreateGroupViewModel.swift */,
398400
8465FDDC2747A14700AF091E /* CustomComposerAttachmentView.swift */,
399401
84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */,
402+
84EDBC36274FE5CD0057218D /* Localizable.strings */,
400403
8465FCCA27468B7500AF091E /* Info.plist */,
401404
8465FCC227468B6A00AF091E /* Assets.xcassets */,
402405
8465FBB62746873A00AF091E /* Products */,
@@ -786,6 +789,7 @@
786789
buildActionMask = 2147483647;
787790
files = (
788791
8465FCC627468B6A00AF091E /* Preview Assets.xcassets in Resources */,
792+
84EDBC37274FE5CD0057218D /* Localizable.strings in Resources */,
789793
8465FCC327468B6A00AF091E /* Assets.xcassets in Resources */,
790794
);
791795
runOnlyForDeploymentPostprocessing = 0;

docusaurus/docs/iOS/swiftui/localization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ title: Localization
44

55
## Introduction
66

7-
If you deploy your app to users who speak another language, you'll need to internationalize (localize) it. That means you need to write the app in a way that makes it possible to localize values like text and layouts for each language or locale that the app supports.
7+
If your app supports multiple languages, the chat SDK has support for localizations. For example, you can add more languages, or you can change translations for the existing texts used throughout the SDK.
88

99
## Adding a new language
1010

1111
1. If you don't have `strings` or `stringsdict` files in your project, add those new files to `Localizable.strings` and `Localizable.stringsdict`.
1212
2. Next [add new language to the project](https://developer.apple.com/documentation/xcode/adding-support-for-languages-and-regions).
1313
3. Copy the StreamChatUI localization keys into your `strings` and `stringsdict` files. You can find the latest version [here](https://github.com/GetStream/stream-chat-swift/blob/main/Sources/StreamChatSwiftUI/Resources/en.lproj/).
14-
4. Set the `localizationProvider` to provide your `AppBundle` instead of `StreamChatSwiftUI` frameworks:
14+
4. Set the `localizationProvider` to provide your `Bundle` instead of the one provided by `StreamChatSwiftUI` SDK (as early as possible in the App lifecylce, e.g. in the `AppDelegate`):
1515
```swift
16-
Appearance.default.localizationProvider = { key, table in
16+
Appearance.localizationProvider = { key, table in
1717
Bundle.main.localizedString(forKey: key, value: nil, table: table)
1818
}
1919
```

0 commit comments

Comments
 (0)