-
Notifications
You must be signed in to change notification settings - Fork 126
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
Support for plurals #2
Comments
We use separate string resources for those cases, and have done since before Phrase. "Beer" or "Beers" would be baked into the resource string, not substituted in by Phrase. This makes life easy for translators and only adds a simple conditional or switch statement for developers. Generally we have at most four cases: none, one, some, and all.
It's rare to have to do this at all, and extremely rare to have all four cases. Grepping our strings.xml, which contains nearly 800 string resources, shows maybe ten cases where we had to have multiple versions of a string to support different cardinalities. |
I see. The reason I'm asking is because some (actually many) languages have more difficult rules for pluralization (see http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html) and those rules unfortunately can't be expressed with a simple |
Right, that's exactly why we bake the nouns into the template and just have our translators handle it. Developers add the English default string and our translators do the rest. We use Shuttle to manage the process. We avoid trying to generate natural-language strings that embed improper nouns from user input, in part so that we don't have to attempt to pluralize those nouns. |
I implemented an easy possible solutions in #3. Let me know what you think. |
I'd like to reopen plurals for discussion. If base your strings on English you might not cover all the pluralization cases needed by translators. In English there is no distinction between "1 beer" and "2 beers", but apparently there is a difference in Welsh. There's a bunch of examples of of this problem in the Android docs: http://developer.android.com/guide/topics/resources/string-resource.html#Plurals |
Thanks, @dlew. The discussion isn't closed, and @Turbo87's PR #3 is still open. At this point I'm sold on supporting pluralization. We just need to get the API right. There are some other breaking API changes I'd like to make as well, and I think it makes sense to bundle them into a single release. Just haven't had time to do it yet. |
I wonder if there is a way to layer some Phrase niceties on top of Android's plural support, somehow. There's lots and lots of rules built into android's plurals support, but as folks have found out, it still doesn't do everything we really want. More concretely, I'm thinking Phrase could actually define a plural of its own, with default-language values for zero, one, two, few, many, other that correspond exactly to those keys. Then Phrase could easily switch internally based on those values, maybe overlaying some logic as needed (people love their custom zeroes, for example). Support for native quantity strings may be desirable, or may be confusing, not sure. |
Quick attempt at an API, for example: enum QuantityMode {LANGUAGE, FORCE};
Phrase.forQuantity(resources)
.zero(R.string.beer_none, FORCE) // Even if the language doesn't officially support it, use it.
.one(R.string.beer_one) // we can just overload the builder methods to exclude the other parameter
.two(R.string.beer_two)
.few(R.string.some_beer)
.many(R.string.beer_many)
.quantity(quantity); // And this could put in an implicit putOptional() on "{quantity}", say. @loganj Well, I mean awkward if we mix Android Quantities and Phrase Quantities. The only place where I've seen people longing for a behavior is for zero support across all languages. |
The zero problem. Plurals in English only count "one" and "other" even if you might want a different phrasing for a particular case. ...Dang it pforhan. I'm posting anyways. :P |
FWIW, this is a pretty old issue, but: I don't know that Phrase needs to change to accomodate plurals. I'm doing this by just using plurals in the xml:
And then:
If you didn't want to necessarily have the |
That's a really good point, one that I hadn't considered before! I've ended up using |
Yeah, that's definitely sufficient and none of the other options have been compelling. I could be convinced that a |
How about this for a convincing argument: I'll make a PR, then you won't have to do the work. ;) Though it'd actually have to be |
Did #21 ever get released? |
not yet, I need to get the build working again, #40 for an attempt. But I have to work on it again, or alternately we should move to actions |
and we should get #24 in before a release as well |
How do you handle "1 Beer" vs "3 Beers" with this library? Is there any special code for that or is something like that planned?
The text was updated successfully, but these errors were encountered: