String localization

Hi again

The strings don't seem to be included for localization—is that correct?

ex :

My_string := 'I need to be localized';

I'd like to say that, for me, this is an essential feature

That is correct, a string literal in code is not picked up. The collector walks the live components through RTTI, so it can only see text that sits in a published property of a named component. A literal has no component, no name and no property to attach a translation to, so there is nothing for the editor to key on.

For strings in code, use a snippet. Declare it once with a name and its source text, register it at startup, and translate at the point of use:

uses
  TMS.TMSFNCLocalizationSnippets;

const
  SNeedsLocalizing: TTMSFNCSnippetRec = (Name: 'Messages.NeedsLocalizing'; DefaultText: 'I need to be localized');

initialization
  CollectSnippet(SNeedsLocalizing);

and then:

My_string := TranslateSnippet(SNeedsLocalizing);

The CollectSnippet call in initialization is what makes it appear in the editor, under Snippets. TranslateSnippet only resolves it, so both are needed.

If the text depends on a count ("1 item" versus "5 items") use a number snippet instead. Those declare one line per plural form and pick the right one for the target language, which is not something a single string with a %d in it can do correctly for every language:

const
  SnippetItemCount: TTMSFNCNumberSnippetRec = (Name: 'Sales.ItemCount'; One: '%d item in the order.'; Other: '%d items in the order.');

initialization
  CollectNumberSnippet(SnippetItemCount);

used as TranslateNumberSnippetFormat(SnippetItemCount, Count).

There is a working example of both in the NumberSnippets demo.

Hi
Sure, there is a solution—either using “snippets” or “localizationStringCatalog.” But from what I've seen, you have to write the "catalog" to localize the strings. This is feasible for a new project or one that contains only a few strings. But for a project containing several hundred strings, it would take an enormous amount of time. The “LocalizationCollector” needs to be able to detect these strings in the code, such as with GetText(‘xxx’) or _(‘xxx’) [ GitHub - jrathlev/GnuGetText-for-Delphi: Gnu GetText Tools for Delphi · GitHub ].
For example, by using the existing “StringCatalog.Strings.FindByName(‘xxx’).Value” to add that string to the catalog if it doesn’t exist.
Without this capability, I wouldn’t be able to use “TMS Localization,” unfortunately :sleepy_face: