Real-Time Preview
All translations done in the Crowdin Editor can be displayed in your version of the application in real-time. See the translations that have already been done and the ones you're typing.
Setup
Add the following code to the Application class:
- Kotlin
- Java
override fun onCreate() {
super.onCreate()
Crowdin.init(applicationContext,
CrowdinConfig.Builder()
.withDistributionHash(your_distribution_hash)
.withRealTimeUpdates()
.withSourceLanguage(source_language)
.withAuthConfig(AuthConfig(
client_id,
client_secret,
request_auth_dialog
))
.withOrganizationName(organization_name) // required for Crowdin Enterprise
.withNetworkType(network_type) // optional
.withUpdateInterval(interval_in_seconds) // optional
.build())
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Crowdin.init(this,
new CrowdinConfig.Builder()
.withDistributionHash(your_distribution_hash)
.withRealTimeUpdates()
.withSourceLanguage(source_language)
.withAuthConfig(new AuthConfig(
client_id,
client_secret,
request_auth_dialog
))
.withOrganizationName(organization_name) // required for Crowdin Enterprise
.withNetworkType(network_type) // optional
.withUpdateInterval(interval_in_seconds) // optional
.build());
}
Authorization
Crowdin Authorization is required for Real-Time Preview feature. Create connection using Activity/Fragment method inMainActivity class:
- Kotlin
- Java
override fun onCreate(savedInstanceState: Bundle?) {
Crowdin.authorize(this)
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
Crowdin.authorize(this);
}
You can disconnect via:
- Kotlin
- Java
override fun onDestroy() {
super.onDestroy()
Crowdin.disconnectRealTimeUpdates()
}
@Override
protected void onDestroy() {
super.onDestroy();
Crowdin.disconnectRealTimeUpdates();
}
Tips
- To use the Real-Time Preview feature you still need to wrap context for your activities.
- The OAuth App redirect URL should match your App scheme.
E.g., for scheme<data android:scheme="crowdintest" />
redirect URL in Crowdin should becrowdintest://
. - To easily control the Real-Time Preview feature you could also use the SDK Controls UI widget.
Config options
Config option | Description | Example |
---|---|---|
withDistributionHash | Distribution Hash | withDistributionHash("7a0c1...7uo3b") |
withRealTimeUpdates | Enable Real-Time Preview feature | withRealTimeUpdates() |
withSourceLanguage | Source language code in your Crowdin project | withSourceLanguage("en") |
withAuthConfig | Crowdin authorization config | withAuthConfig(AuthConfig("client_id", "client_secret")) |
client_id , client_secret | Crowdin OAuth Client ID and Client Secret | "gpY2yC...cx3TYB" , "Xz95tfedd0A...TabEDx9T" |
request_auth_dialog | Request authorization dialog | true by default or false |
withOrganizationName | An Organization domain name (for Crowdin Enterprise users only) | "mycompany" for Crowdin Enterprise or null for crowdin.com |