Skip to content

Commit 40cfbdf

Browse files
committed
feat: add language change to android demo
1 parent 47d0ba6 commit 40cfbdf

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

demo/android-view/src/main/kotlin/io/tolgee/demo/view/MainActivity.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,24 @@ class MainActivity : ComponentActivity() {
2727
setContentView(R.layout.activity_main)
2828

2929
val basic = findViewById<TextView>(R.id.basic_text)
30+
val name = findViewById<TextView>(R.id.app_name_text)
3031
val parameter = findViewById<TextView>(R.id.parameterized_text)
31-
val button = findViewById<Button>(R.id.button)
3232
val plural = findViewById<TextView>(R.id.plural_text)
3333
val array = findViewById<TextView>(R.id.array_text)
34+
val buttonEn = findViewById<Button>(R.id.button_en)
35+
val buttonFr = findViewById<Button>(R.id.button_fr)
36+
val buttonCs = findViewById<Button>(R.id.button_cs)
3437

38+
lifecycleScope.launch {
39+
tolgee.tFlow(
40+
context = this@MainActivity,
41+
id = R.string.app_name,
42+
).collect { value ->
43+
withContext(Dispatchers.Main) {
44+
name.text = value
45+
}
46+
}
47+
}
3548
lifecycleScope.launch {
3649
tolgee.tFlow(
3750
context = this@MainActivity,
@@ -74,8 +87,15 @@ class MainActivity : ComponentActivity() {
7487
}
7588
}
7689
}
77-
button.setOnClickListener {
90+
91+
buttonEn.setOnClickListener {
7892
tolgee.setLocale(Locale.ENGLISH)
7993
}
94+
buttonFr.setOnClickListener {
95+
tolgee.setLocale(Locale.FRENCH)
96+
}
97+
buttonCs.setOnClickListener {
98+
tolgee.setLocale(Locale("cs"))
99+
}
80100
}
81101
}

demo/android-view/src/main/kotlin/io/tolgee/demo/view/MyApplication.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class MyApplication : Application() {
1111
Tolgee.init {
1212
contentDelivery {
1313
url = "https://cdn.tolg.ee/96eacb8b07382b60c3f94b30405cc49b"
14-
formatter = Tolgee.Formatter.Sprintf
1514
}
1615
}
1716
}

demo/android-view/src/main/res/layout/activity_main.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
android:gravity="center"
1010
tools:context=".MainActivity">
1111

12+
<TextView
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:id="@+id/app_name_text"
16+
android:text="@string/app_name"
17+
android:textAlignment="center"
18+
android:textSize="20sp"
19+
android:layout_marginBottom="24dp" />
20+
1221
<TextView
1322
android:layout_width="match_parent"
1423
android:layout_height="wrap_content"
@@ -46,8 +55,24 @@
4655
android:layout_width="match_parent"
4756
android:layout_height="wrap_content"
4857
android:layout_margin="16dp"
49-
android:id="@+id/button"
58+
android:id="@+id/button_en"
5059
android:text="English"
5160
android:textAlignment="center" />
5261

62+
<Button
63+
android:layout_width="match_parent"
64+
android:layout_height="wrap_content"
65+
android:layout_margin="16dp"
66+
android:id="@+id/button_fr"
67+
android:text="French"
68+
android:textAlignment="center" />
69+
70+
<Button
71+
android:layout_width="match_parent"
72+
android:layout_height="wrap_content"
73+
android:layout_margin="16dp"
74+
android:id="@+id/button_cs"
75+
android:text="Czech"
76+
android:textAlignment="center" />
77+
5378
</LinearLayout>

demo/multiplatform-compose/src/commonMain/kotlin/io/tolgee/demo/compose/Setup.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ object Setup {
88
Tolgee.init {
99
contentDelivery {
1010
url = "https://cdn.tolg.ee/96eacb8b07382b60c3f94b30405cc49b"
11-
formatter = Tolgee.Formatter.Sprintf
1211
}
1312
}
1413
}

0 commit comments

Comments
 (0)