Localization Support
Preparation
- In the Project Navigator, select your project.
- Select your target.
- Go to the Build Phases tag.
- Under “Copy Bundle Resources”, add
UsherAutoSDKLocalizedStrings.bundle
. - You can put the bundle file anywhere in your file structure.
- Every error.localizedDescription is localized by the locale you set.
Add New Languages
- In
UsherAutoSDKLocalizedStrings.bundle
, create a strings file named in one of the following ways: * [language designator]-[region designator], e.g. en-AU.strings, en-GB.strings, etc. * [language designator]-[script designator], e.g. zh-Hans.strings, zh-Hant.strings, etc. * [language designator].strings, e.g. zh.strings, en.strings, ja.strings, etc. - Make sure
UsherAutoSDKLocalizedStrings.bundle
is already imported in your target. - Everything should work properly now.
Note: If no specific script or region designator is found, the SDK falls back to [language designator].strings. For example, if en-GB.strings is not found, the SDK uses en.strings. If en.strings is not found, the default English strings are used. You can reference the following links for language, region, and script designators:
You can reference the following links for language, region and script designators:
- Apple’s Internationalization and Localization Guide - Language and Locale IDs
- iOS Supported Language Codes (ISO-639)
Set Locale
let locale = Locale(identifier: "en-US")
UsherSDK.setLocale(locale)
Get Locale
let currentLocale = UsherSDK.getLocale()
The default locale is “en-US” if no locale is set.
Get Localized Error Strings
AccountManager.signOut() { error in
guard error == nil else {
print("Error: \(error.localizedDescription)")
}
}
Use the localizedDescription property to get the localized error message from NSError.
Set Localized Strings for Authentication with Biometrics
Set localized strings for enabling sign in by authenticating with biometrics
- Set the localized string key on the configuration before the initialization of UsherSDK.
let config = UsherSDKConfiguration(serverUrl: serverURL,
applicationId: "MyApp")
// other configurations...
// The prompt message is configurable. It describes the attempt to enable sign in with biometrics.
// Default is "Authenticate with Biometrics"
config.enableBiometricSignInMessage = "Authenticate with Biometrics"
UsherSDK.initializeWith(configuration: config, completion: completion)
Modify the key-value pairs for all strings files in UsherAutoSDKLocalizedStrings.bundle
.
For example, make sure you have the key-value pair (“Authenticate with Biometrics” = “生体認証”;) in the ja.strings file. The key should match the value you set on the enableBiometricSignInMessage
of the config object.