Skip to content
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

feat: allow tokens in localize, localize progress bar time #4060

Merged
merged 7 commits into from
Feb 21, 2017

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Feb 10, 2017

Fix #4024.

@gkatsev gkatsev added the a11y This item might affect the accessibility of the player label Feb 10, 2017
@gkatsev gkatsev requested a review from OwenEdwards February 10, 2017 23:44
return primaryLang[string];
if (tokens) {
localizedString = localizedString.replace(/\{(\d+)\}/g, function(match, index) {
return tokens[index - 1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check the validity of index here (is a number, is in-range for tokens[], etc.)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we probably should. Should we just return the match if the index isn't available in tokens[]?
So, if you do this.localize('{1} {2} {3}', ['a', 'b']) you would get a b {3}.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable default behavior. Of course, we're also going to need to clearly document what {1}, {2} etc. are for each string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at this, I realize that the visual display next to the progress bar is actually the remaining time, not the duration of the video. Maybe {3} should be remaining time, so that the text can be customized that way, too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we're also going to need to clearly document what {1}, {2} etc. are for each string

I've been planning to write a glossary explaining every string in en.json. The translations have grown a lot recently and there's a lot in there that's not all that clear out of context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing I can think of to help with this is having the translation string and then default be two different things. So, for this case I can do something like this.localize('progress bar timing', [currentTime, duration], '{1} {2}') and the en.json would have progress bar timing: '{1} {2}'. That way we have a default, that's described, but people who only look at the json would have a better idea about what's happening.
Not quite sure if there's the best approach but a thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To elaborate and update (after some discussion with @OwenEdwards).
The key should be progress bar timing: currentTime={1}, duration={2} and the value would be {1} of {2}. That way, as you're reading the JSON files, you have some idea of what the items are.
Then, we would want to add a 3rd argument to localize, a defaults argument, which would be {1} of {2} which is what should be used in the case a language file isn't included (and so we don't have to require en.json to be included).

@OwenEdwards
Copy link
Member

Tested with IE11 + JAWS, and macOS 10.12.3 Safari + VoiceOver; other than the notes I've already made, LGTM

@@ -220,28 +220,35 @@ class Component {
* @return {string}
* The localized string or if no localization exists the english string.
*/
localize(string) {
localize(string, tokens, defaultValue = string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the JSDoc block for this function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually need "defaultValue" as an argument here? Can't we just make a copy of string in the function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we need defaultValue as an argument. The = string just makes the default value of defaultValue to be string. But if a defaultValue is passed in to this function, it is used instead of the value of `string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried explaining it in the jsdoc, can you re-read it and let me know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, makes sense to me. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we just make "{1} of {2}" the string we are localizing here? Seems weird to make the translation key and the value have different wording.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the key in the lang file describes what it should be. If you see {1} of {2} how would you know what is {1} and {2} and also what should you be translating?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm ok LGTM

Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 comment LGTM otherwise

@@ -220,28 +220,35 @@ class Component {
* @return {string}
* The localized string or if no localization exists the english string.
*/
localize(string) {
localize(string, tokens, defaultValue = string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually need "defaultValue" as an argument here? Can't we just make a copy of string in the function

@gkatsev gkatsev merged commit db01120 into master Feb 21, 2017
@gkatsev gkatsev deleted the localize-tokens branch February 21, 2017 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y This item might affect the accessibility of the player confirmed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants