- Introduction
- Features
- Prerequisites
- Project Settings
- Integration Steps
- Usage Examples
- Demo App
- Trobleshooting
The JioLocalizationSDKAndroid offers a robust solution for managing localization in your Android applications. With this SDK, you can effortlessly fetch localization data, retrieve localized strings, and handle dynamic placeholders, ensuring your app can cater to a global audience with ease.
- Fetch localization data.
- Retrieve localized strings with dynamic placeholders.
- Support for nested JSON structures.
- Handle missing localization keys with fallback values.
Before getting started with this example app, please ensure you have the following software installed on your machine:
- Android Studio
- Support for Java 11
i.: Generate a Personal Access Token for GitHub
- Settings -> Developer Settings -> Personal Access Tokens -> Generate new token
- Make sure you select the following scopes (“ read:packages”) and Generate a token
- After Generating make sure to copy your new personal access token. You cannot see it again! The only option is to generate a new key.
ii. Update build.gradle inside the application module
repositories {
maven {
credentials {
<!--github user name-->
username = ""
<!--github user token-->
password = ""
}
url = uri("https://maven.pkg.github.com/JioMeet/JioLocalizationSDK_Android")
}
google()
mavenCentral()
}
iii. In Gradle Scripts/build.gradle (Module: ) add the SDK dependency. The dependencies section should look like the following:
dependencies {
...
implementation " com.jio.localization:jiolocalizationsdk:<version>"
...
}
Find the Latest version of the Core SDK and replace with the one you want to use. For example: 1.0.0-SNAPSHOT.
In /app/Manifests/AndroidManifest.xml, add the following permissions after :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Create and configure the instance of JioLocalization
.
The JioLocalization
instance can be configured with the following options:
context
: The application context.baseURL
: The base URL of the localization service.apiKey
: The API key for the localization service.
The JioLocalization
instance is created using the JioLocalization.Builder
class.
val builder = JioLocalization.Builder()
builder.apply {
init(context, Server.SIT.baseURL)
setApiKey(apiKey)
}
jioLocalization = builder.build()
This method fetches localization data for a specified language code from the remote service. It is designed to be called during the initialization phase of your application to ensure that all user-facing strings are appropriately localized based on the user’s language preference. The method handles both success and error cases, allowing for seamless user experience while providing feedback on the localization loading process
jioLocalization.loadLocalization("en"){ result ->
when (result) {
is Completion.Success -> {
Log.d("TAG", "Localization successfully loaded: ", )
}
is Completion.Error -> {
Log.e("TAG", "Some error while loading localization: ")
}
}
}
This method retrieves localized strings based on a provided key. It supports loading a key with a default value and can also handle dynamic value placeholders within the string.
Basic Retrieval:
The first example retrieves the localized string for the key "callDeclined". If the key does not exist in the localization data, it will return null or the default value if specified.
// Retrieve a localized message without a default value
val message = jioLocalization.getLocalizedString("callDeclined")
With Default Value:
The second example demonstrates how to use a default value. If the key "callDeclined" is not found, the method will return "Default Value" instead.
// Retrieve a localized message without a default value
val messageWithDefault = jioLocalization.getLocalizedString("callDeclined", "Default Value")
Dynamic Values:
The third example shows how to load a key that contains a dynamic value placeholder (%@). In this case, the placeholder will be replaced with the string "English" in the final output.
val dynamicMessage = jioLocalization.getLocalizedString("callDeclined", mapOf("%@" to "English"), "Default Value")
Note:
- Ensure that the localization data is loaded before calling this method to prevent potential null returns.
- Use dynamic value placeholders to create more flexible and context-aware localized messages
The JioLocalizationSDK_Android demonstrates how to integrate the jiolocalizationsdk into your Android project. The app showcases various examples of fetching localized strings, including simple strings, nested strings, and strings with dynamic placeholders
Facing any issues while integrating or installing the JioLocalization Android SDK kit, please connect with us via https://translate.jio/contact-us.html