AndroidViews
To read full documentation about Tolgee for Android Views, visit docs.
Load static translations with Tolgee CLI
For managing static translations, we recommend using Tolgee CLI.
To install Tolgee CLI globally run:
npm install --global @tolgee/cli
Create a project-specific configuration file:
// .tolgeerc
{
"$schema": "https://docs.tolgee.io/cli-schema.json",
"apiUrl": "{{{apiUrl}}}",
"projectId": "{{{projectId}}}",
"format": "ANDROID_XML",
"push": {
"filesTemplate": "./src/main/res/values-{languageTag}/strings.xml",
"language": ["en", "cs", "fr", ...]
},
"pull": {
"path": ".",
"fileStructureTemplate": "./src/main/res/values-{languageTag}/strings.{extension}"
}
}
Login with a project API key:
tolgee login "{{{apiKey}}}"
Pull/push translations:
tolgee pull
# or
tolgee push
Add Dependency
# gradle/libs.versions.toml
[libraries]
tolgee = { group = "io.tolgee.mobile-kotlin-sdk", name = "core", version.ref = "tolgee" }
// build.gradle.kts
dependencies {
implementation(libs.tolgee)
}
Add network security config
Create a network security config file network_security.xml in your res/xml folder:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
<domain-config>
<domain includeSubdomains="true">tolgee.io</domain>
<domain includeSubdomains="true">tolg.ee</domain>
</domain-config>
</network-security-config>
Add network security config to your AndroidManifest.xml:
<application
android:networkSecurityConfig="@xml/network_security"> <!-- Add this line to your existing application tag -->
</application>
Setup CDN
In Developer settings create a new CDN deployment for the project with the format set to Android SDK and use the URL in the next step.
Setup Project
Initialize Tolgee in your Application class:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Tolgee.init {
contentDelivery {
url = "https://cdn.tolg.ee/your-cdn-url-prefix"
storage = TolgeeStorageProviderAndroid(this@MyApplication, BuildConfig.VERSION_CODE)
}
}
}
}
Use Tolgee!
// Get a translation with fallback to Android resources
val text = tolgee.t(context, R.string.string_key)
// Get a translation with fallback to Android resources with parameters
val textWithParams = tolgee.t(context, R.string.string_with_params, "param1", "param2")
// Get a translation with fallback to Android resources as a Flow
val textFlow = tolgee.tFlow(context, R.string.string_key)
or use extension functions
// Get a translation with fallback to Android resources
val text = context.getStringT(R.string.string_key)
// Get a translation with fallback to Android resources with parameters
val textWithParams = context.getStringT(R.string.string_with_params, "param1", "param2")