Coder Social home page Coder Social logo

android-placeholders-validator's Introduction

android-placeholders-validator

Gradle plugin which validates placeholders from translated strings.xml files by comparing them with main strings.xml file.

Why may I need it?

If other people make translations for your app there is a risk that they may modify and malform string placeholders.
I struggled with such situations which eventually led to app crashing only for Korean people (sorry Korean people).
Then I applied the plugin in my other apps and it turned out that some placeholders are also malformed! Luckily it didn't make the app crashing, but not luckily, displayed strings were incorrectly formatted. Of course you could also malform or accidentaly modify such placeholder by yourself, but as we programmers don't make mistakes, it is less probable, isn't it? ๐Ÿ˜…

Validation

The plugin compares placeholders from translated strings.xml files with placeholders from your main strings.xml file. When there is no match, you get clear message with exact place of issue, like this one:

Affected file: .../app/src/main/res/values-fr/strings.xml Affected key: settings_version. Should be: [%1$s] but is: [] 
Affected file: .../app/src/main/res/values-fr/strings.xml Affected key: post_history_create_date. Should be: [%1$s] but is: [] 
Affected file: .../app/src/main/res/values-de/strings.xml Affected key: settings_version. Should be: [%1$s] but is: [%2$s] 

Usage

In main build.grale file:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.appunite.placeholdersvalidator:placeholders-validator:1.0.2"
  }
}

At the end of your app module build.gradle file:

apply plugin: "com.appunite.placeholdersvalidator"
placeholdersValidator {
    resourcesDir = android.sourceSets.main.res.sourceFiles
}
preBuild.dependsOn placeholdersValidatorTask

Code below will run the validation before building. You can adjust it to your needs though.

preBuild.dependsOn placeholdersValidatorTask

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.