Skip to content

Commit

Permalink
Cleaned up the addLanguage function
Browse files Browse the repository at this point in the history
  • Loading branch information
heff committed May 20, 2015
1 parent cba48a9 commit 2a1d13f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import log from './utils/log.js';
import * as Dom from './utils/dom.js';
import * as browser from './utils/browser.js';
import extendsFn from './extends.js';
import merge from 'lodash.merge';

// Include the built-in techs
import Html5 from './tech/html5.js';
Expand Down Expand Up @@ -307,15 +308,11 @@ videojs.plugin = plugin;
*
* @param {String} code The language code or dictionary property
* @param {Object} data The data values to be translated
* @return {Object} The resulting global languages dictionary object
*
* @return {Object} The resulting language dictionary object
*/
videojs.addLanguage = function(code, data){
if(globalOptions['languages'][code] !== undefined) {
globalOptions['languages'][code] = mergeOptions(globalOptions['languages'][code], data);
} else {
globalOptions['languages'][code] = data;
}
return globalOptions['languages'];
return merge(globalOptions.languages, { [code]: data })[code];
};

// REMOVING: We probably should add this to the migration plugin
Expand Down
6 changes: 3 additions & 3 deletions test/unit/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ test('should add the value to the languages object', function() {
data = {'Hello': 'Hola'};
result = videojs.addLanguage(code, data);

ok(globalOptions['languages'][code], 'should exist');
equal(globalOptions['languages']['es']['Hello'], 'Hola', 'should match');
deepEqual(result[code]['Hello'], globalOptions['languages']['es']['Hello'], 'should also match');
ok(globalOptions.languages[code], 'should exist');
equal(globalOptions.languages['es']['Hello'], 'Hola', 'should match');
deepEqual(result['Hello'], globalOptions.languages['es']['Hello'], 'should also match');
});


Expand Down

0 comments on commit 2a1d13f

Please sign in to comment.