Recent

Author Topic: Should i18n work with TListBox and TMemo contents?  (Read 722 times)

pleumann

  • Jr. Member
  • **
  • Posts: 95
Should i18n work with TListBox and TMemo contents?
« on: October 02, 2023, 11:17:31 am »
Hi,

I'm making first steps towards translating my application. A lot of things work fine already, although the overall process is a bit obscure to me. For instance, I don't fully understand which files will be updated automatically when new resources are added in the designer. The wiki docs continue to puzzle me because they don't seem to match the current state of Lazarus (LclTranslator vs. DefaultTranslator, .po files vs. .pot files, ...).

Anyway, the problem I have right now is that the contents of TListBox and TMemo objects do not appear in the i18n files. Is that a general limitation? I can move the contents to resource strings and fill the objects in OnCreate. I guess I would also have to take care of them in case of runtime language changes, right? Of course, if there were a built-in way to make it work that would be my preference.

Best regards
Joerg

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: Should i18n work with TListBox and TMemo contents?
« Reply #1 on: October 02, 2023, 12:31:50 pm »
The wiki docs continue to puzzle me because they don't seem to match the current state of Lazarus (LclTranslator vs. DefaultTranslator, .po files vs. .pot files, ...)
Which wiki language are you using? IIRC, I reworked the main (English) page of https://wiki.lazarus.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications recently, but, of course, I cannot take care of the translated pages.

LCLTranslator and DefaultTranslator are effectively the same, DefaultTranslator just calls SetDefaultLang at startup. .pot files are the untranslated po files and serve as templates for the translations, it used to be .po without language code until some years ago. In order to create a new translation, copy the .pot file and rename its extension to .language_code.po where "language_code" is the two-digit country code, e.g. "de" for German. Then load the new file into a translation tool, e.g. POEdit, and translate the individual lines.

Anyway, the problem I have right now is that the contents of TListBox and TMemo objects do not appear in the i18n files. Is that a general limitation? I can move the contents to resource strings and fill the objects in OnCreate. I guess I would also have to take care of them in case of runtime language changes, right? Of course, if there were a built-in way to make it work that would be my preference.
TListbox, TMemo, TCombobox - in general: all classes with TStrings properties - usually display information which is available only at runtime. Therefore they cannot be handled by the automatic translation. If you want their contents be translated you must create resource strings and assign them manually when the application language changes.

pleumann

  • Jr. Member
  • **
  • Posts: 95
Re: Should i18n work with TListBox and TMemo contents?
« Reply #2 on: October 02, 2023, 01:04:39 pm »
The wiki docs continue to puzzle me because they don't seem to match the current state of Lazarus (LclTranslator vs. DefaultTranslator, .po files vs. .pot files, ...)
Which wiki language are you using? IIRC, I reworked the main (English) page of https://wiki.lazarus.freepascal.org/Step-by-step_instructions_for_creating_multi-language_applications recently, but, of course, I cannot take care of the translated pages.

LCLTranslator and DefaultTranslator are effectively the same, DefaultTranslator just calls SetDefaultLang at startup. .pot files are the untranslated po files and serve as templates for the translations, it used to be .po without language code until some years ago. In order to create a new translation, copy the .pot file and rename its extension to .language_code.po where "language_code" is the two-digit country code, e.g. "de" for German. Then load the new file into a translation tool, e.g. POEdit, and translate the individual lines.

I'll have another look at that page, if that is the one most recently updated. I'm reading them in English, so possibly outdated translations are not an issue for me.

Regarding the file handling: What happens if I already have some translations files, but add new resources to my project? Will the *.pot file be updated automatically? And would POEdit notice that, say, *.de_DE.po is now missing some items that are new in *.pot? Or do I have do manage/merge manually?

Anyway, the problem I have right now is that the contents of TListBox and TMemo objects do not appear in the i18n files. Is that a general limitation? I can move the contents to resource strings and fill the objects in OnCreate. I guess I would also have to take care of them in case of runtime language changes, right? Of course, if there were a built-in way to make it work that would be my preference.
TListbox, TMemo, TCombobox - in general: all classes with TStrings properties - usually display information which is available only at runtime. Therefore they cannot be handled by the automatic translation. If you want their contents be translated you must create resource strings and assign them manually when the application language changes.

Yes, I noticed the slight stupidity of the question myself. :) I was about to post that when I saw your response. I somehow expected that each and every string resource in the program is subject to i18n, but what I am doing here is abusing lists as menus and a memo for displaying a longer text, so that's not the normal usecase.

Thanks!
Joerg

wp

  • Hero Member
  • *****
  • Posts: 12470
Re: Should i18n work with TListBox and TMemo contents?
« Reply #3 on: October 02, 2023, 01:33:50 pm »
What happens if I already have some translations files, but add new resources to my project? Will the *.pot file be updated automatically? And would POEdit notice that, say, *.de_DE.po is now missing some items that are new in *.pot? Or do I have do manage/merge manually?
Normally this is done in a transparent/automatic way when "Create/update .po file when saving lfm file" is checked in the i18n project options. You may also want to check "Force update PO files on next build" - but this will uncheck itself after the next build, iirc. If, in rare cases, the pot/po files are not updated, do a "Run" > "Build", or "Run" > "Clean up and Build", or "Project" > "Resave forms with enabled i18n" (can't remember which one is most effective...)

Be careful with .lrj files. They are important for the translation system. Do not delete them, add them to the repository if you use version control (git, svn).

When new resoure strings or controls with translated texts are added to a form, the items are added to the po/pot files, their translation will be empty. Load each po into POEdit, seek for untranslated items (empty lines at the right side of the text list) and update them.

Yes, I noticed the slight stupidity of the question myself. :)
There are no stupid questions.

 

TinyPortal © 2005-2018