{"id":13610118,"url":"https://github.com/ioki-mobility/TextRef","last_synced_at":"2025-04-12T22:32:48.409Z","repository":{"id":54253684,"uuid":"156376043","full_name":"ioki-mobility/TextRef","owner":"ioki-mobility","description":"An abstraction over Android strings with formatting support","archived":false,"fork":false,"pushed_at":"2024-05-22T19:03:20.000Z","size":467,"stargazers_count":16,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-22T20:25:36.350Z","etag":null,"topics":["android","android-library","hacktoberfest","library","text"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ioki-mobility.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-06T11:52:02.000Z","updated_at":"2024-05-22T20:25:37.720Z","dependencies_parsed_at":"2022-08-13T10:10:18.868Z","dependency_job_id":"8c82ea18-0e35-444e-bef9-e336e942ffb2","html_url":"https://github.com/ioki-mobility/TextRef","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2FTextRef","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2FTextRef/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2FTextRef/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioki-mobility%2FTextRef/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ioki-mobility","download_url":"https://codeload.github.com/ioki-mobility/TextRef/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248641362,"owners_count":21138192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","hacktoberfest","library","text"],"created_at":"2024-08-01T19:01:41.419Z","updated_at":"2025-04-12T22:32:48.111Z","avatar_url":"https://github.com/ioki-mobility.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# TextRef\n\n[![CI](https://github.com/ioki-mobility/TextRef/actions/workflows/test-lib.yml/badge.svg)](https://github.com/ioki-mobility/TextRef/actions/workflows/test-lib.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/com.ioki.textref/textref?labelColor=%2324292E\u0026color=%233246c8)](https://central.sonatype.com/namespace/com.ioki.textref)\n[![Snapshot](https://img.shields.io/nexus/s/com.ioki.textref/textref?labelColor=%2324292E\u0026color=%234f78ff\u0026server=https://s01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/com/ioki/textref/)\n[![javadoc](https://javadoc.io/badge2/com.ioki.textref/textref/javadoc.svg?labelColor=%2324292E\u0026color=%236eaaff)](https://javadoc.io/doc/com.ioki.textref) \n[![MIT](https://img.shields.io/badge/license-MIT-blue.svg?labelColor=%2324292E\u0026color=%23d11064)](https://github.com/ioki-mobility/TextRef/blob/master/LICENSE.md)\n\n## What?\n\nTextRef is an abstraction over Android text. It wraps a `String` or a string/plurals resource ID.\nWith the help of an Android `Context` a final `String` can be resolved. Format args are supported too!\n\n## How?\n\n**Create**\n```kotlin\nTextRef.string(\"My string\")\nTextRef.stringRes(R.string.my_string)\nTextRef.pluralsRes(R.plurals.number_of_items, 3)\nTextRef.string(\"The arguments are %d and %s\", 5, \"foo\")\n```\n\n**Resolve**\n```kotlin\nval text: String = textRef.resolve(context)\n```\n\n## Why?\n\n* **String agnostic APIs:** Make functions return TextRefs to allow for any type of text representation\n* **Less dependent on Context:** No need to resolve string resources close to business logic such as view models\n* **Lazy formatting:** Pass format args and let TextRef do the formatting as late as possible.\n* **Simplified testing:** No need to mock `Context.getString`\n\n## Example\n\nHere's a simple MVP use case:\n\n```kotlin\n// View\nfun renderUserName(text: TextRef) {\n    userNameTextView.text = text.resolve(context)\n}\n\n// Presenter\nval userName = if (user != null) {\n    TextRef.string(user.name)\n} else {\n    TextRef.stringRes(R.string.guest)\n}\nview.renderUserName(userName)\n```\n\n## Requirements\n\n* API Level \u003e= 21\n\n## Jetpack Compose support\n\nNext to the core implementation we also support Jetpack compose:\n\n```kotlin\n@Composable\nfun RenderText(textRef: TextRef, nullableTextRef: TextRef?) {\n    Text(text = textRef(textRef))\n    textRefOrNull(nullableTextRef)?.let { Text(text = it) }\n}\n```\n\n## Download\n\nTextRef is hosted on Maven Central. Here's how you include it in your gradle project:\n\n**Step 1.** Add the Maven Central repository to your `build.gradle[.kts]`:\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\n```\n\n\u003cdetails\u003e\n    \u003csummary\u003eFor the snapshot version:\u003c/summary\u003e\n\n```kotlin\nrepositories {\n    maven(url = \"https://s01.oss.sonatype.org/content/repositories/snapshots\")\n}\n```\n\u003c/details\u003e\n\n**Step 2.** Add the dependency:\n\n```kotlin\ndependencies {\n    implementation(\"com.ioki.textref:textref:\u003clatest-version\u003e\")\n}\n```\n\n**Step 2.1.** Add the optional **Jetpack compose** dependency:\n\n```kotlin\ndependencies {\n    implementation(\"com.ioki.textref:compose:\u003clatest-version\u003e\")\n}\n```\n\n## Releasing\n\n**Step 1.** Make sure you are on the `main` branch.\n\n**Step 2.** Add the changes to the top of [CHANGELOG.md](CHANGELOG.md)\n\n**Step 3.** Update the version in [`build.gradle.kts`](build.gradle.kts)\n\n**Step 4.** Commit\n\n```bash\ngit commit -m \"Prepare next release\" .\n```\n\n**Step 5.** Create a git tag with the version of the CHANGELOG and push the tag\n\n```\ngit tag x.y.z\ngit push origin x.y.z\n```\n\n**Step 6.** Update the version [`build.gradle.kts`](build.gradle.kts) to the **next minor version** +`-SNAPSHOT`\n\n**Step 7.** Commit and push the `main` branch\n\n```bash\ngit push origin main\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioki-mobility%2FTextRef","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fioki-mobility%2FTextRef","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioki-mobility%2FTextRef/lists"}