Giter Site home page Giter Site logo

phrase's Introduction

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)

phrase's People

Contributors

nikeorever avatar

Stargazers

 avatar

Watchers

 avatar

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.