[Qt-creator] Keeping UI strings consistent

Kyle Evans kyledevans at gmail.com
Mon Mar 5 06:25:11 CET 2012


>
>> -----Original Message-----
>> From: qt-creator-bounces+kai.koehne=nokia.com at qt-project.org
>> [mailto:qt-creator-bounces+kai.koehne=nokia.com at qt-project.org] On
>> Behalf Of ext Kyle Evans
>> Sent: Tuesday, February 28, 2012 8:53 PM
>> To: qt-creator at qt-project.org
>> Subject: [Qt-creator] Keeping UI strings consistent
>>
>> So I've been working on a project that helps track prescriptions and
>> inventory.  Some data (IE: the name of a medication) is displayed in several
>> locations throughout the app.  The problem arises when I need to make a
>> tooltip or a QLabel that describes what information is being displayed.  If I
>> change a tooltip or QLabel in one .ui file, then I have to manually go and
>> change every QLabel and tooltip so that the app has consistent strings.
>
> Hi Kyle,
>
> First of all, this is a question about using Qt, not Qt Creator  - you should have rather posted it on interest at qt-project.org, it will also reach a wider audience there.
>
>> For example I have some widgets that appear like so:
>> "Medication name: <medication_name_is_inserted_here>"
>>
>> In another place in the application I have some QTableWidgets that display
>> results from a SQL query.  The column headings would appear like so:
>> "...... | Medication name | ......"
>>
>> My interest is keeping the strings "Medication name" identical if for example
>> I changed one to simply "Medication".  I currently have the following
>> solutions in mind for achieving this:
>>
>> 1) When using the UI designer, simply put placeholder strings which are then
>> replaced by global strings in C++.
>>   - Allows changing a string in one location and have it take effect everywhere
>> in the app.
>>   - Adds a ton of C++ code.  A single widget with 10 strings can easily add up to
>> 40 lines of code.
>>   - Partially removes the advantages of using the UI designer.
>
> You could leverage on this and use the translation infrastructure to translate the 'placeholder strings'. Now you can change your strings in one place (in the translation files), and you don't have to add 'ton of C++ code'.
>
> A neat trick to make really sure you translate everything is making the original strings still readable, but looking weird: E.g. http://doc.qt.nokia.com/qq/qq03-swedish-chef.html#mock.swedish . This way you can easily see places that you 'forgot'.
>
> Just my 2 cents,
>
> Kai

Thanks, after some initial trouble figuring out the Qt translation
workflow I was able to get it working.

-- 
-- Kyle Evans



More information about the Qt-creator mailing list