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

Update: Improve subtitle selection algorithm #129

Merged
merged 2 commits into from
May 23, 2017
Merged

Update: Improve subtitle selection algorithm #129

merged 2 commits into from
May 23, 2017

Conversation

bhh1988
Copy link
Contributor

@bhh1988 bhh1988 commented May 20, 2017

When selecting subtitles from scratch (toggle-on button) we were
previously selecting the first subtitle in the list. Instead, in this
commit we will go by the user's locale - if the user's language isn't
available, we fall back to English, and if English isn't available, we
fall back to the first language in the subtitles menu. This is similar
to what YouTube does.

@@ -511,34 +512,57 @@ class Settings extends EventEmitter {
}

/**
* Returns whether subtitles are available or not
Copy link
Contributor

Choose a reason for hiding this comment

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

@return {boolean} Are subtitles available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the type info. But "Are subtitles available" is self-explanatory. I guarantee you no one's going to be ambiguous about that one. Looks like we don't have a convention of always having a description for the return statements anyway.

this.toggleToSubtitle = 0; // An index into the subtitles track list. Initialize with the first subtitle in list
this.subtitles = [];
this.locale = undefined;
this.toggleToSubtitle = undefined; // An index into the subtitles list. Initialize with sentinel value
Copy link
Contributor

@tonyjin tonyjin May 22, 2017

Choose a reason for hiding this comment

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

@JustinHoldstock suggested that we start documenting all of the properties of a class at the top of the function. That way we know all of them beforehand and can document what they are for and don't have ones declared dynamically that a dev would need to search around for the definition of.

The syntax is:

class Foo {
    /**
     * Whether settings are open or not
     *
     * @property {boolean}
     */
    visible;

    /**
     * Array of supported subtitles 
     *
     * @property {Array}
     */
    subtitles;
    ...
    constructor() { }

FYI @pramodsum @JustinHoldstock @jeremypress ^

We already do this in the UI Kits and it's enforced through Flow. I can't find a comparable ESLint rule that would enforce the same (I'm not sure if there is one?) - if you could investigate @JustinHoldstock that'd be great, thanks!

We already do this in Preview.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do this in a separate commit afterwards. This helped me find a bug btw - this.locale should actually be this.language.

this.chooseOption('subtitles', this.toggleToSubtitle.toString());
} else { // Do some intelligent selection: Prefer user's language if exists, then fallback to English, then fallback to first subtitle in list
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to turn on prettier, which some other teams are using to automatically format code.

let idx = [].findIndex.call(this.subtitles, (subtitle) => subtitle === this.language);
if (idx === -1) {
// Fall back to English if user's language doesn't exist
idx = [].findIndex.call(this.subtitles, (subtitle) => subtitle === 'English');
Copy link
Contributor

Choose a reason for hiding this comment

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

this.subtitles.findIndex, findIndex is polyfilled in polyfill.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

When selecting subtitles from scratch (toggle-on button) we were
previously selecting the first subtitle in the list. Instead, in this
commit we will go by the user's locale - if the user's language isn't
available, we fall back to English, and if English isn't available, we
fall back to the first language in the subtitles menu. This is similar
to what YouTube does.
@bhh1988 bhh1988 merged commit 561cb73 into box:master May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants