Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about strings without parameters? #256

Open
Raenar4k opened this issue Oct 31, 2023 · 2 comments
Open

What about strings without parameters? #256

Raenar4k opened this issue Oct 31, 2023 · 2 comments

Comments

@Raenar4k
Copy link

As far as i understand Paraphrase aims to generate these methods for strings that use ICU message format.
But what about simple strings without any arguments?

My use-case is that we used a string without arguments, that later was changed to have 1 argument.
But if we use R.strings for these cases, then we cannot detect such change.
Reverse is possible to detect, thanks to Paraphrase.

  <string name="test_string">Bagels are tasty</string>
  <string name="test_argument">bagel count: {0}</string>
  <string name="test_plural">{count, plural, one {# tasty bagel} other {# tasty bagels}}
image
@JakeWharton
Copy link
Collaborator

Seems a like pretty compelling argument

@theisenp
Copy link
Collaborator

theisenp commented Nov 2, 2023

Great question!

We could start generating accessors for string resources without arguments. Something like:

object FormattedResources {
  @StringRes val test_string: Int = R.string.test_string
  fun test_argument(arg0: Any): StringResource = ...
  fun test_plural(count: Number): StringResource = ...
}

Then if we added an argument, the val would turn into a fun and we would get a compile error.

I suspect that in most Android projects, a majority of the string resources will have no arguments. So it might be a little weird to access everything through a class called FormattedResources. But maybe not? Or maybe we could rename it StringResources?

Another option would be something like a lint rule that warns us if we make a getString call with missing arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants