git-machete-intellij-plugin icon indicating copy to clipboard operation
git-machete-intellij-plugin copied to clipboard

Consider using {<param-pos>,choice,<#n-cases>} in the bundle

Open mkondratek opened this issue 3 years ago • 6 comments

I found the following property:

rebase.notification.successful.rebased.checkout.message=Checked out{0,choice,0#|1# {1}} and rebased it{2,choice,0#|1# on {3}}

and here is its usage:

if (withCheckout) {
  return GitBundle.message(
    "rebase.notification.successful.rebased.checkout.message",
    convertBooleanToInt(currentBranch != null), currentBranch,
    convertBooleanToInt(baseBranch != null), baseBranch);
}

And another example to better understand how it works (as there is no documentation for it Xd):

branch.worker.could.not.create.tag=Couldn''t create tag {0}{1,choice,0#|1#|2# in {2}}
String error = GitBundle.message("branch.worker.could.not.create.tag",
                                 name,
                                 GitUtil.getRepositoryManager(repository.getProject()).getRepositories().size(),
                                 getShortRepositoryName(repository));

Action points:

  • [x] when this functionality has been introduced? can we safely use it (in the scope of backward compatibility)?
  • [ ] if we can use it; do we have use cases for it?
  • [ ] if we do have them; apply it to our bundle

mkondratek avatar Sep 22 '22 08:09 mkondratek

And question number ~one~ zero, WTF it even does? 😯 as in, what's the syntax/semantics of these expressions... from a quick look it seems to be some if-then-else (?)

PawelLipski avatar Sep 22 '22 08:09 PawelLipski

Yup, it is if (else if) else

  1. First is the index of param - length/size/etc (some int)
  2. Then "choice" keyword
  3. Options separated with |, e.g. 0# is applied when the param value is equal to 0, 1# if it equals to 1, etc

I assume that last case works like else (so all not met before values go for it)

mkondratek avatar Sep 22 '22 08:09 mkondratek

Looking at a source code, this feature is provided by java.text.MessageFormat from Java 1.1 and has been implemented in IntelliJ from at least 2012

MarconZet avatar Oct 13 '22 15:10 MarconZet

One more thing: whether https://checkerframework.org/dev/api/org/checkerframework/checker/i18nformatter/I18nFormatterChecker.html that we heavily rely on even supports it

PawelLipski avatar Oct 13 '22 16:10 PawelLipski

It works very well. Not only does it detect the number of arguments, but also the type (the switching argument must be a number)

MarconZet avatar Oct 14 '22 14:10 MarconZet

Looking though the tutorials, this feature is mostly used when dealing with numbers, example being: We have {0, choice, 0#no messages|1#a message|2#two messages|2<{2, number, integer} messages} for you

MarconZet avatar Oct 14 '22 14:10 MarconZet

Probably not worth pursuing, closing

PawelLipski avatar Feb 20 '23 18:02 PawelLipski