Skip to content

Commit bec3356

Browse files
committed
docs: improve code examples with descriptive comments in Android SDK usage guide
1 parent 3b4d5ee commit bec3356

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

android-sdk/usage.mdx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@ description: How to use Tolgee Android SDK in your Android application
66

77
## Simple Translation
88

9+
Get a translation with fallback to Android resources:
10+
911
```kotlin
10-
// Get a translation with fallback to Android resources
1112
val text = tolgee.t(context, R.string.string_key)
1213
textView.text = text
1314
```
1415

1516
## With Parameters
1617

18+
Get a translation with fallback to Android resources with parameters:
19+
1720
```kotlin
18-
// Get a translation with fallback to Android resources with parameters
1921
val textWithParams = tolgee.t(context, R.string.string_with_params, "param1", "param2")
2022
textView.text = textWithParams
2123
```
2224

2325
## Plurals
2426

27+
Handle Android plurals via resources:
28+
2529
```kotlin
26-
// Handle Android plurals via resources
2730
val itemsText = tolgee.tPlural(context, R.plurals.items_count, count, count)
2831
textView.text = itemsText
2932
```
@@ -36,14 +39,21 @@ textView.text = itemsText
3639

3740
### Language Switching
3841

42+
Set locale:
43+
3944
```kotlin
40-
// Set locale
4145
tolgee.setLocale("en")
46+
```
47+
48+
Get current locale:
4249

43-
// Get current locale
50+
```kotlin
4451
val locale = tolgee.getLocale()
52+
```
53+
54+
Listen for changes:
4555

46-
// Listen for changes
56+
```kotlin
4757
tolgee.changeFlow.collect {
4858
// Locale or available translations changed, update UI if needed
4959
}
@@ -53,11 +63,12 @@ tolgee.changeFlow.collect {
5363

5464
#### Formatter Configuration
5565

66+
Configure formatters for parsing translations from CDN:
67+
5668
```kotlin
5769
Tolgee.init {
5870
contentDelivery {
5971
url = "https://cdn.tolg.ee/your-cdn-url-prefix"
60-
// Configure formatters for parsing translations from CDN
6172
format(Tolgee.Formatter.Sprintf) // Android SDK formatting (default)
6273
// format(Tolgee.Formatter.ICU) // Tolgee Native Flat JSON formatting
6374
}
@@ -66,8 +77,9 @@ Tolgee.init {
6677

6778
#### Preloading Translations
6879

80+
Preload translations for the current locale from Activity:
81+
6982
```kotlin
70-
// Preload translations for the current locale from Activity
7183
override fun onStart() {
7284
super.onStart()
7385
tolgee.preload(this)

0 commit comments

Comments
 (0)