Skip to content

Commit

Permalink
End i18n work of OSD statistics (betaflight#1512)
Browse files Browse the repository at this point in the history
End i18n work of OSD statistics
  • Loading branch information
mikeller authored Jul 1, 2019
2 parents 8895405 + 647859e commit c167f48
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
9 changes: 9 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4424,12 +4424,21 @@
"osdDescStatTotalFlightDistance": {
"message": "Total distance traveled"
},
"osdTextStatMinRssiDbm": {
"message": "RSSI dBm minimum",
"description": "One of the statistics that can be shown at the end of the flight in the OSD"
},
"osdDescStatMinRssiDbm": {
"message": "Minimum RSSI dBm value"
},
"osdTextStatUnknown": {
"message": "Unknown $1",
"description": "One of the statistics that can be shown at the end of the flight in the OSD"
},
"osdDescStatUnknown": {
"message": "Unknown statistic (details to be added in a future release)"
},

"osdDescribeFontVersion1": {
"message": "Font version: 1 (Betaflight 4.0 or older)"
},
Expand Down
41 changes: 21 additions & 20 deletions src/js/tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ OSD.constants = {
},
MIN_RSSI_DBM: {
name: 'MIN_RSSI_DBM',
text: 'osdTextStatMinRssiDbm',
desc: 'osdDescStatMinRssiDbm'
},
},
Expand Down Expand Up @@ -1842,7 +1843,8 @@ OSD.msp = {

// Read all the data for any statistics we don't know about
} else {
d.stat_items.push({name: 'UNKNOWN', desc: 'osdDescStatUnknown', index: i, enabled: v === 1 });
let statisticNumber = i - OSD.constants.STATISTIC_FIELDS.length + 1;
d.stat_items.push({name: 'UNKNOWN', text: ['osdTextStatUnknown', statisticNumber], desc: 'osdDescStatUnknown', index: i, enabled: v === 1 });
}
}

Expand Down Expand Up @@ -2114,16 +2116,20 @@ TABS.osd.initialize = function (callback) {
}

function insertOrdered(fieldList, field) {
let added = false;
fieldList.children().each(function() {
if ($(this).text().localeCompare(field.text(), i18n.getCurrentLocale(), { sensitivity: 'base' }) > 0) {
$(this).before(field);
added = true;
return false;
}
});
if(!added) {
if (field.name == 'UNKNOWN') {
fieldList.append(field);
} else {
let added = false;
fieldList.children().each(function() {
if ($(this).text().localeCompare(field.text(), i18n.getCurrentLocale(), { sensitivity: 'base' }) > 0) {
$(this).before(field);
added = true;
return false;
}
});
if(!added) {
fieldList.append(field);
}
}
}

Expand Down Expand Up @@ -2311,6 +2317,7 @@ TABS.osd.initialize = function (callback) {
);
$field.append('<label for="' + field.name + '" class="char-label">' + titleizeField(field) + '</label>');

// Insert in alphabetical order, with unknown fields at the end
insertOrdered($statsFields, $field);
}

Expand Down Expand Up @@ -2348,11 +2355,8 @@ TABS.osd.initialize = function (callback) {
$field.append('<label for="' + field.name + '" class="char-label">' + finalFieldName + '</label>');

// Insert in alphabetical order, with unknown fields at the end
if (field.name == 'UNKNOWN') {
$warningFields.append($field);
} else {
insertOrdered($warningFields, $field);
}
insertOrdered($warningFields, $field);

}
}
}
Expand Down Expand Up @@ -2482,11 +2486,8 @@ TABS.osd.initialize = function (callback) {
}

// Insert in alphabetical order, with unknown fields at the end
if (field.name == OSD.constants.UNKNOWN_DISPLAY_FIELD.name) {
$displayFields.append($field);
} else {
insertOrdered($displayFields, $field);
}
insertOrdered($displayFields, $field);

}

GUI.switchery();
Expand Down

0 comments on commit c167f48

Please sign in to comment.