Recent

Author Topic: [SOLVED] How to use "Resourcestring" in objectivec1 and objectivec2 mode  (Read 620 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
Getting my feet wet with localization, I found that the use of Resourcestring is not supported in objectivec1 or objectivec2 mode.
See also: Resource string documentation.

To confirm: Doing some tests, I see there are not a single is being added to the .po file, when enabling i18n, for any of my objectivec1 or objectivec2  units in my application. Regular units (mostly objfpc mode) however are included.

How does one use Resourcestrings for units that require objectivec1 or objectivec2 mode? (typically when a unit utilizes one or the other macOS framework)

Note: I'd like to keep those units "generic" so I can reuse them with other projects without any not-so-obvious constructs.
« Last Edit: April 17, 2025, 08:59:38 am by Hansaplast »

wp

  • Hero Member
  • *****
  • Posts: 12761
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #1 on: April 15, 2025, 10:27:22 am »
Just an idea: The {$mode} can be set per unit. Can't you move all resource strings to a separate unit in which you have {$mode objfp}? This way you could keep {$mode objectivec1/2} in all other units, but still have resource strings.

Thaddy

  • Hero Member
  • *****
  • Posts: 16805
  • Ceterum censeo Trump esse delendam
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #2 on: April 15, 2025, 10:52:31 am »
That is indeed the case and the documentation implies it...(it does not say objectivec mode won't work globally with such a unit in objfpc/delphi mode)
Try it. It may or may not work, I do never use resourcestrings myself but rely on resource files.
« Last Edit: April 15, 2025, 10:54:06 am by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Hansaplast

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #3 on: April 15, 2025, 11:20:12 am »
Yeah, took me a while to figure out why it didn't work - the documentation is the only place where I found it.
I did add it to the "Step-by-step instructions for creating multi-language applications" (macOS section) so others would see it.

I just wanted to use po files so other can help translating, as their native language.
The "system" to do this is there, so I figured; better use it if I can (and find/fix bugs if I find those as well).

Seems a FPC limitation. Just wondering how others work around this issue without going bonkers on constructs to wok around this.

So in short: it does not work in objectivec1 and objectivec2 mode.
Tested it with a objfpc mode unit and an objectivec1 unit. The objectivec1 unit is simply being skipped. The objfpc unit works as expected.

Hansaplast

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #4 on: April 15, 2025, 11:23:57 am »
Just an idea: The {$mode} can be set per unit. Can't you move all resource strings to a separate unit in which you have {$mode objfp}? This way you could keep {$mode objectivec1/2} in all other units, but still have resource strings.

Well, that could work, but I want to keep the unit more generic so I can use it wth other applications as well without having to figure out time and again how the work around works.
Even thought about making them a variable, set at initialization to the default values and have the main application override them with Resourcestring.
Of course then I ran into one of my applications that uses objectivec1 mode to begin with.

Thaddy

  • Hero Member
  • *****
  • Posts: 16805
  • Ceterum censeo Trump esse delendam
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #5 on: April 15, 2025, 01:12:06 pm »
This is not a workaround. As long as the unit is compiled in mode objfpc/delphi.
But I did not try yet if it works.
It is also cross platform that way.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Hansaplast

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #6 on: April 15, 2025, 02:24:10 pm »
I noticed that LFM files, even if the unit is objectivec1/2, will get its po file resources.
Which makes sense since its not the actual unit.

Makes me wonder if your method will work for macOS?
Is there a simple way so I can test this?
I'm not really familiar with using an external resource file.

Having said that:
Wouldn't it be desirable that Resourcestring works for all modes as it seems the recommended method for localization?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5938
  • Compiler Developer
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #7 on: April 16, 2025, 10:56:52 pm »
Getting my feet wet with localization, I found that the use of Resourcestring is not supported in objectivec1 or objectivec2 mode.

ObjectiveC1 and ObjectiveC2 are not modes. They are modeswitches which means they are used in conjunction with one of the modes (or the default mode).

To confirm: Doing some tests, I see there are not a single is being added to the .po file, when enabling i18n, for any of my objectivec1 or objectivec2  units in my application. Regular units (mostly objfpc mode) however are included.

The compiler does not deal with po-files. It generates rsj-files for each unit that contain all the resourcestrings of the corresponding unit. These can then be converted to po-files using the rstconv utility provided together with FPC. I don't know what Lazarus' I18n option does behind the scenes.

Wouldn't it be desirable that Resourcestring works for all modes as it seems the recommended method for localization?

Resource strings can be declared in all modes except ISO and ExtPas, because resourcestring is not a reserved keyword in those modes. The documentation simly isn't quite up to date regarding that (because in the past it required the Class modeswitch which is provided by defaul by modes ObjFPC, Delphi and DelphiUnicode).

Hansaplast

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
Re: How to use "Resourcestring" in objectivec1 and objectivec2 mode
« Reply #8 on: April 17, 2025, 08:58:48 am »
Thanks for the details PascalDragon!
You're totally right!

I finally got everything to work, and the key to getting it to work was: making sure the units were listed in the Project Inspector.

I never paid much attention to the Project Inspector before, but once I added the units there, the POT file is being updated with the proper resourcestring. (tip that I got in Bug Tracker)

Thanks all for chiming in - it is much appreciated  :)

 

TinyPortal © 2005-2018