- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.1k
Translate quality badges and quality names #988
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smart! I like it. 👍
How about making the array reduce a method in utils.js like getIn or getDeep?
It could actually be used internally in Plyr to avoid code like x && x.y && x.y.z, since it's pretty much a simplified variant of lodash's get https://lodash.com/docs#get which is used for this purpose.
Regardless of the application of it, I would make sure it returns undefined (not {}) when it doesn't match though, and also use more readable variable names (like obj and key). Since i isn't an iterator, it's actually a misnomer.
Like I said last time, Sam's the maintainer and has the final word.
| Thanks for the feedback. I will move it to the utils.js file and change the variable names of course. It actually returns  | 
| I changed the base branch to  | 
| Thank's for the review. For some reason the  | 
| 
 That's the problem though. And very easy to fix: function getDeep1(path, object) {
    return path.split('.').reduce((obj, key) => obj[key] || {}, object);
}
function getDeep2(path, object) {
    return path.split('.').reduce((obj, key) => (obj && obj[key]), object);
}
console.log('Test 1', getDeep1('a.b.c', {a: {b: {c: 'd'}}})); // 'd'
console.log('Test 2', getDeep2('a.b.c', {a: {b: {c: 'd'}}})); // also 'd'
console.log('Test 3', getDeep1('a.b.c', {})); // {}
console.log('Test 4', getDeep2('a.b.c', {})); // undefined | 
| You can remove commits, combine etc with an interactive rebase (ex  | 
| // Get a nested value in an object | ||
| getDeep(object, path) { | ||
| return path.split('.').reduce((obj, key) => (obj && obj[key]) || undefined, object); | ||
| return path.split('.').reduce((obj, key) => obj && obj[key], object); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha.. my bad! I caught this and edited right after posting it, but you were faster.
| @sampotts What do you think about this changes? | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good. Just a very minor change to please my OCD! 😂
        
          
                src/js/controls.js
              
                Outdated
          
        
      | case 'quality': | ||
| if (utils.is.number(value)) { | ||
| return `${value}p`; | ||
| const qualityName = i18n.get(`qualityName.${value}`, this.config); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small one but could we call the variable label and maybe the property for i18n as qualityLabel?
| Sure! I've renamed the variable 😄 | 
| Thanks mate! Awesome solution btw. I'll deploy a new version shortly. I just need to work on a small UI bug I've noticed. | 
Translate quality badges and quality names
Sumary of proposed changes
This is my second approach to #878.
I have extended i18n to allow nested translations with the dot notation. So you can call
i18n.t('qualityName.720', this.config). And with this change I added the ability to translate the badge and the quality name.Result:

… another way to solve this issue would be to add a
labelto the<source>elements. That would be the same approach ascaptionsis currently using. But this seems like a complicated change to me.