UI Text Conventions

From Qt Wiki
Jump to: navigation, search


The points listed below help you to make sure the text strings presented to the user are easy to handle by interpreters for localized applications. One should basically keep in mind that user interface text strings (enclosed in tr()-calls) are potentially extracted from of the source code in the translation process and thus the interpreter does not necessarily know the source code context of the messages.

  • Add linguist comments ( //:) to clarify where appropriate:
//: Contact book "Add person" button label
return tr("Add");
  • If the class is not a Q_OBJECT, use
QCoreApplication::translate("class context", "message")

or consider using

  • Do not use QObject::tr() which is confusing since the messages appear grouped by class context in linguist, which messages tied to QObject do not have.
  • Avoid contractions and do not shout at users using exclamation marks:
tr("Cannot open the file.")

instead of

tr("Can't open the file!")
  • Use plurals correctly:
tr("%n files found", 0, number)

instead of

tr("%1 files found").arg(number)
  • Be aware that articles have a grammatical gender in some languages and sentences cannot be as easily constructed as in English, so avoid things like:
tr("%1 failed").arg(someCondition ? "the operation" : "opening a file")
  • Try to avoid concatenating messages (use "%1" formatting instead), as some constructions may not work for grammar reasons. Also, never use leading/trailing/multiple blanks to achieve formatting in a message, as they will invariably be clobbered by translators (think Excel, other tools):
tr("Foo failed: %1").arg(message)

instead of

tr("Foo failed: ") + message
  • In Qt Designer, preferably use plain text for Tooltips. Should you want some extra formatting, write short, canonical HTML in the source tab of the rich text editor:
<html><head/><body><b>Note:</b> text.

In Qt 4.7, only the source tab of the Designer rich text editor should be used. The automatic conversion performed by the rich text editor tab produces a lot of redundant stylesheet information and hard-coded fonts that look bad on other platforms and make translation in Linguist difficult. Qt Designer 4.8 has a feature simplifying the rich text (on by default), still, you should verify by looking at the source tab.

Capitalization Guides Short Reference

Here is a short summary of the above mentioned Capitalization Guidelines. Two major styles are used, book title and sentence style:

  • Example of Book Title Capitalization
  • Example of sentence style capitalization

Use book style for:

  • Titles (window, dialog, group box, tab, list view columns, and so on)
  • Functions (menu items, buttons)
  • Selectable items (combobox items, listbox items, tree list items, and so on)

Use sentence style for:

  • Labels
  • Tool tips
  • Descriptive text