@@ -97,8 +97,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
97
97
For Swift projects, you will also need to copy the ` TXNativeExtensions.swift ` file in
98
98
your project and include it in all of the targets that call any of the following Swift methods:
99
99
100
- * ` String.localizedStringWithFormat(format:...) `
101
- * ` NSString.localizedStringWithFormat(format:...) `
100
+ * ` NSString.localizedStringWithFormat(_ format:, _ args:) `
101
+ * ` String.localizedStringWithFormat(_ format:, _ arguments:) `
102
+ * [ ⚠️] ( #stringlocalized-initializers ) ` String.init(localized:) `
103
+ * [ ⚠️] ( #stringlocalized-initializers ) ` String.init(localized:options:) `
104
+ * [ ⚠️] ( #stringlocalized-initializers ) ` String.init(localized:defaultValue:table:bundle:locale:comment:) `
105
+ * [ ⚠️] ( #stringlocalized-initializers ) ` String.init(localized:defaultValue:options:table:bundle:locale:comment:) `
106
+ * [ ⚠️] ( #stringlocalized-initializers ) ` String.init(localized:table:bundle:locale:comment:) `
107
+ * [ ⚠️] ( #stringlocalized-initializers ) ` String.init(localized:options:table:bundle:locale:comment:) `
102
108
103
109
If none of your application targets call any of the above methods, then you don't need to
104
110
add this file to your project.
@@ -171,6 +177,36 @@ TXNative.initialize(
171
177
token:@"<transifex_token>"] ;
172
178
```
173
179
180
+ ### Supported localization methods
181
+
182
+ On runtime, Transifex SDK overrides / swizzles the following localization
183
+ methods and structures in order to ensure that the application source code does
184
+ not require any changes:
185
+
186
+ * `NSLocalizedString(_ key:tableName:bundle:value:comment:)`
187
+ * `NSString.localizedStringWithFormat(_ format:, _ args:)`
188
+ * `String.localizedStringWithFormat(_ format:, _ arguments:)`
189
+ * `-[NSString localizedStringWithFormat:]`
190
+ * `NSBundle.localizedString(forKey:value:table:)`
191
+ * `-[NSBundle localizedAttributedStringForKey:value:table:]`
192
+ * Any SwiftUI view initializer that accepts a `LocalizedStringKey` struct.
193
+ * [⚠️](#stringlocalized-initializers) `String.init(localized:)`
194
+ * [⚠️](#stringlocalized-initializers) `String.init(localized:options:)`
195
+ * [⚠️](#stringlocalized-initializers) `String.init(localized:defaultValue:table:bundle:locale:comment:)`
196
+ * [⚠️](#stringlocalized-initializers) `String.init(localized:defaultValue:options:table:bundle:locale:comment:)`
197
+ * [⚠️](#stringlocalized-initializers) `String.init(localized:table:bundle:locale:comment:)`
198
+ * [⚠️](#stringlocalized-initializers) `String.init(localized:options:table:bundle:locale:comment:)`
199
+
200
+ Developers are also able to use the public methods of `TXNative` class if they
201
+ want to (`t(_:)`, `localizedString(format:arguments:)`, `translate(...)`.
202
+
203
+ > [!WARNING]
204
+ >
205
+ > Please note that if the 'Use Compiler to Extract Swift Strings' build settting
206
+ > is enabled (`SWIFT_EMIT_LOC_STRINGS`) and you use any of the `TXNative` publicly
207
+ > provided methods, the strings will not be automatically collected when building
208
+ > the application.
209
+
174
210
### Fetching translations
175
211
176
212
As soon as `fetchTranslations` is called, the SDK will attempt to download the
@@ -367,6 +403,47 @@ public `TXStandardLogHandler` class to control the log level printed to the cons
367
403
368
404
## Limitations
369
405
406
+ ### ` String(localized:) ` initializers
407
+
408
+ While the ` String(localized:) ` family of initializers ([ ^ 1 ] [ ^ 2 ] [ ^ 3 ] [ ^ 4 ] [ ^ 5 ] [ ^ 6 ] )
409
+ is supported through the ` TXNativeExtensions.swift ` file, we do not recommend using
410
+ them due to their reliance on reflection and regular expressions to extract the
411
+ ` LocalizationValue ` properties.
412
+
413
+ Developers can choose to switch between the Reflection and the Regular Expression
414
+ extraction logic via the ` extractionType ` argument of the ` TXNative.translate(...) `
415
+ methods used in the ` TXNativeExtensions.swift ` file.
416
+
417
+ > [ !WARNING]
418
+ >
419
+ > ** Risk of Breaking Changes**
420
+ >
421
+ > Apple may change the internal representation of the ` LocalizationValue `
422
+ > struct at any time, which would break the implemented logic.
423
+
424
+ We strongly recommend using any of the following supported methods instead of
425
+ the ` String(localized:) ` initializers:
426
+
427
+ * ` NSLocalizedString(_ key:tableName:bundle:value:comment:) `
428
+ * ` NSString.localizedStringWithFormat(_ format:, _ args:) `
429
+ * ` String.localizedStringWithFormat(_ format:, _ arguments:) `
430
+ * ` -[NSString localizedStringWithFormat:] `
431
+ * ` NSBundle.localizedString(forKey:value:table:) `
432
+ * ` -[NSBundle localizedAttributedStringForKey:value:table:] `
433
+ * Any SwiftUI view initializer that accepts a ` LocalizedStringKey ` struct.
434
+
435
+ If you understand the risks, you may uncomment the relevant section in
436
+ ` TXNativeExtensions.swift ` after adding the file to your application’s
437
+ target(s). However, we strongly advise using the recommended
438
+ alternatives whenever possible.
439
+
440
+ [ ^ 1 ] : https://developer.apple.com/documentation/swift/string/init (localized:)
441
+ [ ^ 2 ] : https://developer.apple.com/documentation/swift/string/init (localized:options:)
442
+ [ ^ 3 ] : https://developer.apple.com/documentation/swift/string/init (localized:defaultvalue:table:bundle:locale:comment:)
443
+ [ ^ 4 ] : https://developer.apple.com/documentation/swift/string/init (localized:defaultvalue:options:table:bundle:locale:comment:)
444
+ [ ^ 5 ] : https://developer.apple.com/documentation/swift/string/init (localized:table:bundle:locale:comment:)
445
+ [ ^ 6 ] : https://developer.apple.com/documentation/swift/string/init (localized:options:table:bundle:locale:comment:)
446
+
370
447
### Special cases
371
448
372
449
Localized strings that are being managed by the OS are not supported by the Transifex
0 commit comments