Skip to content
Shushant TiwariMobile engineer & maker
← All stories

Empowering Android Development: Unleashing the Potential of Gradle Plugins for Seamless Localization and Resource Management

Two Gradle plugins that automate localization and generate typed access to strings and drawables for Compose projects.

Shushant TiwariMobile engineer. Building tools that help us see.
Contents

Developing Android applications often involves managing multiple aspects, such as localization and resource access. To enhance the development workflow, two powerful Gradle plugins have been crafted — the Gradle Localization Plugin and the Generate App Resource Class Plugin. Let’s dive into the capabilities and benefits of each plugin.

Gradle Localization Plugin

Overview

The Gradle Localization Plugin is a robust tool tailored to simplify and optimize the localization process for Android applications. It automates key aspects of localization, making it seamless for solo developers or teams. Say farewell to manual translation management and ensure a consistent user experience across various languages.

Elevate your app’s global reach with automated string extraction, seamless translation service integration, and automatic resource file generation.

Features

  1. Automated Extraction: Effortlessly extract translatable strings from your source code and XML resources.
  2. Automatic Resource File Generation: Streamline your build process to automatically generate localized resource files.
  3. Collaboration Enhancement: Improve collaboration between developers and translators with clear, standardized workflows.

Getting Started

  1. Apply the plugin to your app-level build.gradle file:
plugins {
    id 'dev.shushant.localization.plugin' version 'x.x.x'
}

localization {
   supportedLang = listOf(
       // this Languages enum is already available in plugin as supported
       // languages

       Languages.Kannada,
       Languages.Bengali,
       Languages.Hindi,
       // Add more languages...
   )
   moduleName = ":moduleName"
   pathToGenerateSupportedLanguageEnum = "Language Enum path"
   packageName = "Application Id"
}
  1. Configure the plugin with your desired settings.
  2. Build your project to automatically generate the localized resource files.
  3. Unlock the full potential of globalizing your Android app!

Visit the Gradle portal for detailed information and updates. Feel free to contribute or provide feedback by opening an issue.

Illustration accompanying Empowering Android Development: Unleashing the Potential of Gradle Plugins for Seamless Localization and Resource Management

Gradle Localization Plugin

Generate App Resource Class Plugin

Overview

The Generate App Resource Class Plugin simplifies resource management in Jetpack Compose projects. This Gradle plugin automates the creation of a Kotlin class serving as a central hub for accessing application resources directly from your Composables.

Features

  1. Automatic Generation: Generate a Kotlin class with constants for all string resources, ensuring easy and type-safe access.
  2. Drawable Resource Access: Access drawable resources through generated extension functions.
  3. Seamless Integration: Integrate seamlessly into your build process to keep the resource class up-to-date.
  4. Code Readability and Maintainability: Improve code readability and maintainability by centralizing resource access.
plugins {
    id 'dev.shushant.generate-app-resource-class.plugin' version 'x.x.x'
}

appResourceExtension {
    stringFilePathWithFileName = ""
    iconsFilePathWithFileName = ""
    moduleName = ""
    packageNameWhereToGenerateFiles = ""
    applicationId =""
    classNameForIcons ="AppIcons"
    classNameForStrings ="AppStrings"
}
  1. Configure the plugin with your desired settings.
  2. Build your project to automatically generate the AppResource class.
  3. Access strings and drawables directly from your Composables using the generated class.
  4. Enhance your Compose development workflow by leveraging the Generate App Resource Class plugin.

Illustration accompanying Empowering Android Development: Unleashing the Potential of Gradle Plugins for Seamless Localization and Resource Management

Illustration accompanying Empowering Android Development: Unleashing the Potential of Gradle Plugins for Seamless Localization and Resource Management

Generated class for String Resource & Icons

// Access string resource as string to use in composables
val welcomeMessage: String = FileName.welcomeMessage

// Access drawable resource as Painter to use in composables 
val appIcon: Painter = FileName.appIcon

Illustration accompanying Empowering Android Development: Unleashing the Potential of Gradle Plugins for Seamless Localization and Resource Management

Localization

Plugin Links:

https://plugins.gradle.org/plugin/dev.shushant.localization.plugin

https://plugins.gradle.org/plugin/dev.shushant.generate-app-resource-class.plugin

I hope you have enjoyed reading this article! Please leave 1/2/tons of 👏 if you liked it, feedbacks are welcome as well!

Originally published on Medium on 27 Dec 2023. Republished here by the author.

Examples and opinions reflect the original publication date.

Keep the conversation going.

Have a thought to add?Join the conversation on Medium.