Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Need way for strings to specify multiple plurals #5007

Open
njx opened this issue Aug 30, 2013 · 17 comments
Open

Need way for strings to specify multiple plurals #5007

njx opened this issue Aug 30, 2013 · 17 comments

Comments

@njx
Copy link

njx commented Aug 30, 2013

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.

@ghost ghost assigned njx Aug 30, 2013
@njx
Copy link
Author

njx commented Aug 30, 2013

See #4856 for some discussion about this.

@lkcampbell
Copy link
Contributor

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

@lkcampbell
Copy link
Contributor

@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:

StringUtils.formatPlural(0, "en", "no files;a single file;{0} files") -> "no files"
...as in "You selected no files."

StringUtils.formatPlural(1, "en", "no files;a single file;{0} files") -> "a single file"
...as in "You selected a single file."

StringUtils.formatPlural(25, "en", "no files;one file;{0} files") -> "25 files"
...as in "You selected 25 files."

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 _PLURALS in it, for example: FIND_RESULT_COUNT_PLURALS. Then, we set its value to the semicolon delimited list format presented above.

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?

@njx
Copy link
Author

njx commented Sep 23, 2013

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?

@lkcampbell
Copy link
Contributor

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
"SELECT_FILE_COUNT" : "You selected {0} from directory {1}."
"SELECT_FILE_COUNT_PLURALS" : "no files;one file;{0} files"

// 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);

@lkcampbell
Copy link
Contributor

@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.

@ghost ghost assigned lkcampbell Sep 30, 2013
@zaggino
Copy link
Contributor

zaggino commented Oct 1, 2013

I have noticed that on http://angularjs.org/ there's an actual sample of this in Localization, might be worth checking out the code.

@njx
Copy link
Author

njx commented Oct 1, 2013

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.

@njx
Copy link
Author

njx commented Oct 1, 2013

By the way, I'm really digging that Plural Rule 16.

@njx
Copy link
Author

njx commented Oct 1, 2013

Oh, minor API comment: seems like the argument order should be consistent with formatString, so the key should be the first arg.

@lkcampbell
Copy link
Contributor

@zaggino and @njx, thanks for the suggestions. I will do some more research today and let you know what I discover.

@TomMalbran
Copy link
Contributor

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.

@lkcampbell
Copy link
Contributor

@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.

@njx
Copy link
Author

njx commented Oct 2, 2013

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
Copy link
Contributor

ybayer commented Oct 2, 2013

@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.

@lkcampbell
Copy link
Contributor

Assigning back to @njx as it doesn't look like I am going to be working on a solution presently.

@ghost ghost assigned njx Oct 3, 2013
@njx
Copy link
Author

njx commented Oct 3, 2013

OK--thanks for doing all that research; it was really valuable.

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

No branches or pull requests

5 participants