comahe-de / i18n4k

Internationalization for Kotlin
Apache License 2.0
78 stars 9 forks source link

Select-Pattern #42

Closed comahe-de closed 11 months ago

comahe-de commented 1 year ago

Select a text value based on the value of the parameter.

Format:

{ PARAMETER_NUMBER, select, VALUE1:  TEXT1 | VALUE2 / VALUE3:  TEXT2 | <VALUE_REGEX> : TEXT_REGEX | ? OTHERWISE_TEXT}

Values and texts are trimmed (leading and tailing whitespaces are removed) and must not contain "," , "/", "\", "<", ">" or "|". If these special characters are needed, they can be escaped via backslash "\".

Example:

{0} has forgotten {1, select, female # her | ? his }  {3, select, one # bag | ? {2} bags}.

Usage:

FORGOTTEN_BAG("Peter", "male", 1, "one") 
-> Peter has forgotten his bag.

FORGOTTEN_BAG("Mary", "female", 2, "few")
-> Mary has forgotten her 2 bags.
CodeServant commented 1 year ago

So to be clear the pattern is this new construct in curly braces and not regex pattern as in JAVA or Kotlin.

comahe-de commented 1 year ago

@CodeServant, yes I mean the construct in curly braces.

trentkan commented 11 months ago

While I understand the request, I wonder if it makes sense to complicate the codebase with programmatically figuring out the gender of words, when we could solve the same problem with two entries in the message bundle.

I understand that this feature is confined with braces though, so no issues - just a suggestion.