Extend Programmer's Guide with notes about influence of setlocale()
ClosedPublic

Authored by kossebau on Apr 14 2017, 7:38 PM.

Details

Summary

Collect knowlegde found when investigating why i18n calls before line
QApplication app;
do not return translated strings.

Perhaps needs more prominent place to warn about the issues.
But having it documented somewhere will be a start.

Diff Detail

Repository
R249 KI18n
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
kossebau created this revision.Apr 14 2017, 7:38 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 14 2017, 7:38 PM

See thread around https://phabricator.kde.org/D5439#102005 for related discussion.

Actually, I simplified/ignored how i18n calls internally make the gettext call chose a locale name for which a catalog has been found, by temporarily setting the LANGUAGE variable.
What do you think, should this implementation detail be noted here as well, or would it only result in confused readers, who might already being challenged a lot by the complexity how to use the ki18n API?

aacid accepted this revision.Apr 27 2017, 3:24 PM
aacid added a subscriber: aacid.

Looks a bit convoluted way of explaining not to use i18n before Q*Application, but i guess it works :)

This revision is now accepted and ready to land.Apr 27 2017, 3:24 PM
ilic edited edge metadata.Apr 27 2017, 8:40 PM

I guess not bad to mention this stuff, but I would make following adaptations:

  1. Move the section as subsection of "Controlling Language Of Catalog to Use", and give it a more focused ( title, e.g. "Placing i18n calls before creation of QCoreApplication".
  1. State up front that in general one should avoid making i18n calls before QCoreApplication is crated, in one of two ways: either using statically initialized character arrays wrapped in I18N_* macros for extraction, and later making actual i18n* calls; or, using ki18n* calls to make KLocalizedString instances, that do not perform immediate catalog lookup, and later fetch actual translation throug their toString() methods.
  1. Finally the part about setlocale etc, for the case that all of the above is for some reason not applicable. I'm not 100% percent sure that everything will work as expected with this. For example, before QCoreApplication is initialized, what happens with ki18n's internal search for catalogs through standard directory paths...
kossebau updated this revision to Diff 14158.May 5 2017, 3:09 PM

rework text follwing feedback

@ilic Thanks for the comments, agreed. Actually the initial text had some "really?" across it, as I was surprised about the findings stated in there and wanted (your) confirmation.
So made this info bit a subsection of the "Writing Messages" part, and changed it to first be handling instructions (given this is a guide), then have some explanation for the curious. Also dumped any proposals for custom usage of setlocale().

BTW, the <a name="x"> and \ref x seems not to work (only reused that for consistency), will do a separate patch later which follows instructions from http://doxygen.10944.n7.nabble.com/Creating-links-in-and-between-Markdown-files-pages-td6689.html

BTW, the <a name="x"> and \ref x seems not to work (only reused that for consistency), will do a separate patch later which follows instructions from http://doxygen.10944.n7.nabble.com/Creating-links-in-and-between-Markdown-files-pages-td6689.html

Hmpf, seems there is a bug in doxygen about section creation, as actually also stated by the doxygen author in the linked thread above. Guess that is also why currently the <a name="x"> are used. Giving up on that bug for now.

For the given patch in this review, will commit next WE unless someone has further comments :)(or before if you ilic give your okay)

ilic accepted this revision.May 6 2017, 10:23 PM

All good to me.

This revision was automatically updated to reflect the committed changes.