Recent

Author Topic: Localization of Open/Save dialogs for non-English languages  (Read 1157 times)

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 321
Localization of Open/Save dialogs for non-English languages
« on: January 04, 2021, 02:38:09 pm »
Users of my app from non-English countries complaint that OpenDialog and SaveDialog are always shown on English language (including overwrite file prompts).

The same problem with Lazarus IDE. Even if I set French or German language for user interface, all Open/Save dialogs stay on English (despite the fact that macOS also use French or German interface).

How to modify my app bundle to use current UI language from macOS?

I read that I should add localization options in Xcode project that automatically modifies the APP bundle, but we use Lazarus. So we should do it manually.
« Last Edit: January 04, 2021, 05:19:51 pm by Igor Kokarev »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1428
  • Former Delphi 1-7, 10.2 user
Re: Localization of Open/Save dialogs for non-English languages
« Reply #1 on: January 05, 2021, 05:39:18 am »
Apple's Xcode localisation article is pretty easy to understand, but I do not think this is what you really want because I'm reasonably certain it is not going to work with a Lazarus-created application.

Have you looked at the Wiki article Step-by-step instructions for creating multi-language applications ?

Disclaimer: I've never localised anything other than an Apple help book as a demo.
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

dbannon

  • Hero Member
  • *****
  • Posts: 1372
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Localization of Open/Save dialogs for non-English languages
« Reply #2 on: January 05, 2021, 07:04:13 am »
I don't think its a problem for Igor to solve by reading wiki.

When a translator translates to another language, he/she gets a list of the text the programmer has used in the application.  But there is a second list, one made up of all the text from LCL, such things as open dialogs.  That list ends up in a file called lclstrconsts."$CCODE".mo

That LCL translation is done by the LCL developers (bless them) and it looks to me as if they have missed the file dialog boxes.

I just switched my app to Spanish and sure enough, a save dialog still comes up in English.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 321
Re: Localization of Open/Save dialogs for non-English languages
« Reply #3 on: January 05, 2021, 08:53:30 am »
My app is translated to other languages, using internal code and language strings based on .ini files.

The problem is only with file Open/Save dialogs. Regrettably Wiki article doesn't describe this situation for macOS.

I've read Apple's documentation for this subject.

Yes, it's possible to manually translate some text captions in Open/Save dialogs. Not all. You will not able to translate names of user's folders (Documents, Music, Desktop) in the list of folders on the left side.

We need to "tell" macOS that Open/Save dialogs should be translated automatically by macOS on OS side. Not a manual translation by our app. I have no idea how to do it.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2955
  • Compiler Developer
Re: Localization of Open/Save dialogs for non-English languages
« Reply #4 on: January 05, 2021, 08:55:16 am »
I just switched my app to Spanish and sure enough, a save dialog still comes up in English.

The file dialogs are done by the OS, not the LCL. Thus one needs to correctly tell the OS to translate the dialog (e.g. on Windows the OS language will be used). And that's the question that Igor Kokarev has.

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 321
Re: Localization of Open/Save dialogs for non-English languages
« Reply #5 on: January 05, 2021, 09:06:15 am »
The file dialogs are done by the OS, not the LCL. Thus one needs to correctly tell the OS to translate the dialog (e.g. on Windows the OS language will be used). And that's the question that Igor Kokarev has.

Yes. And it would be great if Lazarus IDE also could use OS language in Open/Save dialogs. Or language set for IDE in Lazarus's Preferences.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1428
  • Former Delphi 1-7, 10.2 user
Re: Localization of Open/Save dialogs for non-English languages
« Reply #6 on: January 05, 2021, 09:55:00 am »
The solution is very simple as it turns out :)  Just add this to your application's Info.plist file:

Code: XML  [Select][+][-]
  1.         <key>CFBundleLocalizations</key>
  2.         <array>
  3.                 <string>en</string>
  4.                 <string>fr</string>
  5.                 ...etc...
  6.         </array>

Your application will then  present the system dialogs in the user's preferred language. See attached pic.
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 321
Re: Localization of Open/Save dialogs for non-English languages
« Reply #7 on: January 05, 2021, 02:12:22 pm »
trev,

Thanks for your advice.

It's strange, but it doesn't work for me. I switched OS language to French and restarted macOS.

I created a new project and added these keys to Info.plist (English and French). However Open/Save dialog stay on English (OS language is French, and Chrome shows Open dialog on French).

I attach my test project (without executable file).

macOS 11.1 Big Sur, Lazarus 2.1.0 / FPC 3.2.1 fixes.

P.S. I checked other apps. For example, TextEdit shows localized Open/Save dialogs but it's Info.plist doesn't include any CFBundleLocalizations records.
« Last Edit: January 05, 2021, 02:22:28 pm by Igor Kokarev »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1428
  • Former Delphi 1-7, 10.2 user
Re: Localization of Open/Save dialogs for non-English languages
« Reply #8 on: January 05, 2021, 10:36:56 pm »
Your test application worked for me - when I changed my language to French, restarted, your open dialog was in French ... I tested it under Mojave, Catalina and Big Sur (ARM64). Weird!

I can't think why it does not work for you... did you try copying the executable into the MacOS folder and deleting the symbolic link? Have you tried it on other machines?
« Last Edit: January 05, 2021, 10:51:38 pm by trev »
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 321
Re: Localization of Open/Save dialogs for non-English languages
« Reply #9 on: January 06, 2021, 12:05:09 am »
trev,

Thanks! You gave me an idea.

Localization in NSOpenPanel / NSSavePanel does NOT work when an app uses a symbolic link to executable created by Lazarus. I didn't think about this reason. Seems to be a bug in macOS?

So I removed a symbolic link and copied real executable to /MacOS folder and now localization works fine!

Also I found two alternative ways to activate localization:

A. Add CFBundleLocalizations records as you wrote above.

B. Or create an empty folder for each language in /Contents/Resources
For example for French fr.lproj in /Resources

Probably it would be an useful information for Lazarus Wiki.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1428
  • Former Delphi 1-7, 10.2 user
Re: Localization of Open/Save dialogs for non-English languages
« Reply #10 on: January 06, 2021, 03:35:07 am »
Great!

Yes - I've already added the .plist info to the localisation article in the Wiki. I'll also add your find. Thanks!
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 321
Re: Localization of Open/Save dialogs for non-English languages
« Reply #11 on: January 06, 2021, 08:31:51 am »
trev,

Thanks again!

 

TinyPortal © 2005-2018