Crowdin Android SDK delivers all new translations from Crowdin project to the application immediately. So there is no need to update this application via Google Play Store to get the new version with the localization.
The SDK provides:
- Over-The-Air Content Delivery – the localized content can be sent to the application from the project whenever needed.
- Real-Time Preview – all the translations that are done in the Editor can be shown in your version of the application in real-time. View the translations already made and the ones you're currently typing in.
- Screenshots – all the screenshots made in the application may be automatically sent to your Crowdin project with tagged source strings.
- Requirements
- Installation
- Example Project
- Setup
- Advanced Features
- File Export Patterns
- Notes
- Limitations
- Contributing
- Seeking Assistance
- Security
- License
- Android SDK version 16+
-
JCenter
implementation 'com.crowdin.platform:mobile-sdk:1.1.4'
-
Download or clone this module.
To discover how Android SDK is integrated into a real project see the Example project. You can set up this project for yourself, run, and test.
To run the example project, first clone the repo and run project in the Example directory.
To configure Android SDK integration you need to:
- Upload your xml localization files to Crowdin. If you have ready translations, you can also upload them.
- Set up Distribution in Crowdin.
- Set up SDK and enable Over-The-Air Content Delivery feature in your project.
Distribution is a CDN vault that mirrors the translated content of your project and is required for integration with Android app.
To manage distributions open the needed project and go to Over-The-Air Content Delivery. You can create as many distributions as you need and choose different files for each. You’ll need to click the Release button next to the necessary distribution every time you want to send new translations to the app.
To integrate SDK with your application you need to follow step by step instructions:
-
Inject Crowdin translations by adding override method in BaseActivity class to inject Crowdin translations into the Context.
Note! If you don’t have BaseActivity class add the following code to all of your activities.
Kotlin
override fun attachBaseContext(newBase: Context) { super.attachBaseContext(Crowdin.wrapContext(newBase)) }
Java
@Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(Crowdin.wrapContext(newBase)); }
In case your project already overrides attachBaseContext use the following code:
@Override super.attachBaseContext(Crowdin.wrapContext(SomeLib.wrap(newBase)));
SKD uses
androidx
version of libraries. In case your project still not migrated toandroidx
you can add this lines in thegradle.properties
file:android.enableJetifier=true android.useAndroidX=true
It might require additional changes in your code.
-
Enable Over-The-Air Content Delivery in your project so that application can pull translations from CDN vault. Add the following code to App/Application class:
Kotlin
override fun onCreate() { super.onCreate() Crowdin.init(applicationContext, CrowdinConfig.Builder() .withDistributionHash(your_distribution_hash) .withNetworkType(network_type) // optional .withUpdateInterval(interval_in_seconds) // optional .build()) }
Java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crowdin.init(this, new CrowdinConfig.Builder() .withDistributionHash(your_distribution_hash) .withNetworkType(network_type) // optional .withUpdateInterval(interval_in_seconds) // optional .build()); }
Config option Description Example withDistributionHash
Distribution Hash withDistributionHash("7a0c1...7uo3b")
withNetworkType
Network type to be used for translations download Acceptable values are NetworkType.ALL
,NetworkType.CELLULAR
,NetworkType.WIFI
withUpdateInterval
Translations update interval in seconds. The minimum and the default value is 15 minutes. Translations will be updated every defined time interval once per application load withUpdateInterval(900)
Note! The CDN feature does not update the localization files. if you want to add new translations to the localization files you need to do it yourself.
All the translations that are done in the Editor can be shown in your version of the application in real-time. View the translations already made and the ones you're currently typing in.
-
Add the following code to the Application class:
Kotlin
override fun onCreate() { super.onCreate() Crowdin.init(applicationContext, CrowdinConfig.Builder() .withDistributionHash(your_distribution_hash) .withRealTimeUpdates() .withSourceLanguage(source_language) .withAuthConfig(AuthConfig(client_id, client_secret, organization_name)) .withNetworkType(network_type) // optional .withUpdateInterval(interval_in_seconds) // optional .build()) }
Java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crowdin.init(this, new CrowdinConfig.Builder() .withDistributionHash(your_distribution_hash) .withRealTimeUpdates() .withSourceLanguage(source_language) .withAuthConfig(AuthConfig(client_id, client_secret, organization_name)) .withNetworkType(network_type) // optional .withUpdateInterval(interval_in_seconds) // optional .build()); }
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", "organization_name"))
client_id
,client_secret
Crowdin OAuth Client ID and Client Secret "gpY2yC...cx3TYB"
,"Xz95tfedd0A...TabEDx9T"
organization_name
An Organization domain name (for Crowdin Enterprise users only) "mycompany"
withNetworkType
Network type to be used for translations download Acceptable values are NetworkType.ALL
,NetworkType.CELLULAR
,NetworkType.WIFI
withUpdateInterval
Translations update interval in seconds. The minimum and the default value is 15 minutes. Translations will be updated every defined time interval once per application load withUpdateInterval(900)
-
Crowdin Authorization is required for Real-Time Preview feature. Create connection using Activity/Fragment method inMainActivity class:
Kotlin
override fun onCreate(savedInstanceState: Bundle?) { Crowdin.authorize(this) }
Java
@Override public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); Crowdin.authorize(this); }
You can disconnect via:
override fun onDestroy() { super.onDestroy() // Close connection with Crowdin. Crowdin.disconnectRealTimeUpdates() }
Enable if you want all the screenshots made in the application to be automatically sent to your Crowdin project with tagged strings. This will provide additional context for translators.
You can take a screenshots and automatically upload them tagged to Crowdin in two ways: using system buttons or create own handler (for example, clicking on some button in your application).
-
Add the following code to the Application class:
Kotlin
override fun onCreate() { super.onCreate() Crowdin.init(applicationContext, CrowdinConfig.Builder() .withDistributionHash(your_distribution_hash) .withScreenshotEnabled() .withSourceLanguage(source_language) .withAuthConfig(AuthConfig(client_id, client_secret, organization_name)) .withNetworkType(network_type) // optional .withUpdateInterval(interval_in_millisec) // optional .build()) } // Using system buttons to take screenshots and automatically upload them to Crowdin. Crowdin.registerScreenShotContentObserver(this)
Java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crowdin.init(this, new CrowdinConfig.Builder() .withDistributionHash(your_distribution_hash) .withScreenshotEnabled() .withSourceLanguage(source_language) .withAuthConfig(AuthConfig(client_id, client_secret, organization_name)) .withNetworkType(network_type) // optional .withUpdateInterval(interval_in_seconds) // optional .build()); }
Config option Description Example withDistributionHash
Distribution Hash withDistributionHash("7a0c1...7uo3b")
withScreenshotEnabled
Enable Screenshots feature withScreenshotEnabled()
withSourceLanguage
Source language code in your Crowdin project withSourceLanguage("en")
withAuthConfig
Crowdin authorization config withAuthConfig(AuthConfig("client_id", "client_secret", "organization_name"))
client_id
,client_secret
Crowdin OAuth Client ID and Client Secret "gpY2yC...cx3TYB"
,"Xz95tfedd0A...TabEDx9T"
organization_name
An Organization domain name (for Crowdin Enterprise users only) "mycompany"
withNetworkType
Network type to be used for translations download Acceptable values are NetworkType.ALL
,NetworkType.CELLULAR
,NetworkType.WIFI
withUpdateInterval
Translations update interval in seconds. The minimum and the default value is 15 minutes. Translations will be updated every defined time interval once per application load withUpdateInterval(900)
Note! Using
Crowdin.registerScreenShotContentObserver(this)
(system buttons handler) for sending screenshots to Crowdin requires Storage permission for your app. -
Crowdin Authorization is required for Screenshots feature. Create connection using Activity/Fragment method in MainActivity class:
Kotlin
override fun onCreate(savedInstanceState: Bundle?) { Crowdin.authorize(activity) }
Java
@Override public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); Crowdin.authorize(this); }
-
If you want to setup own handler for capturing screenshots you can do it programmatically with callback:
Kotlin
Crowdin.sendScreenshot(activity!!, object : ScreenshotCallback { override fun onSuccess() { Log.d(TAG, "Screenshot uploaded") } override fun onFailure(throwable: Throwable) { Log.d(TAG, throwable.localizedMessage) } })
Java
View.OnClickListener oclBtnOk = new View.OnClickListener() { @Override public void onClick(View v) { Crowdin.sendScreenshot(YourActivity.this, new ScreenshotCallback() { @Override public void onSuccess() { Log.d("", "Screenshot uploaded"); } @Override public void onFailure(Throwable throwable) { Log.d("", String.valueOf(throwable)); } }); } };
You can set file export patterns and check existing ones using File Settings. The following placeholders are supported:
Name | Description |
---|---|
%language% | Language name (e.g. Ukrainian) |
%two_letters_code% | Language code ISO 639-1 (e.g. uk) |
%three_letters_code% | Language code ISO 639-2/T (e.g. ukr) |
%locale% | Locale (e.g. uk-UA) |
%locale_with_underscore% | Locale (e.g. uk_UA) |
%android_code% | Android Locale identifier used to name "values-" directories |
-
Crowdin works with current locale, so if you change locale with
Locale.setDefault(newLocale);
Crowdin will start using strings of the new locale.
-
For displaying a string, Crowdin tries to find that in dynamic strings, and will use bundled version as fallback. In the other words, Only the new provided strings will be overridden and for the rest the bundled version will be used.
-
To translate menu items you need to update your
onCreateOptionsMenu
method:override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflateWithCrowdin(R.menu.activity_menu, menu, resources) return true }
@Override public boolean onCreateOptionsMenu(Menu menu) { ExtentionsKt.inflateWithCrowdin(getMenuInflater(), R.menu.your_menu, menu, getResources()); return true; }
-
In case you have custom views that uses
TypedArray
andstylable
attributes, you will need to use such approach:val textId = typedArray.getResourceId(R.styleable.sample_item, 0) textView.setText(textId)
instead of
typedArray.getString(R.styleable.sample_item)
-
Activity title defined via AndroidManifest won't be translated.
<activity android:name=".activities.SampleActivity" android:label="@string/title"/>
You can simply update your
toolbar
inside of activity or fragment:toolbar.setTitle(R.string.title);
-
In case your project already overrides
attachBaseContext
:super.attachBaseContext(Crowdin.wrapContext(SomeLib.wrap(newBase)));
-
You can register/unregister observer for data changes by adding this lines:
override fun onCreate(savedInstanceState: Bundle?) { Crowdin.registerDataLoadingObserver(this) }
-
ShakeDetector for triggering force upload from Crowdin. It will try to download latest updates from release.
override fun onCreate(savedInstanceState: Bundle?) { Crowdin.registerShakeDetector(this) }
On each shake event it will trigger
Crowdin.forceUpdate(this)
method. You can call this method from your app. Also there are other public methods inCrowdin
class. You can find details inkotlin doc
files. -
Currently, Custom Languages, Dialects, and Language Mapping are not supported for Android SDK.
- Plurals are supported from Android SDK version 24.
- TabItem text added via xml won't be updated. There is workaround: you can store tabItem titles in your string-array and add tabs dynamically.
PreferenceScreen
defined via XML not supported.
If you want to contribute please read the Contributing guidelines.
If you find any problems or would like to suggest a feature, please feel free to file an issue on Github at Issues Page.
Need help working with Crowdin Android SDK or have any questions? Contact Customer Success Service.
Crowdin Android SDK CDN feature is built with security in mind, which means minimal access possible from the end-user is required. When you decide to use Crowdin Android SDK, please make sure you’ve made the following information accessible to your end-users.
- We use the advantages of Amazon Web Services (AWS) for our computing infrastructure. AWS has ISO 27001 certification and has completed multiple SSAE 16 audits. All the translations are stored at AWS servers.
- When you use Crowdin Android SDK CDN – translations are uploaded to Amazon CloudFront to be delivered to the app and speed up the download. Keep in mind that your users download translations without any additional authentication.
- We use encryption to keep your data private while in transit.
- We do not store any Personally Identifiable Information (PII) about the end-user, but you can decide to develop the opt-out option inside your application to make sure your users have full control.
- The Automatic Screenshots and Real-Time Preview features are supposed to be used by the development team and translators team. Those features should not be compiled to the production version of your app. Therefore, should not affect end-users privacy in any way.
The Crowdin Android SDK is licensed under the MIT License. See the LICENSE file distributed with this work for additional information regarding copyright ownership. Except as contained in the LICENSE file, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.