- Add dependency for the plugin:
pluginManagement {
repositories {
...
mavenCentral()
...
}
}
- Declare plugin in top-level build.gradle.kts:
plugins { id 'org.dynodict.plugin' version 'x.x.x' apply false } - Apply plugin in app/build.gradle.kts:
plugins { id 'org.dynodict.plugin' } - Add dependency for the SDK:
implementation 'org.dynodict:android:x.x.x' implementation 'org.dynodict:core:x.x.x' - Run gradle task:
see Migration your project to use DynoDict
./gradlew clean :app:migrateStrings --input=app/src/main/res/values/strings.xml - Upload the metadata.json and strings_x_xx.json to the server and initialize the SDK to get the
translations.
CoroutineScope(Dispatchers.Main).launch { DynoDict.initWith(this@MoWidApplication, endpoint = YOUR_ENDPOINT_HERE, Settings.Production).apply { setLocale(DLocale("en")) } } - Verify everything is fine with the text and update the text:
./gradlew clean :app:downloadStrings --package=YOUR_PACKAGE --url=metadata_url
see more Update metadata and buckets 8. You the resources: Instead of having xml resources - use the generated classes.
Text(
text = stringResource(id = R.string.label_empty_state),
textAlign = TextAlign.Center,
)
Converts to:
Text(
text = Label.Empty.State.value,
textAlign = TextAlign.Center)
This is the SDK to generate and update the list of Strings used in your project. Use plugin to generate Kotlin placeholders for strings. For example:
{
"translations": [
{
"key": "LoginScreen.ButtonName",
"params": [
{
"type": "string",
"key": "param1"
},
{
"type": "long",
"key": "param2",
"format":"startDate"
}
],
"value": "Log in {param1} ({param2})"
}
]
}
is converted to:
object LoginScreen : StringKey("LoginScreen") {
object ButtonName : StringKey("ButtonName", LoginScreen) {
fun get(param1: String, param2: Long): String {
return DynoDict.instance.get(
this,
Parameter.StringParameter(param1, key = "param1"),
Parameter.LongParameter(param2, key = "param2", format = "startDate"))
}
}
}
and can be used further in code:
val loginButtonName = LoginScreen.ButtonName.get("Param1", time)
-
Apply plugin:
plugins { id 'org.dynodict.plugin' } -
run gradle script
./gradlew clean :app:downloadStrings --package=org.dynodict --url=metadata_urlThis task will download metadata from metadata_url and will generate Kotlin file Strings.kt with Kotlin placeholders as well as json/yaml buckets.
-
Enjoy!
For :downloadStrings there is only one mandatory parameters which need to be passed:
--url - Url where to get the data from.
Optional parameters which can be used:
--package - package which should be used to place Kotlin files. It is also used to set package at the top of the file. Default is evaluated based on the first non-single folder
--output - location where generated Kotlin file should be placed to. Default src/main/java
--assets - location of the assets folder where default .json files are placed to
This task will migrate your project to use DynoDict. It will generate Kotlin files with placeholders.
./gradlew clean migrateStrings --input=app/src/main/res/values/strings.xml
For :migrateStrings there is only one mandatory parameters which need to be passed:
--input - location of the strings.xml file. Default is app/src/main/res/values/strings.xml
Optional parameters which can be used:
--output - location where generated Kotlin file should be placed to. Default ''
--schemeVersion - version of the scheme to use. Default is 1.
--bucketName - name of the bucket to use. Default is 'strings'