Browse Source

Localize deviceManager

pull/2385/head
Artur Arseniev 7 years ago
parent
commit
23ce3c8d3d
  1. 4
      src/device_manager/config/config.js
  2. 29
      src/device_manager/index.js
  3. 24
      src/device_manager/view/DevicesView.js
  4. 4
      src/editor/config/config.js
  5. 13
      src/i18n/locale/en.js
  6. 10
      src/i18n/locale/tr.js

4
src/device_manager/config/config.js

@ -1,5 +1,3 @@
export default { export default {
devices: [], devices: []
deviceLabel: 'Device'
}; };

29
src/device_manager/index.js

@ -58,7 +58,8 @@ export default () => {
if (!(name in c)) c[name] = defaults[name]; if (!(name in c)) c[name] = defaults[name];
} }
devices = new Devices(c.devices); devices = new Devices();
(c.devices || []).forEach(dv => this.add(dv.id || dv.name, dv.width, dv));
view = new DevicesView({ view = new DevicesView({
collection: devices, collection: devices,
config: c config: c
@ -68,21 +69,27 @@ export default () => {
/** /**
* Add new device to the collection. URLs are supposed to be unique * Add new device to the collection. URLs are supposed to be unique
* @param {string} name Device name * @param {String} id Device id
* @param {string} width Width of the device * @param {String} width Width of the device
* @param {Object} opts Custom options * @param {Object} [opts] Custom options
* @return {Device} Added device * @returns {Device} Added device
* @example * @example
* deviceManager.add('Tablet', '900px'); * deviceManager.add('tablet', '900px');
* deviceManager.add('Tablet2', '900px', { * deviceManager.add('tablet2', '900px', {
* height: '300px', * height: '300px',
* // At first, GrapesJS tries to localize the name by device id.
* // In case is not found, the `name` property is used (or `id` if name is missing)
* name: 'Tablet 2',
* widthMedia: '810px', // the width that will be used for the CSS media * widthMedia: '810px', // the width that will be used for the CSS media
* }); * });
*/ */
add(name, width, opts) { add(id, width, opts = {}) {
var obj = opts || {}; const obj = {
obj.name = name; ...opts,
obj.width = width; id,
name: opts.name || id,
width: width
};
return devices.add(obj); return devices.add(obj);
}, },

24
src/device_manager/view/DevicesView.js

@ -67,25 +67,29 @@ export default Backbone.View.extend({
* @private * @private
*/ */
getOptions() { getOptions() {
var result = ''; const { collection, em } = this;
this.collection.each(device => { let result = '';
var name = device.get('name');
result += '<option value="' + name + '">' + name + '</option>'; collection.each(device => {
const { name, id } = device.attributes;
const label = em.t(`deviceManager.devices.${id}`) || name;
result += `<option value="${name}">${label}</option>`;
}); });
return result; return result;
}, },
render() { render() {
var pfx = this.ppfx; const { em, ppfx, $el, el } = this;
this.$el.html( $el.html(
this.template({ this.template({
ppfx: pfx, ppfx,
deviceLabel: this.config.deviceLabel deviceLabel: em.t('deviceManager.device')
}) })
); );
this.devicesEl = this.$el.find('.' + pfx + 'devices'); this.devicesEl = $el.find(`.${ppfx}devices`);
this.devicesEl.append(this.getOptions()); this.devicesEl.append(this.getOptions());
this.el.className = pfx + 'devices-c'; el.className = `${ppfx}devices-c`;
return this; return this;
} }
}); });

4
src/editor/config/config.js

@ -194,20 +194,24 @@ export default {
deviceManager: { deviceManager: {
devices: [ devices: [
{ {
id: 'desktop',
name: 'Desktop', name: 'Desktop',
width: '' width: ''
}, },
{ {
id: 'tablet',
name: 'Tablet', name: 'Tablet',
width: '768px', width: '768px',
widthMedia: '992px' widthMedia: '992px'
}, },
{ {
id: 'mobileLandscape',
name: 'Mobile landscape', name: 'Mobile landscape',
width: '568px', width: '568px',
widthMedia: '768px' widthMedia: '768px'
}, },
{ {
id: 'mobilePortrait',
name: 'Mobile portrait', name: 'Mobile portrait',
width: '320px', width: '320px',
widthMedia: '480px' widthMedia: '480px'

13
src/i18n/locale/en.js

@ -6,7 +6,18 @@ export default {
uploadTitle: 'Drop files here or click to upload' uploadTitle: 'Drop files here or click to upload'
}, },
blocks: { blocks: {
labels: {}, labels: {
// 'block-id': 'Block Label',
},
categories: {} categories: {}
},
deviceManager: {
device: 'Device',
devices: {
desktop: 'Desktop',
tablet: 'Tablet',
mobileLandscape: 'Mobile Landscape',
mobilePortrait: 'Mobile Portrait'
}
} }
}; };

10
src/i18n/locale/tr.js

@ -6,10 +6,12 @@ export default {
}, },
deviceManager: { deviceManager: {
device: 'Cihaz', device: 'Cihaz',
desktop: 'Masaüstü', devices: {
tablet: 'Tablet', desktop: 'Masaüstü',
mobileLandscape: 'Mobil Yatay', tablet: 'Tablet',
mobilePortrait: 'Mobil Dikey' mobileLandscape: 'Mobil Yatay',
mobilePortrait: 'Mobil Dikey'
}
}, },
styleManager: { styleManager: {
noEl: 'Stilini düzenlemek istediğiniz öğeyi seçiniz', noEl: 'Stilini düzenlemek istediğiniz öğeyi seçiniz',

Loading…
Cancel
Save