You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finally, use the same functions, `rememberStrings()` and `ProvideStrings()`, to make your `LocalStrings` accessible down the tree. But this time you need to provide your `strings` and `LocalStrings` manually.
122
-
```kotlin
123
-
val lyricist = rememberStrings(strings)
124
-
125
-
ProvideStrings(lyricist, LocalStrings) {
126
-
// Content
127
-
}
128
-
```
129
-
130
-
---
131
-
</details>
132
-
133
111
Now you can use `LocalStrings` to retrieve the current strings.
Use the Lyricist instance provided by `rememberStrings()` to change the current locale. This will trigger a [recomposition](https://developer.android.com/jetpack/compose/mental-model#recomposition) that will update the strings wherever they are being used.
135
+
Use the Lyricist instance provided by `rememberStrings()` to change the current locale. This will trigger a [recomposition](https://developer.android.com/jetpack/compose/mental-model#recomposition) that will update the entire content.
158
136
```kotlin
159
137
lyricist.languageTag =Locales.PT
160
138
```
161
139
140
+
**Important**
141
+
142
+
Lyricist uses the System locale as current language (on Compose it uses `Locale.current`). If your app has a mechanism to change the language in-app please set this value on `rememberStrings(currentLanguageTag = CURRENT_VALUE_HERE)`.
143
+
144
+
If you change the current language at runtime Lyricist won't persist the value on a local storage by itself, this should be done by you. You can save the current language tag on shared preferences, a local database or even through a remote API.
145
+
162
146
### Controlling the visibility
163
147
To control the visibility (`public` or `internal`) of the generated code, provide the following (optional) argument to KSP in the module's `build.gradle`.
164
148
```gradle
@@ -174,8 +158,14 @@ ksp {
174
158
arg("lyricist.generateStringsProperty", "true")
175
159
}
176
160
```
161
+
After a successfully build you can refactor your code as below.
162
+
```kotlin
163
+
// Before
164
+
Text(text =LocalStrings.current.hello)
177
165
178
-
**Important:** Lyricist uses the System locale as default. It won't persist the current locale on storage, is outside its scope.
You can easily migrate from `strings.xml` to Lyricist just by copying the generated files to your project. That way, you can finally say goodbye to `strings.xml`.
220
210
211
+
## Extending Lyricist
212
+
213
+
<details><summary>Writing the generated code from KSP manually</summary>
214
+
215
+
Don't want to enable KSP to generate the code for you? No problem! Follow the steps below to integrate with Lyricist manually.
216
+
217
+
1. Map each supported language tag to their corresponding instances.
218
+
```kotlin
219
+
val strings =mapOf(
220
+
Locales.EN to EnStrings,
221
+
Locales.PT to PtStrings,
222
+
Locales.ES to EsStrings,
223
+
Locales.RU to RuStrings
224
+
)
225
+
```
226
+
227
+
2. Create your `LocalStrings` and choose one translation as default.
3. Use the same functions, `rememberStrings()` and `ProvideStrings()`, to make your `LocalStrings` accessible down the tree. But this time you need to provide your `strings` and `LocalStrings` manually.
233
+
```kotlin
234
+
val lyricist = rememberStrings(strings)
235
+
236
+
ProvideStrings(lyricist, LocalStrings) {
237
+
// Content
238
+
}
239
+
```
240
+
</details>
241
+
242
+
<details><summary>Supporting other UI Toolkits</summary>
243
+
244
+
At the moment Lyricist only supports Jetpack Compose and Compose Multiplatform out of the box. If you need to use Lyricist with other UI Toolkit (Android Views, SwiftUI, Swing, GTK...) follow the instructions bellow.
245
+
246
+
1. Map each supported language tag to their corresponding instances
247
+
```kotlin
248
+
val translations =mapOf(
249
+
Locales.EN to EnStrings,
250
+
Locales.PT to PtStrings,
251
+
Locales.ES to EsStrings,
252
+
Locales.RU to RuStrings
253
+
)
254
+
```
255
+
256
+
2. Create an instance of Lyricist, can be a project-wide singleton or a local instance per module
257
+
```kotlin
258
+
val lyricist =Lyricist(defaultLanguageTag, translations)
259
+
```
260
+
261
+
3. Collect Lyricist state and notify the UI to update whenever it changes
Current version: 
0 commit comments