|
1 | | -# Kotlin Multiplatform and Android package for Tolgee |
| 1 | +# Tolgee Mobile Kotlin SDK (Alpha) |
2 | 2 |
|
3 | | -🚨🚨🚨This package is currently under heavy development and will be released under alpha versions until stable and properly tested by pilot users.🚨🚨🚨 |
| 3 | +🚨🚨🚨This package is still under development and the API is not yet stable. |
| 4 | +Feel free to use it, but there might be API breakage between releases.🚨🚨🚨 |
4 | 5 |
|
5 | | -[](https://tolgee.io/)   |
| 6 | +[](https://tolgee.io/) |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +[](https://github.com/tolgee/tolgee-mobile-kotlin-sdk/releases/latest) |
| 12 | +[](https://github.com/tolgee/tolgee-mobile-kotlin-sdk/blob/master/LICENSE) |
| 13 | +[](https://github.com/tolgee/tolgee-mobile-kotlin-sdk) |
| 14 | +[](https://github.com/tolgee/tolgee-platform) |
| 15 | +[](https://github.com/tolgee/tolgee-platform/discussions) |
| 16 | +[](https://dev.to/tolgee_i18n) |
| 17 | +[](https://docs.tolgee.io/) |
| 18 | +[](https://tolg.ee/slack) |
| 19 | +[](https://www.youtube.com/@tolgee) |
| 20 | +[](https://www.linkedin.com/company/tolgee/) |
| 21 | +[](https://x.com/Tolgee_i18n) |
6 | 22 |
|
7 | | -A flexible Gradle plugin and runtime library for integrating [Tolgee translations](https://tolgee.io) into **Kotlin Multiplatform** and **Compose** projects. |
| 23 | +## What is Tolgee? |
8 | 24 |
|
9 | | -## Gradle plugin |
| 25 | +[Tolgee](https://tolgee.io/) is a powerful localization platform that simplifies the translation process for your applications. |
| 26 | +This SDK provides integration for Kotlin-based projects, with a primary focus on Android. |
10 | 27 |
|
11 | | -Comes with a convenient task to pull your latest translations directly into your resources folder. |
| 28 | +Currently, Android is fully supported, but any Kotlin-based codebase can in theory use this library. |
12 | 29 |
|
13 | | -### Setup |
| 30 | +## Features |
14 | 31 |
|
15 | | -Using Version Catalog is highly recommended to keep your versions aligned. |
16 | | - |
17 | | -```toml |
18 | | -[plugins] |
19 | | -tolgee = { id = "dev.datlag.tolgee", version.ref = "tolgee" } |
20 | | -``` |
| 32 | +- **Over-the-air updates**: Update your translations without releasing a new app version |
| 33 | +- **Multiple format support**: |
| 34 | + - Sprintf (Android SDK) formatting |
| 35 | + - ICU (Tolgee Native Flat JSON) formatting |
| 36 | +- **Compose integration**: Full integration with Jetpack Compose and Compose Multiplatform |
| 37 | +- **Compiler plugin**: Automatically transform existing code to use Tolgee without manual changes |
| 38 | +- **Kotlin Multiplatform**: Designed with multiplatform support in mind |
21 | 39 |
|
22 | | -**Configuration** |
23 | | - |
24 | | -You can change the plugin behavior to your needs: |
25 | | - |
26 | | -```kotlin |
27 | | -tolgee { |
28 | | - // REQUIRED |
29 | | - apiKey.set("<YOUR TOLGEE APIKEY WITH TRANSLATION READ ACCESS>") // or use the 'tolgee.apikey=' property instead |
30 | | - |
31 | | - // more options |
32 | | - pull { ... } |
33 | | - push { ... } |
34 | | - |
35 | | - // change compile time behavior |
36 | | - compilerPlugin { |
37 | | - android { |
38 | | - // Replaces Context.getString occurrences with Context.getStringT |
39 | | - replaceGetString.set(false) // default true |
40 | | - } |
41 | | - } |
42 | | -} |
43 | | -``` |
| 40 | +## Modules |
44 | 41 |
|
45 | | -### Usage |
| 42 | +The SDK is split into multiple modules, each serving a specific purpose: |
46 | 43 |
|
47 | | -Pull translations from Tolgee using the `pullTranslation` Gradle task. |
48 | | -Push local translations to Tolgee using the `pushTranslation` Gradle task. |
| 44 | +- **[Core](./core/README.md)**: Base library for fetching translations from CDN and querying them |
| 45 | +- **[Compose](./compose/README.md)**: Extension for using the library with Jetpack Compose or Compose Multiplatform |
| 46 | +- **[Gradle Plugin](./gradle-plugin/README.md)**: Gradle plugin for integrating and configuring the compiler plugin |
49 | 47 |
|
50 | | -## Core |
| 48 | +## Which Module Should I Use? |
51 | 49 |
|
52 | | -This Kotlin Multiplatform library provides runtime support for Tolgee translations in your app. |
53 | | -No longer creating a new release just to update your strings. |
| 50 | +- If you are using **traditional Android Views**, use the [Core](./core/README.md) module |
| 51 | +- If you are using **Jetpack Compose** or **Compose Multiplatform**, use the [Compose](./compose/README.md) module |
| 52 | +- If you want to **automatically transform existing code** to use Tolgee, add the [Gradle Plugin](./gradle-plugin/README.md) |
54 | 53 |
|
55 | | -### Setup |
| 54 | +## Installation |
56 | 55 |
|
57 | 56 | Using Version Catalog is highly recommended to keep your versions aligned. |
58 | 57 |
|
| 58 | +### Core Module (Traditional Android) |
| 59 | + |
59 | 60 | ```toml |
| 61 | +# gradle/libs.versions.toml |
60 | 62 | [libraries] |
61 | | -tolgee = { group = "dev.datlag.tolgee", name = "core", version.ref = "tolgee" } |
| 63 | +tolgee = { group = "io.tolgee.mobile-kotlin-sdk", name = "core", version.ref = "tolgee" } |
62 | 64 | ``` |
63 | 65 |
|
64 | | -### Usage |
65 | | - |
66 | | -Simply create a `Tolgee` singleton or multiple instances, using an API Key and/or a content delivery url. |
| 66 | +```kotlin |
| 67 | +// build.gradle.kts |
| 68 | +dependencies { |
| 69 | + implementation(libs.tolgee) |
| 70 | +} |
| 71 | +``` |
67 | 72 |
|
68 | | -#### Content Delivery |
| 73 | +### Compose Module (Jetpack Compose or Compose Multiplatform) |
69 | 74 |
|
70 | | -Content Delivery supports JSON only and can be used with any formatting option. |
| 75 | +```toml |
| 76 | +# gradle/libs.versions.toml |
| 77 | +[libraries] |
| 78 | +tolgee = { group = "io.tolgee.mobile-kotlin-sdk", name = "compose", version.ref = "tolgee" } |
| 79 | +``` |
71 | 80 |
|
72 | 81 | ```kotlin |
73 | | -/** Thread safe: Retrieve the current singleton or create one. */ |
74 | | -val tolgee = Tolgee.instanceOrInit { |
75 | | - apiKey = "<API KEY>" |
76 | | - contentDelivery("<ContentDelivery URL>") { |
77 | | - format(Tolgee.Formatter.ICU) // default formatting |
78 | | - format(Tolgee.Formatter.Sprintf) // for sprintf or Java.format formatting |
79 | | - } |
| 82 | +// build.gradle.kts |
| 83 | +dependencies { |
| 84 | + implementation(libs.tolgee) |
80 | 85 | } |
| 86 | +``` |
81 | 87 |
|
82 | | -/** Updates the text automatically when loaded from API or locale changed. */ |
83 | | -val updatingText: Flow<String> = tolgee.translation("key") |
| 88 | +### Gradle Plugin (Compiler Plugin) |
84 | 89 |
|
85 | | -/** Returns the text that's currently loaded from API. */ |
86 | | -/** Requires `tolgee.preload` or `tolgee.translation` call else always null. */ |
87 | | -val currentText: String? = tolgee.instant("key") |
| 90 | +```toml |
| 91 | +# gradle/libs.versions.toml |
| 92 | +[plugins] |
| 93 | +tolgee = { id = "io.tolgee.mobile-kotlin-sdk", version.ref = "tolgee" } |
88 | 94 | ``` |
89 | 95 |
|
90 | | -## Compose |
| 96 | +```kotlin |
| 97 | +// build.gradle.kts |
| 98 | +plugins { |
| 99 | + alias(libs.plugins.tolgee) |
| 100 | +} |
| 101 | +``` |
91 | 102 |
|
92 | | -### Setup |
| 103 | +## Basic Usage |
93 | 104 |
|
94 | | -Using Version Catalog is highly recommended to keep your versions aligned. |
| 105 | +For detailed usage instructions, please refer to the module-specific documentation: |
95 | 106 |
|
96 | | -```toml |
97 | | -[libraries] |
98 | | -tolgee = { group = "dev.datlag.tolgee", name = "compose", version.ref = "tolgee" } |
99 | | -``` |
| 107 | +- [Core Module Documentation](./core/README.md)—For traditional Android and base functionality |
| 108 | +- [Compose Module Documentation](./compose/README.md)—For Jetpack Compose and Compose Multiplatform |
| 109 | +- [Gradle Plugin Documentation](./gradle-plugin/README.md)—For compiler plugin configuration |
100 | 110 |
|
101 | | -### Usage |
| 111 | +### Quick Start |
102 | 112 |
|
103 | | -``` |
104 | | -@Composable |
105 | | -fun SimpleText() { |
106 | | - Text(text = stringResource(tolgee, Res.string.about)) |
107 | | -} |
| 113 | +Here's a quick example of initializing Tolgee in an Android application: |
108 | 114 |
|
109 | | -@Composable |
110 | | -fun ArgsSupported(vararg args: Any) { |
111 | | - Text(text = stringResource(tolgee, Res.string.about, *args)) |
| 115 | +```kotlin |
| 116 | +class MyApplication : Application() { |
| 117 | + override fun onCreate() { |
| 118 | + super.onCreate() |
| 119 | + |
| 120 | + Tolgee.init { |
| 121 | + contentDelivery { |
| 122 | + url = "https://cdn.tolg.ee/your-cdn-url-prefix" |
| 123 | + storage = TolgeeStorageProviderAndroid(this@MyApplication, BuildConfig.VERSION_CODE) |
| 124 | + } |
| 125 | + } |
| 126 | + } |
112 | 127 | } |
113 | 128 | ``` |
114 | 129 |
|
115 | | -#### Jetpack Compose? |
| 130 | +## Example Projects |
116 | 131 |
|
117 | | -What if you are using Jetpack Compose (Android only) or some explicit strings in your android source? |
118 | | -No problem! This is handled as well. |
| 132 | +For complete examples of how to use the Tolgee SDK, check out the demo projects: |
119 | 133 |
|
120 | | -```kotlin |
121 | | -@Composable |
122 | | -fun AndroidOnly() { |
123 | | - Text(text = i18n.stringResource(R.string.android_string)) |
124 | | -} |
| 134 | +- [Example Android](./demo/exampleandroid)—Traditional Android Views example |
| 135 | +- [Example Jetpack](./demo/examplejetpack)—Jetpack Compose example |
| 136 | +- [Multiplatform Compose](./demo/multiplatform-compose)—Compose Multiplatform example |
125 | 137 |
|
126 | | -@Composable |
127 | | -fun AndroidWithArgs(vararg args: Any) { |
128 | | - Text(text = i18n.stringResource(R.string.android_string, *args)) |
129 | | -} |
130 | | -``` |
| 138 | +## Contributing |
131 | 139 |
|
132 | | -### This is a non-profit project! |
| 140 | +Contributions are welcome! Please feel free to submit a Pull Request. |
133 | 141 |
|
134 | | -Sponsoring to this project means sponsoring to all my projects! |
135 | | -So the further text is not to be attributed to this project, but to all my apps and libraries. |
| 142 | +## License |
136 | 143 |
|
137 | | -Supporting this project helps to keep it up-to-date. You can donate if you want or contribute to the project as well. |
138 | | -This shows that the library is used by people, and it's worth to maintain. |
| 144 | +This project is licensed under the Apache License 2.0—see the [LICENSE](LICENSE) file for details. |
0 commit comments