Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 863191 - Add l10nId to the elements
Browse files Browse the repository at this point in the history
  • Loading branch information
crh0716 committed May 21, 2013
1 parent e99e62c commit a46954a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 34 deletions.
63 changes: 29 additions & 34 deletions apps/settings/js/connectivity.js
Expand Up @@ -69,15 +69,15 @@ var Connectivity = (function(window, document, undefined) {
}
_initialized = true;

kCardState = {
'pinRequired' : _('simCardLockedMsg'),
'pukRequired' : _('simCardLockedMsg'),
'networkLocked' : _('simLockedPhone'),
'serviceProviderLocked' : _('simLockedPhone'),
'corporateLocked' : _('simLockedPhone'),
'unknown' : _('unknownSimCardState'),
'absent' : _('noSimCard'),
'null' : _('simCardNotReady')
kCardStateL10nId = {
'pinRequired' : 'simCardLockedMsg',
'pukRequired' : 'simCardLockedMsg',
'networkLocked' : 'simLockedPhone',
'serviceProviderLocked' : 'simLockedPhone',
'corporateLocked' : 'simLockedPhone',
'unknown' : 'unknownSimCardState',
'absent' : 'noSimCard',
'null' : 'simCardNotReady'
};

updateCarrier();
Expand All @@ -86,11 +86,6 @@ var Connectivity = (function(window, document, undefined) {
updateBluetooth();
// register blutooth system message handler
initSystemMessageHandler();

window.addEventListener('localized', function() {
updateWifi();
updateBluetooth();
});
}

/**
Expand All @@ -108,12 +103,11 @@ var Connectivity = (function(window, document, undefined) {
if (wifiManager.enabled) {
// network.connection.status has one of the following values:
// connecting, associated, connected, connectingfailed, disconnected.
wifiDesc.textContent = _('fullStatus-' +
wifiManager.connection.status,
wifiManager.connection.network);
localize(wifiDesc,
'fullStatus-' + wifiManager.connection.status,
wifiManager.connection.network);
} else {
wifiDesc.textContent = _('disabled');
wifiDesc.dataset.l10nId = 'disabled';
localize(wifiDesc, 'disabled');
}

// record the MAC address here because the "Device Information" panel
Expand Down Expand Up @@ -145,7 +139,7 @@ var Connectivity = (function(window, document, undefined) {
* Mobile Connection Manager
*/

var kCardState; // see init()
var kCardStateL10nId; // see init()
var kDataType = {
'lte' : '4G LTE',
'ehrpd': 'CDMA',
Expand Down Expand Up @@ -179,6 +173,7 @@ var Connectivity = (function(window, document, undefined) {
var text = msg.error ||
((data && operator) ? (operator + ' - ' + data) : operator);
dataDesc.textContent = text;
dataDesc.dataset.l10nId = msg.l10nId || '';

/**
* XXX italic style for specifying state change is not a ideal solution
Expand All @@ -201,11 +196,11 @@ var Connectivity = (function(window, document, undefined) {
return setCarrierStatus({});

// ensure the SIM card is present and unlocked
var cardState = kCardState[mobileConnection.cardState ?
mobileConnection.cardState :
'null'];
if (cardState)
return setCarrierStatus({ error: cardState });
var cardState = mobileConnection.cardState || 'null';
var l10nId = kCardStateL10nId[cardState];
if (l10nId) {
return setCarrierStatus({ error: _(l10nId), l10nId: l10nId });
}

// operator name & data connection type
if (!mobileConnection.data || !mobileConnection.data.network)
Expand Down Expand Up @@ -242,8 +237,8 @@ var Connectivity = (function(window, document, undefined) {
return;

// update the current SIM card state
var cardState = mobileConnection.cardState;
callDesc.textContent = kCardState[cardState] || '';
var cardState = mobileConnection.cardState || 'null';
localize(callDesc, kCardStateL10nId[cardState]);
}

/**
Expand All @@ -258,8 +253,10 @@ var Connectivity = (function(window, document, undefined) {
init();
return; // init will call updateBluetooth()
}
bluetoothDesc.textContent = bluetooth.enabled ?
_('bt-status-nopaired') : _('bt-status-turnoff');

var l10nId = bluetooth.enabled ? 'bt-status-nopaired' : 'bt-status-turnoff';
localize(bluetoothDesc, l10nId);

if (!bluetooth.enabled) {
return;
}
Expand All @@ -277,11 +274,9 @@ var Connectivity = (function(window, document, undefined) {
paired.sort(function(a, b) {
return a.name > b.name;
});
var text = _('bt-status-paired', {
name: paired[0].name,
n: length - 1
});
bluetoothDesc.textContent = text;

localize(bluetoothDesc, 'bt-status-paired',
{ name: paired[0].name, n: length - 1 });
};
};
}
Expand Down
27 changes: 27 additions & 0 deletions apps/settings/js/utils.js
Expand Up @@ -107,6 +107,33 @@ function audioPreview(element, type) {
}
}

/**
* L10n helper
*/

function localize(element, id, args) {
var mozL10n = navigator.mozL10n;
if (!element || !mozL10n)
return;

if (id) {
element.dataset.l10nId = id;
} else {
element.dataset.l10nId = '';
element.textContent = '';
}

if (args) {
element.dataset.l10nArgs = JSON.stringify(args);
} else {
element.dataset.l10nArgs = '';
}

mozL10n.ready(function l10nReady() {
mozL10n.translate(element);
});
}

/**
* Helper class for formatting file size strings
* required by *_storage.js
Expand Down

0 comments on commit a46954a

Please sign in to comment.