Forum > Translations

Reading Embeded PO Files

(1/1)

CMELIGM:
Hello,

i am using PO Files to translate my Application and so far it all works out like expected. i recently embeded my po Files into the Executable using project settings -> resources.

i am currently extracting the files from the executable again when using it:

--- 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";}};} ---initialization  ForceDirectories(Application.Location + 'languages');  ExtractResource('MyApplication.DE', 'languages\MyApplication.de.po', true);  ExtractResource('MyApplication.EN', 'languages\MyApplication.en.po', true);     

and to switch language i use:

--- 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";}};} ---SetDefaultLang('en', 'languages');  
This works but i wonder if there is also a way where i do not have to extract the Files and can directly use them ?. so skip the steps "ExtractResource"

i tried this: "https://wiki.lazarus.freepascal.org/Everything_else_about_translations#Compiling_po_files_into_the_executable_and_change_language_while_running"

but i did not work for me (i also did not fully understand what is going on).

Thaddy:
The overhead is almost not there or very low: why would you need that?
I think you can also include the PO files as RT_RCDATA resource entries. Then there is no overhead at all.(just a pointer change)

Bart:
Maybe this unit of mine can give you some pointers?

Bart

CMELIGM:

--- Quote from: Thaddy on June 13, 2025, 10:00:11 am ---The overhead is almost not there or very low: why would you need that?
I think you can also include the PO files as RT_RCDATA resource entries. Then there is no overhead at all.(just a pointer change)

--- End quote ---

it would be great to not have the PO Files lying around in the install Folder.


--- Quote from: Bart on June 13, 2025, 01:34:25 pm ---Maybe this unit of mine can give you some pointers?

Bart

--- End quote ---

Thank you, this was indeed helpful.

Thaddy:
Tnx Bart for the real life example I was too lazy to provide.

Navigation

[0] Message Index

Go to full version