1 // ==========================================================================
  2 // Project:   The M-Project - Mobile HTML5 Application Framework
  3 // Copyright: (c) 2011 M-Way Solutions GmbH. All rights reserved.
  4 //            (c) 2011 panacoda GmbH. All rights reserved.
  5 // Creator:   Dominik
  6 // Date:      03.05.2011
  7 // License:   Dual licensed under the MIT or GPL Version 2 licenses.
  8 //            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
  9 //            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
 10 // ==========================================================================
 11 
 12 m_require('core/foundation/object.js');
 13 
 14 /**
 15  * @class
 16  *
 17  * M.DeviceSwitch defines a prototype for using device specific objects within
 18  * an application developed with The M-Project.
 19  *
 20  * @extends M.Object
 21  */
 22 M.DeviceSwitch = M.Object.extend(
 23 /** @scope M.DeviceSwitch.prototype */ {
 24 
 25     /**
 26      * The type of this object.
 27      *
 28      * @type String
 29      */
 30     type: 'M.DeviceSwitch',
 31 
 32     /**
 33      * The name of the current device.
 34      *
 35      * @type String
 36      */
 37     device: null,
 38 
 39     /**
 40      * This method returns the specialized string for the given key based on
 41      * the current device/environment.
 42      *
 43      * @param {String} key The key to the specialized string.
 44      * @returns {String} The specialized string based on the current device/environment.
 45      */
 46     s: function(key) {
 47         return this.specialize(key);
 48     },
 49 
 50     /**
 51      * This method returns the localized string for the given key based on
 52      * the current language. It is internally used as a wrapper for l() for
 53      * a better readability.
 54      *
 55      * @private
 56      * @param {String} key The key to the localized string.
 57      * @returns {String} The localizes string based on the current application language.
 58      */
 59     specialize: function(key) {
 60         if(!this.device) {
 61             M.Logger.log('No device specified!', M.ERR);
 62             return null;
 63         }
 64 
 65         if(this[this.device] && this[this.device][key]) {
 66             return this[this.device][key];
 67         } else {
 68             M.Logger.log('Key \'' + key + '\' not defined for device \'' + this.device + '\'.', M.WARN);
 69             return null;
 70         }
 71     }
 72 
 73 });
 74 
 75 M.DS = M.DeviceSwitch;