Cocoa - LCLTranslator not using the correct path for .app bundes
- Lazarus/FPC Version: Lazarus 4.99 (rev main_4_99-1771-g8161c5f621) FPC 3.3.1 aarch64-darwin-cocoa
- Operating System: macOS 15.4 (any for that matter)
- CPU / Bitness: AARCH64 64 bit
What happens
Seems LCLTranslator uses ParamStr(0) to determine the path for determining potential locations of locale or languages directories.
For macOS this doesn't work with .app bundles, and selecting a directory in the .app bundle does not work either, as ParamStr(0) returns the path of the binary not as expected.
When running the .app bundle in the project directory, the binary in the app bundle is linked to the binary in the project folder. ParamStr(0) returns the project folder.
When the final application is created, the binary is located in project1.app/Contents/MacOS, and ParamStr(0) now returns project1.app/Contents/MacOS.
After that LCLTranslator assumes AppDir (project1.app/Contents/MacOS) as the base to start, however under macOS the translation files are typically stored in project1.app/Contents/Resources - which is not what the LCLTranslator code is taking in consideration.
What did you expect
I would have hoped that LCLTranslator would take macOS in consideration, but for now it only seems to consider Windows or Linux.
Steps to reproduce
Build a basic form with .app bundle that uses i18n, enable i18n and set the pot path to project1.app/Contents/Resources/locale, translate the pot file, run the application. Translation works. Now prepare the .app bundle for deployment - the binary is now no longer a linked file and gets moved to project1.app/Contents/MacOS. Translation no longer works.
Suggestion to fix this
Just getting my feet wet with localization, so my apologies if I missed something here, but this seems to work for me. It assumes that the "locale" or "languages" directory is located in the Resources directory of the app bundle. If the LPR file exists, use the Resources directory in the .app bundle located in the project directory. If the LPR file does not exist, use the correct Resources directory in the distribution .app bundle. Again: just getting my feet wet with localization.
diff --git a/lcl/lcltranslator.pas b/lcl/lcltranslator.pas
index 71393b519b..74c770209a 100644
--- a/lcl/lcltranslator.pas
+++ b/lcl/lcltranslator.pas
@@ -137,7 +137,15 @@ begin
FoundLang := LangID;
+ {$IFDEF darwin}
+ if FileExists(ChangeFileExt(ParamStr(0), '.lpr')) then // runs in project folder
+ AppDir := ParamStr(0)+'.app/Contents/Resources/'
+ else
+ AppDir := ExtractFileDir(ExtractFileDir(ParamStrUTF8(0)))+'/Resources/';
+ {$ELSE}
AppDir := ExtractFilePath(ParamStrUTF8(0));
+ {$ENDIF}
+
LCFileName := ChangeFileExt(GetLCFileName, LCExt);
if Dir<>'' then