Phrase Plugin

A Gradle plugin which generates compile-safe format string builders.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

cn.nikeo.phrase
ArtifactId

ArtifactId

gradle-plugin
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Phrase Plugin
A Gradle plugin which generates compile-safe format string builders.
Project URL

Project URL

https://github.com/nikeorever/phrase
Source Code Management

Source Code Management

https://github.com/nikeorever/phrase

Download gradle-plugin

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.10

runtime (1)

Group / Artifact Type Version
cn.nikeo.phrase : classes-writer jar 1.1.2

Project Modules

There are no modules declared in this project.

Phrase

Maven Central

A Gradle plugin which generates compile-safe format string builders.

The reason why I created this library

Since Paraphrase has been in a state of experimental, and the project is too old, it seems difficult to maintain, so I created this library.

The goal of this library is consistent with Paraphrase

Sample

Do write your format strings like this (Support Comment):

<!--This is a comment of greeting string-->
<string name="greeting">Hello, {other_name}! My name is {my_name}.</string>

Execute gradle task 'generate{variant}PhraseClasses'

./gradlew :{module}:generate{variant}PhraseClasses

After successful execution, Gradle Plugin will generate a Kotlin File named Phrase.kt for you

// Automatically generated file. DO NOT MODIFY
package cn.nikeo.reparaturapplication

import android.content.Context
import cn.nikeo.phrase.runtime.AbstractPhrase
import kotlin.CharSequence
import kotlin.Suppress

@Suppress("ClassName")
class Phrase_greeting(
  context: Context
) : BasePhrase(context = context, stringResId = R.string.greeting) {
  fun my_name(value: CharSequence): Phrase_greeting {
    put("my_name", value)
    return this
  }

  fun other_name(value: CharSequence): Phrase_greeting {
    put("other_name", value)
    return this
  }
}

/**
 * This is a comment of greeting string
 *
 * The string resource corresponding to [greeting] is in
 * /home/xianxueliang/AndroidStudioProjects/ReparaturApplication/app/src/main/res/values/strings.xml
 */
fun greeting(context: Context): Phrase_greeting = Phrase_greeting(context)

Do enjoy formatting them like this:

text.text = greeting(this)
    .my_name("Jake Wharton")
    .other_name("GitHub user")
    .format()

Or

greeting(this)
    .my_name("Jake Wharton")
    .other_name("GitHub user")
    .into(text)

Download

Top-level build file

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "cn.nikeo.phrase:gradle-plugin:1.1.2"
    }
}

App-module build file

apply plugin: 'com.android.application'
apply plugin: "cn.nikeo.phrase"

Library-module build file

apply plugin: 'com.android.library'
apply plugin: "cn.nikeo.phrase"

License

Apache License, Version 2.0, (LICENSE or https://www.apache.org/licenses/LICENSE-2.0)

Versions

Version
1.1.2
1.1.1
1.1.0
1.0.0