Skip to content

dynodict/dynodict-android

Repository files navigation

DynoDict

How to start

  1. Add dependency for the plugin:
   pluginManagement {
       repositories {
           ...
           mavenCentral()
           ...
       }
   }
  1. Declare plugin in top-level build.gradle.kts:
    plugins {
        id 'org.dynodict.plugin' version 'x.x.x' apply false
     }
    
  2. Apply plugin in app/build.gradle.kts:
    plugins {
        id 'org.dynodict.plugin'
     }
    
  3. Add dependency for the SDK:
    implementation 'org.dynodict:android:x.x.x'
    implementation 'org.dynodict:core:x.x.x'
    
  4. Run gradle task:
    ./gradlew clean :app:migrateStrings --input=app/src/main/res/values/strings.xml
    
    see Migration your project to use DynoDict
  5. 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"))
      }
    }
    
  6. 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)

Description

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)

Update metadata and buckets

  1. Apply plugin:

    plugins {
        id 'org.dynodict.plugin'
     }
    
  2. run gradle script

    ./gradlew clean :app:downloadStrings --package=org.dynodict --url=metadata_url 
    

    This task will download metadata from metadata_url and will generate Kotlin file Strings.kt with Kotlin placeholders as well as json/yaml buckets.

  3. Enjoy!

Customization

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

Migration your project to use DynoDict

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

Customization

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'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •