Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve currentLocalization description #316

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions website/docs/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,15 @@ By default, SDK searches for new translation once per application load, but not

### Change locale programmatically

By default, the SDK relies on the device locale. To change the SDK target language on the fly regardless of the device locale, use the following method:
By default, the SDK relies on the device locale. To change the SDK target language on the fly regardless of the device locale.

```swift
import CrowdinSDK

CrowdinSDK.enableSDKLocalization(true, localization: "<language_code>")
```

Where `<language_code>` is the target language in [ISO 639-1](http://www.loc.gov/standards/iso639-2/php/English_list.php) format.

You can also use the `CrowdinSDK.currentLocalization` property to get or set the current localization language code used by the Crowdin SDK. When you set this property, the SDK triggers a localization download if needed:
You can use the `CrowdinSDK.currentLocalization` property to get or set the current localization language code ([ISO 639-1](http://www.loc.gov/standards/iso639-2/php/English_list.php)) used by the Crowdin SDK. When you set this property, the SDK triggers a localization download if needed:

```swift
import CrowdinSDK

// Set the current localization to German
CrowdinSDK.currentLocalization = "de"
CrowdinSDK.currentLocalization = "<language_code>"

// ...

Expand All @@ -177,6 +169,13 @@ if let currentLocale = CrowdinSDK.currentLocalization {
}
```

This is the recommended way to change the language programmatically. The SDK will download the new localization if it's not already available. If set to `nil` - the localization will be detected automatically based on the languages available in Crowdin and the system's preferred languages.


:::caution
The UI doesn't update automatically. You must manually update the UI after changing the localization.
:::

### `addDownloadHandler` closure

The `addDownloadHandler` method allows you to add a closure that will be called every time new localization is downloaded. This can be useful for performing actions such as updating the user interface or processing the newly downloaded localization data:
Expand Down
Loading