Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-07

.mo files not working in multi language

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dietmar Braun

Hi!

sorry if I'm wrong here, but I posed my question in the Lazarus forum and was redirected here, so I am asking here again...

After some years of pausing Lazarus development, I just started again with a small project and the problems I had years ago with MultiLanguage
- these days, I managed to create a working multilanguage application, but when I try to distribute it, I run into problems.

My directory structure looks like this:
project (main folder): project1.exe
!--languages (sub folder): project1.de.mo, project1.en.mo

With this setting, switching from the default (German) to English (en) does not work. It seems the .mo files are just being ignored. When I add the .PO files to the subfolder, it works.

Can you advise? I just don't want to have to distribute the plain text .po files...

Thx!
Dietmar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x4A7DA0A7766EC11F.asc
Type: application/pgp-keys
Size: 2430 bytes
Desc: OpenPGP public key
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210720/8263b5cf/attachment.key> -------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210720/8263b5cf/attachment.sig>

Reply by email

Maxim Ganetsky
to Dietmar Braun

21.07.2021 0:03, Dietmar Braun via lazarus пишет:

Show quoted text 13 lines
Hi! sorry if I'm wrong here, but I posed my question in the Lazarus forum and was redirected here, so I am asking here again... After some years of pausing Lazarus development, I just started again with a small project and the problems I had years ago with MultiLanguage - these days, I managed to create a working multilanguage application, but when I try to distribute it, I run into problems. My directory structure looks like this: project (main folder): project1.exe !--languages (sub folder): project1.de.mo, project1.en.mo

Make sure you are using at least Lazarus 2.2 RC1.
Make sure you do not have PO and POT files in this subdirectory.

Show quoted text 10 lines
With this setting, switching from the default (German) to English (en) does not work. It seems the .mo files are just being ignored. When I add the .PO files to the subfolder, it works. Can you advise? I just don't want to have to distribute the plain text .po files... Thx! Dietmar
Best regards, Maxim Ganetsky mailto:

Reply by email

Dietmar Braun
to Maxim Ganetsky
Maxim Ganetsky wrote
Make sure you are using at least Lazarus 2.2 RC1. Make sure you do not have PO and POT files in this subdirectory.

Works like a charm, thank you!

Regards
Dietmar

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x4A7DA0A7766EC11F.asc
Type: application/pgp-keys
Size: 2430 bytes
Desc: OpenPGP public key
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210721/61c91d8c/attachment.key> -------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210721/61c91d8c/attachment.sig>

Reply by email

Dietmar Braun
to Maxim Ganetsky: 21.07.2021 0:03, Dietmar Braun via lazarus пишет: Make sure you are using at least…

Hi,

Maxim Ganetsky wrote
Make sure you are using at least Lazarus 2.2 RC1. Make sure you do not have PO and POT files in this subdirectory.

one further question:
Is it possible to add the .mo files as resources so that they are being hold in the exe file? How could I achieve this?

Best regards
Dietmar

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x4A7DA0A7766EC11F.asc
Type: application/pgp-keys
Size: 2430 bytes
Desc: OpenPGP public key
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210722/a3950e91/attachment.key> -------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210722/a3950e91/attachment.sig>

Reply by email

Maxim Ganetsky
to Dietmar Braun

22.07.2021 15:41, Dietmar Braun via lazarus пишет:

Show quoted text 9 lines
Hi, On 20.07.2021 23:36, Maxim Ganetsky via lazarus wrote: > Make sure you are using at least Lazarus 2.2 RC1. > Make sure you do not have PO and POT files in this subdirectory. one further question: Is it possible to add the .mo files as resources so that they are being hold in the exe file? How could I achieve this?

Put them to RES or LRS file, link this file to your program, then extract them at runtime to some directory and load it from there.

Best regards, Maxim Ganetsky mailto:

Reply by email

Bart
to Maxim Ganetsky
PM Maxim Ganetsky wrote
Put them to RES or LRS file, link this file to your program, then extract them at runtime to some directory and load it from there.

Can't you use them from the resource like you can with po-files?

From one of my units that does thi using old style .lrs resource:

===========

type
  TTransalateFromLazarusResourceResult = (trSuccess,
trResourceNotFound, trTranslationError);
function TryTranslateFromLazarusResource: TTransalateFromLazarusResourceResult;
var
  LRes: TLResource;
  PO: TPOFile;
  SS: TStringStream;
  B: Boolean;
begin
  Result := trResourceNotFound;
  LRes := LazarusResources.Find('lclstrconsts.nl','PO');
  if LRes  nil then
    begin
    SS := nil;
    PO := nil;
    try
      SS := TStringStream.Create(LRes.Value);
      //don't use TPoFile.Create(SS,True): it will crash on
TranslateUnitResourceStrings if you do
      PO := TPoFile.Create(SS, False);
      try
        B := TranslateUnitResourceStrings('lclstrconsts',PO);
        if B then Result := trSuccess else Result := trTranslationError;
      except
        Result := trTranslationError;
        DebugLn('Exception while translating LclStrConsts unit form
internal resources.');
      end;
    finally
      if Assigned(SS) then SS.Free;
      if Assigned(PO) then PO.Free;
    end;
  end;
end;
===============
Bart

Reply by email

Maxim Ganetsky
to Bart

23.07.2021 1:08, Bart via lazarus пишет:

Show quoted text 10 lines
On Thu, Jul 22, 2021 at 11:02 PM Maxim Ganetsky via lazarus wrote: > Put them to RES or LRS file, link this file to your program, then > extract them at runtime to some directory and load it from there. Can't you use them from the resource like you can with po-files? From one of my units that does thi using old style .lrs resource:

Yes, this should work the same way for MO files. In this case LCLTranslator unit will not help, functions from GetText should be called instead.

Best regards, Maxim Ganetsky mailto:

Reply by email

Dietmar Braun
to Maxim Ganetsky

Hi,

Maxim Ganetsky wrote
Yes, this should work the same way for MO files. In this case LCLTranslator unit will not help, functions from GetText should be called instead.

Thanks for your effort. Can you give an example here how to substitute LCLTranslator by GetText?

Thx
Dietmar

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x4A7DA0A7766EC11F.asc
Type: application/pgp-keys
Size: 2430 bytes
Desc: OpenPGP public key
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210723/0a44060d/attachment.key> -------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210723/0a44060d/attachment.sig>

Reply by email