1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-25 09:15:49 +03:00

i18n the OSD warnings list, ordering it in alphabetical order

This commit is contained in:
Miguel Angel Mulero Martinez 2019-06-15 09:09:35 +02:00
parent 2778cbb1f1
commit 8d714f87a8
2 changed files with 124 additions and 24 deletions

View file

@ -1205,66 +1205,82 @@ OSD.constants = {
ALL_WARNINGS: {
ARMING_DISABLED: {
name: 'ARMING_DISABLED',
text: 'osdWarningTextArmingDisabled',
desc: 'osdWarningArmingDisabled'
},
BATTERY_NOT_FULL: {
name: 'BATTERY_NOT_FULL',
text: 'osdWarningTextBatteryNotFull',
desc: 'osdWarningBatteryNotFull'
},
BATTERY_WARNING: {
name: 'BATTERY_WARNING',
text: 'osdWarningTextBatteryWarning',
desc: 'osdWarningBatteryWarning'
},
BATTERY_CRITICAL: {
name: 'BATTERY_CRITICAL',
text: 'osdWarningTextBatteryCritical',
desc: 'osdWarningBatteryCritical'
},
VISUAL_BEEPER: {
name: 'VISUAL_BEEPER',
text: 'osdWarningTextVisualBeeper',
desc: 'osdWarningVisualBeeper'
},
CRASH_FLIP_MODE: {
name: 'CRASH_FLIP_MODE',
text: 'osdWarningTextCrashFlipMode',
desc: 'osdWarningCrashFlipMode'
},
ESC_FAIL: {
name: 'ESC_FAIL',
text: 'osdWarningTextEscFail',
desc: 'osdWarningEscFail'
},
CORE_TEMPERATURE: {
name: 'CORE_TEMPERATURE',
text: 'osdWarningTextCoreTemperature',
desc: 'osdWarningCoreTemperature'
},
RC_SMOOTHING_FAILURE: {
name: 'RC_SMOOTHING_FAILURE',
text: 'osdWarningTextRcSmoothingFailure',
desc: 'osdWarningRcSmoothingFailure'
},
FAILSAFE: {
name: 'FAILSAFE',
text: 'osdWarningTextFailsafe',
desc: 'osdWarningFailsafe'
},
LAUNCH_CONTROL: {
name: 'LAUNCH_CONTROL',
text: 'osdWarningTextLaunchControl',
desc: 'osdWarningLaunchControl'
},
GPS_RESCUE_UNAVAILABLE: {
name: 'GPS_RESCUE_UNAVAILABLE',
text: 'osdWarningTextGpsRescueUnavailable',
desc: 'osdWarningGpsRescueUnavailable'
},
GPS_RESCUE_DISABLED: {
name: 'GPS_RESCUE_DISABLED',
text: 'osdWarningTextGpsRescueDisabled',
desc: 'osdWarningGpsRescueDisabled'
},
RSSI: {
name: 'RSSI',
text: 'osdWarningTextRSSI',
desc: 'osdWarningRSSI'
},
LINK_QUALITY: {
name: 'LINK_QUALITY',
text: 'osdWarningTextLinkQuality',
desc: 'osdWarningLinkQuality'
},
RSSI_DBM: {
name: 'RSSI_DBM',
text: 'osdWarningTextRssiDbm',
desc: 'osdWarningRssiDbm'
},
@ -1819,7 +1835,7 @@ OSD.msp = {
// Push Unknown Warning field
} else {
var warningNumber = i - OSD.constants.WARNINGS.length + 1;
d.warnings.push({name: 'UNKNOWN_' + warningNumber, desc: 'osdWarningUnknown', enabled: (warningFlags & (1 << i)) != 0 });
d.warnings.push({name: 'UNKNOWN', text: ['osdWarningTextUnknown', warningNumber], desc: 'osdWarningUnknown', enabled: (warningFlags & (1 << i)) != 0 });
}
}
@ -2040,6 +2056,32 @@ TABS.osd.initialize = function (callback) {
$('.stats-container div.cf_tip').attr('title', i18n.getMessage('osdSectionHelpStats'));
$('.warnings-container div.cf_tip').attr('title', i18n.getMessage('osdSectionHelpWarnings'));
function titleizeField(field) {
let finalFieldName = inflection.titleize(field.name);
if (field.text) {
if (Array.isArray(field.text) && i18n.existsMessage(field.text[0])) {
finalFieldName = i18n.getMessage(field.text[0], field.text.slice(1));
} else if (i18n.existsMessage(field.text)) {
finalFieldName = i18n.getMessage(field.text);
}
}
return finalFieldName;
}
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) {
fieldList.append(field);
}
}
// 2 way binding... sorta
function updateOsdView() {
// ask for the OSD config data
@ -2256,9 +2298,16 @@ TABS.osd.initialize = function (callback) {
});
})
);
$field.append('<label for="' + field.name + '" class="char-label">' + inflection.titleize(field.name) + '</label>');
$warningFields.append($field);
let finalFieldName = titleizeField(field);
$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);
}
}
}
}
@ -2367,14 +2416,8 @@ TABS.osd.initialize = function (callback) {
})
);
}
let finalFieldName = inflection.titleize(field.name);
if (field.text) {
if (Array.isArray(field.text) && i18n.existsMessage(field.text[0])) {
finalFieldName = i18n.getMessage(field.text[0], field.text.slice(1));
} else if (i18n.existsMessage(field.text)) {
finalFieldName = i18n.getMessage(field.text);
}
}
let finalFieldName = titleizeField(field);
$field.append('<label for="' + field.name + '" class="char-label">' + finalFieldName + '</label>');
if (field.positionable && field.isVisible[OSD.getCurrentPreviewProfile()]) {
$field.append(
@ -2397,17 +2440,7 @@ TABS.osd.initialize = function (callback) {
if (field.name == OSD.constants.UNKNOWN_DISPLAY_FIELD.name) {
$displayFields.append($field);
} else {
let added = false;
$displayFields.children().each(function() {
if ($(this).text().localeCompare($field.text(), i18n.getCurrentLocale(), { sensitivity: 'base' }) > 0) {
$(this).before($field);
added = true;
return false;
}
});
if(!added) {
$displayFields.append($field);
}
insertOrdered($displayFields, $field);
}
}