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

i18n the OSD warnings list, ordering it in alphabetical order (#1497)

i18n the OSD warnings list, ordering it in alphabetical order
This commit is contained in:
Michael Keller 2019-06-18 00:13:54 +12:00 committed by GitHub
commit 7f452d9c96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 124 additions and 24 deletions

View file

@ -1213,66 +1213,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'
},
@ -1827,7 +1843,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 });
}
}
@ -2049,6 +2065,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
@ -2265,9 +2307,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);
}
}
}
}
@ -2376,14 +2425,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(
@ -2406,17 +2449,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);
}
}