-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Need way for strings to specify multiple plurals #5007
Comments
See #4856 for some discussion about this. |
FYI, here's a link that discusses all the different languages and the kinds of plural rules. I had no idea there were so many varieties: https://developer.mozilla.org/en-US/docs/Localization_and_Plurals |
@njx, I have been looking at this issue today. Wanted to get your input on some ideas. The main part is creating a function that takes a number, a language code, and a delimited list of strings and returns the correct plural string that matches to the number. For example:
The function determines which string to select by comparing the number to a set of conditions. The language code determines which set of conditions to apply. The conditions are presented in this list of language-specific Plural Rules: https://developer.mozilla.org/en-US/docs/Localization_and_Plurals#List_of_Plural_Rules We will also have to have a heuristic that recognizes a certain key name formatting in strings.js. Maybe the key name has the string The toughest part is the translators are going to have to be familiar with the Plural Rules so they put the delimited strings in the correct order. This is fairly simple for some languages, less so for others. So, that's my idea, how does it sound to you? |
Wow. Good research! I'm not totally sure I follow how this would work in cases where the item that needs to be pluralized is actually part of a larger string that might have other substitutions. It sounds like the heuristic you mentioned is intended to play a part in that, but I can't quite see how it would work. Could you give a worked-out example of how this would all fit together? |
Upon reflection, it probably doesn't need a heuristic. Just a standard way of naming the constant names so developers know that a _PLURALS string constant is actually a delimited string of plural text fragments. A typical scenario might look like this: The String constants defined in strings.js // Assuming you get these values from other parts of the program...
var fileCount = 25,
language = "en",
dirName = "foobar",
pluralString = "",
finalString = "";
pluralString = StringUtils.formatPlural(fileCount, language, Strings.SELECT_FILE_COUNT_PLURALS);
finalString = StringUtils.format(Strings.SELECT_FILE_COUNT, pluralString, dirName); |
@njx, assuming this plan looks good to you, I am going to start working on the pull request this week. Let me know if you have any other concerns or questions. Assigning to myself. |
I have noticed that on http://angularjs.org/ there's an actual sample of this in Localization, might be worth checking out the code. |
Makes sense to me. But one random thought before you go down this path--is it possible that there's already some little open source JS lib that does this? It seems like the kind of thing that someone might already have built. Might be worth looking around briefly to see if there's something you could leverage before writing it from scratch. |
By the way, I'm really digging that Plural Rule 16. |
Oh, minor API comment: seems like the argument order should be consistent with |
A month ago I saw this presentation from Alex Sexton in JSConf EU about Internalization which was great: https://www.youtube.com/watch?v=uXS_-JRsB8M and he showed some of his tools https://github.com/jedtoolkit. |
@TomMalbran, thanks for the link, it's really good. Makes me realize this problem may be more complex than our current situation suggests. I don't think my proposed solution scales very well if our translated messages become more involved than just a single plural string fragment. @njx, another problem occurs to me. How would these changes integrate with the existing internalization support that Adobe already provides? These changes would affect both Adobe and community translators. Also, has the internalization team found solutions to this problem? Anything we could reuse? I'm removing the "fix in progress" label on this issue for now. I need to spend more time in research, taking a look at this jedtoolkit solution. |
Good questions. @ybayer, do you have any thoughts on this issue? I agree that we might not want to move forward with this right now...it seems complex and maybe not the highest-priority thing to work on. |
@ybayer We don't have a solution for this but someone on our team was looking into JS i18n libraries. I will get back to you on this. |
Assigning back to @njx as it doesn't look like I am going to be working on a solution presently. |
OK--thanks for doing all that research; it was really valuable. |
In some languages like Slovak, there are different plurals for different numbers (e.g. 2 and 5). We don't have a way to deal with this in the strings file right now. We could invent some kind of substitution syntax that specifies the plurals for different numbers/ranges.
The text was updated successfully, but these errors were encountered: