Skip to content
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

Merged
merged 11 commits into from
Jun 13, 2024

Conversation

FrequentFlyer86
Copy link
Contributor

Hi! This PR:

  • implements support for translation of field names via the DisplayFieldName attribute. Now field names in the QuickView can be translated into the user's language of choice
  • if there's no translation available for any given field name - the code falls back to showing the field name
  • adds translation of the field names into uk
  • improves some uk translations

Thanks!

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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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);
Copy link
Contributor Author

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);
Copy link
Contributor Author

@FrequentFlyer86 FrequentFlyer86 Jun 9, 2024

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")]
Copy link
Contributor Author

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.

@meee1 meee1 merged commit b427167 into ArduPilot:master Jun 13, 2024
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants