https://github.com/chrynan/strings

Kotlin Multiplatform Static String Resource Accessor and Creator Library

https://github.com/chrynan/strings

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.7%) to scientific vocabulary

Keywords

android ios kotlin kotlin-android kotlin-ios kotlin-library kotlin-multiplatform library resources

Keywords from Contributors

federated code-generation parcel redact
Last synced: 5 months ago · JSON representation

Repository

Kotlin Multiplatform Static String Resource Accessor and Creator Library

Basic Info
  • Host: GitHub
  • Owner: chRyNaN
  • License: apache-2.0
  • Language: Kotlin
  • Default Branch: master
  • Homepage:
  • Size: 303 KB
Statistics
  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
android ios kotlin kotlin-android kotlin-ios kotlin-library kotlin-multiplatform library resources
Created almost 7 years ago · Last pushed over 4 years ago
Metadata Files
Readme License

README.md

strings

Kotlin Multi-platform String Resource Accessor and Creator Library

Note: This project is in early development stages and is not ready for production use.

The goal of this library is to abstract both the creation and retrieval of strings in Kotlin Multi-platform Projects.

Using the library

Add the Dependencies

Plugin

groovy apply plugin: "com.chrynan.strings.plugin.gradle.json"

Runtime Dependency

```groovy repositories { maven { url = "https://dl.bintray.com/chrynan/chrynan" } }

dependencies { implementation "com.chrynan.strings:strings-accessor:$VERSION" } ```

Configure the Plugin

groovy jsonStrings { inputPaths = ["location/to/json/string/file.json"] outputPath = "src/commonMain/kotlin/com.chrynan.example" outputPackageName = "com.chrynan.example" }

Create the Strings

JSON

Create a JSON file with a top-level array containing the String objects. json [{ "type": "static", "name": "helloWorld", "value": "Hello World" }]

Kotlin Annotations (Not yet supported)

kotlin // File MyStrings - File name and location can be anything @file:StaticString(name = "helloWorld", value = "Hello World")

Run the Gradle Task

./gradlew generateStringsFromJsonInput

Add the generated StringAccessor

kotlin Strings.accessor = KotlinStrings() // Generated Class

Access the String Resources

kotlin // Using the generated String Resource IDs val myStaticString by string(resourceID = StringResIDs.myStaticString)

Definitions

StaticString

Static Strings are String values that are not formatted, meaning they do not require any arguments to obtain a String value.

JSON

json { "type": "static", "name": "hello_world", "value": "Hello World" }

Kotlin Annotations (Not yet supported)

kotlin @file:StaticString(name = "hello_world", value = "Hello World", locale = "en")

Kotlin Accessibility

kotlin val helloWorld = string(resourceID = StringResID.hello_world)

StringArray

String Arrays are Arrays of Static String values.

JSON

json { "type": "array", "name": "numbers", "values": ["one", "two", "three", "four", "five"] }

Kotlin Annotations (Not yet supported)

kotlin @file:StringArray( name = "numbers", locale = "en", values = [ StringArrayItem(value = "one"), StringArrayItem(value = "two"), StringArrayItem(value = "three"), StringArrayItem(value = "four"), StringArrayItem(value = "five") ] )

Kotlin Accessibility

kotlin val numbers = stringArray(resourceID = StringResID.numbers)

DynamicString

Dynamic Strings are String values that can be formatted by providing additional arguments at runtime.

JSON

json { "type": "dynamic", "name": "hello_name", "value": "Hello ${name:String}" }

Kotlin Annotations (Not yet supported)

kotlin @file:DynamicString(name = "hello_name", value = "Hello \${name:String}", locale = "en")

Dynamic String Arguments:

Dynamic String arguments take the following format: ${name:type}. Or if in Kotlin code the $ character must be escaped: \${name:type}. Dynamic Strings with no arguments are essentially Static Strings.

Supported Argument Types:

| Kotlin Type | Expanded Definition | Brief Definition | | --- | --- | --- | | Any | ${name:Any} | ${name:a} | | Char | ${name:Char} | ${name:c} | | String | ${name:String} | ${name:s} | | Int | ${name:Int} | ${name:i} | | Long | ${name:Long} | ${name:l} | | Float | ${name:Float} | ${name:f} | | Double | ${name:Double} | ${name:d} | | Custom | ${name:com.chrynan.Example} | --- |

Custom Types: Custom types can be provided with the following syntax: ${name:packageName.typeName}.

The provided custom type name must be the fully qualified Kotlin type name.

Argument Names:

All Dynamic String arguments need to be prefaced with an argument name. These names will be used to create input argument names in the generated code.

  • Dynamic Strings can use the same argument multiple times: "Hello ${name:String}! How are you ${name}?"
  • If Dynamic String reuse same argument multiple times, the type only has to be provided once, for the first usage of the name.
  • Non-matching types for the same argument name will cause an error.
  • Argument names cannot begin with a number
  • Argument names must conform to Kotlin property name requirements.

Escaping Arguments:

To escape the $ character so that it doesn't register as an argument, use the \ character: \$.

HtmlString

Html Strings are Dynamic Strings that contain Html markup. No special parsing of the markup is performed in this library. Instead, this is a way to organize Html Strings separately so that they can be handled appropriately.

JSON

json { "type": "html", "name": "hello_name", "value": "Hello <b>${name:String}</b>" }

Kotlin Annotations (Not yet supported)

kotlin @file:HtmlString(name = "greeting", value = "Hello <b>\${name:String}</b>")

StringPlurals

String Plurals are Dynamic Strings that are grouped together and distinguished by a provided Quantity. Each of the StringPluralItems must have the same amount of arguments.

JSON

json { "type": "plurals", "name": "items", "values": [ { "quantity": "one", "value": "${number:Int} item" }, { "quantity": "many", "value": "${number:Int} items" } ] }

Kotlin Annotations (Not yet supported)

kotlin @file:StringPlurals( name = "items", locale = "en", values = [ StringPluralItem(quantity = Quantity.ONE, value = "\${number:Int} item"), StringPluralItem(quantity = Quantity.MANY, value = "\${number:Int} items") ] )

Note: That it is up to the accessor of the StringPlurals value to provide a Quantity to retrieve the appropriate String.

Owner

  • Name: Christopher
  • Login: chRyNaN
  • Kind: user
  • Location: Austin, TX
  • Company: Starry

GitHub Events

Total
Last Year

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 163
  • Total Committers: 2
  • Avg Commits per committer: 81.5
  • Development Distribution Score (DDS): 0.025
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Chris c****n@s****m 159
Christopher b****p@g****m 4
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago


Dependencies

.github/workflows/build.yml actions
  • actions/checkout v1 composite
  • actions/setup-java v1 composite
.github/workflows/greetings.yml actions
  • actions/first-interaction v1 composite
.github/workflows/publish.yml actions
  • actions/checkout v1 composite
  • actions/setup-java v1 composite
strings-accessor/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
strings-accessor-coroutines/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
  • org.jetbrains.kotlinx:kotlinx-coroutines-core 1.3.7 implementation
  • org.jetbrains.kotlinx:kotlinx-coroutines-core-common 1.3.7 implementation
  • org.jetbrains.kotlinx:kotlinx-coroutines-core-js 1.3.7 implementation
strings-annotation/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
strings-core/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
strings-creator-core/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
strings-creator-input-json/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
  • org.jetbrains.kotlinx:kotlinx-serialization-runtime 0.20.0 implementation
  • org.jetbrains.kotlinx:kotlinx-serialization-runtime-common 0.20.0 implementation
  • org.jetbrains.kotlinx:kotlinx-serialization-runtime-js 0.20.0 implementation
strings-creator-output-android/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
strings-creator-output-kotlin/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-js * implementation
strings-example-json/build.gradle maven
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
  • org.jetbrains.kotlin:kotlin-stdlib-common * implementation
strings-plugin-annotation/build.gradle maven
  • com.chrynan.logger:logger-core-jvm 1.2.1 api
  • de.jensklingenberg:mpapt-runtime 0.8.4 api
  • org.jetbrains.kotlin:kotlin-compiler-embeddable 1.3.71 compileOnly
  • org.jetbrains.kotlin:kotlin-stdlib * implementation
strings-plugin-gradle-json/build.gradle maven
  • org.jetbrains.kotlin:kotlin-gradle-plugin 1.3.72 implementation
  • org.jetbrains.kotlin:kotlin-stdlib * implementation