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,
redirect_uri,
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,
redirect_uri,
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.
- 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", "redirect_uri")) |
client_id , client_secret | Crowdin OAuth Client ID and Client Secret | "gpY2yC...cx3TYB" , "Xz95tfedd0A...TabEDx9T" |
redirect_uri | OAuth redirect URI (optional, defaults to "crowdintest://" ) | "your-custom://redirect" or "crowdintest://" |
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 |
Redirect URI Configuration
You can configure the OAuth redirect URI for authorization in two ways:
- Via
AuthConfig
(Recommended): Specify the redirect URI directly in yourAuthConfig
. This method provides more flexibility and doesn't require manifest configuration. - Via App Scheme in Manifest: Configure the redirect URI using app scheme in your
AndroidManifest.xml
. When using this method, the redirect URL in your Crowdin OAuth app should becrowdintest://
.
The OAuth App redirect URL should match your configured redirect URI:
- When using AuthConfig method: Set the redirect URL to match the
redirect_uri
parameter value (e.g.,"your-custom://redirect"
) - When using App scheme method: Set the redirect URL to match your app scheme (e.g., for scheme
<data android:scheme="crowdintest" />
usecrowdintest://
)