I have decided to write my own localization component that works with FMX and VCL. Most important, it's free of course! Here the details: https://delphitipsandtrick.blogspot.it/2017/10/delphi-tlanguage-localizaton-tool.html

I have decided to write my own localization component that works with FMX and VCL. Most important, it's free of course! Here the details: https://delphitipsandtrick.blogspot.it/2017/10/delphi-tlanguage-localizaton-tool.html

Basically there is a language editor that creates a json file with the localized strings. Then this file will be loaded in the program as resource (Project > Resources and Images > Add). The component simply loads the resource file, parses the json and outputs the string.

I wanted to share it in case it would be useful to someone even if I recognize that this is far away from perfect, performant, high quality. I have written this because I have some android/ios apps with some text inside (20/30 words not so much) and I really had to be able to have 2 or 3 languages.

I have decided this to work with json and resources but let me know your opinions! I am not an expert, this was the easiest solution I could find. Also I would like to be able to localize components in the form at runtime. At the very first time I thought that I could call FindComponent and localize the component in that way when the form opens.

Can this be a good option? I am not really sure since I think that it could slow down the app.
https://delphitipsandtrick.blogspot.it/2017/10/delphi-tlanguage-localizaton-tool.html

Comments

  1. any chance for git? mega is not a good place to put code...

    ReplyDelete
  2. I really think that the best way to localize Delphi applications would be a DFM patch like it is done for FMX views. You could then not only translate the text but also change components size and position aswell.

    {$R *.dfm}
    {$R *.dfm.en}
    {$R *.dfm.fr}

    ReplyDelete
  3. Paul TOTH​ That is a very nice idea. Are you telling me that the language editor should also generate automaatically the dfm when I save the file? Of course I should look at the original one to get the components

    ReplyDelete
  4. Maybe you can look at using resourcestrings, too?

    ReplyDelete
  5. Alberto Miola look at the way platform views works under FMX,

    {$R *.fmx}
    {$R *.LgXhdpiTb.fmx ANDROID}
    {$R *.iPhone55in.fmx IOS}

    it could be exactly the same but instead of a platform attribute it will be the current local info (at runtime). And you could (like under Android Studio) preview the forms under any language.

    An other option could to bind textual property to a localized resourcestring instead of a hard coded text (in fact that is the way Android Studio works)

    the DFM compiler could also extract BITMAP from the DFM and place them in a BITMAP resource so they can be shared among the forms...but it could be hard to do with the actual DFM workflow...Resource properties with proper editors could be easier to implement.

    ReplyDelete
  6. Paul TOTH​ many thanks! I am going to create as you have said something like {$R *.dfm.fr} but to keep the translation I should create for example a TLabel that contain them. Is it correct?

    ReplyDelete
  7. Alexander Benikowski I thought at first that I could have created pas files with resourcestrings in the implementation part. Is this what you mean?

    ReplyDelete
  8. Alberto Miola you can take a look at this french article
    lookinside.free.fr - Look Inside

    TForm1.Button4Click is the code to load a translation

    the extra DFM should only contains modified properties like this

    {code}
    object Form1: TForm1_fr
    Caption = 'Titre de la fenêtre'
    object Button3: TButton
    Caption = 'Bouton 3'
    Width = 200
    end
    end
    {code}

    there's a sample project to download at the bottom of the page

    ReplyDelete
  9. Alberto Miola no. As a developer, i can define Resourcestrings like:
    Resourcestring
    RGreeting = 'Hello World'

    It is possible to detect resourcestrings after a build, and create resourcedlls(like sisulizer does, which we use).

    For example a tool Foo.exe then has 2 additional dlls Foo.DE and Foo.EN(when supporting German and English). Those ResourceDLLs contain translated versions of the above resourcestring. Everywhere where i used RGreeting, it'll use the loaded translation.

    Never understood the fuz about building tools/mechanics which use extra TranslationMethods oO

    ReplyDelete
  10. BTW: DFMs are resources too. Therefore you can put translated copies of them into those ResourceDLLs which replaces the original DFMs with the localized versions.

    ReplyDelete
  11. PS: Ofcourse TranslationFunction-Based solutions are simpler to integrate for different platforms compared to resourcebased ones, i have to admit.

    ReplyDelete
  12. Compile a project with MapFiles set to detailed, and you'll get an additional *.drc file which has a complete resourcestringtable and paths to all used DFMs.

    ReplyDelete
  13. Alexander Benikowski I have decided to use what I see because I didnt Kobe about the resourcestring thing. I'm not an expert so I've found the easiest solution.

    So if I have correctly understood you can put resourcestrings in the main project. Then after a build you can load at runtime other files containing resouecestrings? Like the Foo.DE you mentioned

    ReplyDelete
  14. Yup. On windows these files are ResourceDLLs (DLLs without code but resources)

    ReplyDelete
  15. Oh and btw delphi comes with basic translationtools using this approach iirc

    ReplyDelete
  16. I was looking for android mostly. Thank you very much!

    ReplyDelete
  17. Alberto Miola try it. They might have done it for mobile, too.

    ReplyDelete

Post a Comment