-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement support for translation of field names in the QV, update the uk translation #3363
Implement support for translation of field names in the QV, update the uk translation #3363
Conversation
max_length = Math.Max(max_length, TextRenderer.MeasureText(field.Name, selectform.Font).Width); | ||
fields.Add((field.Name, field.Name)); | ||
var fieldDesc = MainV2.comPort.MAV.cs.GetFieldDesc(field.Name); | ||
max_length = Math.Max(max_length, TextRenderer.MeasureText(fieldDesc, selectform.Font).Width); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes the translated field name into account when calculating the required width.
return desc; | ||
} | ||
|
||
// fall-through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a translation does not exist, we fall back to showing the field name.
|
||
public string TryTranslate(string defaultTo) | ||
{ | ||
return MissionPlanner.Utilities.L10NU.GetString(_translationKey, defaultTo: defaultTo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DisplayFieldName attribute looks up a translation by a key (e.g. [DisplayFieldName('aspd_error.Field')]
, if no translation exists - then it returns defaultTo
. That way client code may know when a translation does not exist.
|
||
if (translated != null) | ||
{ | ||
var desc = translated.Replace("(fieldName)", name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered moving this logic inside DisplayFieldNameAttribute
, however decided to maintain consistency with the existing code: https://github.com/ArduPilot/MissionPlanner/blob/master/ExtLibs/ArduPilot/CurrentState.cs#L3990-L3994
This code's purpose is to allow field translations to show field names as they are as part of a translation, e.g. this key-value pair:
foo.Field=(fieldName) (My Translation)
would appear to the user in the QV, as:
foo (My Translation)
Doing so would help maintain the sort order and therefore not require of users to re-learn as new translations are added.
@@ -251,15 +251,18 @@ public CurrentState() | |||
public float customfield19 { get; set; } | |||
|
|||
// orientation - rads | |||
[DisplayFieldName("roll.Field")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ".Field" suffix is just a convention to help avoid name collisions. Here, roll.Field
is just a translation key that will be looked up verbatim - very similar to how the DisplayText
attribute is implemented.
Hi! This PR:
Thanks!