Forum > Translations

Embed .po files into exe, unclear on the next step

(1/1)

CyberFilth:
I have several language translations (.po files) for a program of mine stored in a languages subfolder and starting the program using switches on the commandline successfully changes the language of the program.
Now I want to embed the translations in the program so that I can distribute it as a standalone binary but I'm finding conflicting tutorials online.
Some advise converting the .po files to a resource, some say to compile to a .mo file first and then add that as a resource.
Also the advice on how to add a resource differs from using lazres on the command line to just going to Project Options > Add Resource

Can anyone recommend an up-to-date tutorial online, or can offer tips here, that will allow me to embed multiple translations into a program?
Thanks

lainz:

--- Quote ---I have several language translations (.po files) for a program of mine stored in a languages subfolder and starting the program using switches on the commandline successfully changes the language of the program.
--- End quote ---

If you embed the po or mo files into the executable you will not be able to switch them using the command line (if you're using the command line that comes with default). You will need to code your own switching code.

I've done that some time ago, there are several ways all described in the wiki.

minesadorada:
Example that unpacks the .po files in the initialization section:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---begin    // This uses a resource file added via Project/Options (Laz 1.7+)    if not FileExistsUTF8(sPoPath_en) then    begin      // create a resource stream which points to the po file      S := TResourceStream.Create(HInstance, 'JSONEDITOR.EN', MakeIntResource(10));      try        ForceDirectoriesUTF8(ProgramDirectory + 'locale');        F := TFileStream.Create(sPoPath_en, fmCreate);        try          F.CopyFrom(S, S.Size); // copy data from the resource stream to file stream        finally          F.Free; // destroy the file stream        end;      finally        S.Free; // destroy the resource stream      end;    end;    if not FileExistsUTF8(sPoPath_es) then    begin      S := TResourceStream.Create(HInstance, 'JSONEDITOR.ES', MakeIntResource(10));      try        ForceDirectoriesUTF8(ProgramDirectory + 'locale');        F := TFileStream.Create(sPoPath_es, fmCreate);        try          F.CopyFrom(S, S.Size);        finally          F.Free        end;      finally        S.Free;      end;    end;  end 

Navigation

[0] Message Index

Go to full version