IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants FMX Delphi Discussion :

[Tokyo 10.2.3] Traduction avec TLang [Windows]


Sujet :

Composants FMX Delphi

  1. #1
    Invité
    Invité(e)
    Par défaut [Tokyo 10.2.3] Traduction avec TLang
    Bonjour,

    Je continue de tester l'édition Community de Delphi.
    J'essaie de faire une appli multilingue. J'utilise pour cela le composant TLang.
    Cela fonctionne parfaitement pour traduire les champs Text des composants.

    Par contre, je ne trouve pas comment traduire les autres textes :
    • Textes des champs Hint
    • Textes des champs Caption
    • Textes à afficher dans les différentes fenêtres de dialogue...


    Je pensais que le composants prendrait en compte les ResourceString de mon unité, mais ce n'est pas le cas.

    Merci d'avance
    Dernière modification par tourlourou ; 19/08/2018 à 13h38.

  2. #2
    Membre habitué Avatar de XeGregory
    Homme Profil pro
    Passionné par la programmation
    Inscrit en
    Janvier 2017
    Messages
    233
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Passionné par la programmation
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 233
    Points : 159
    Points
    159

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Il n'existe pas de solution native ?

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 021
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 021
    Points : 40 935
    Points
    40 935
    Billets dans le blog
    62
    Par défaut
    Bonjour,

    j'ai toujours eu des problèmes avec les solutions "natives" proposées par Embarcadero, je galère encore avec d'anciennes applications où il faut recompiler pour chaque langage un oubli et c'est la cata

    perso s'il s'agit d'un seul programme je préfère utiliser gettext toutefois le bémol à ce dernier c'est le nombreux répertoires à déployer, dommage car très utilisé.
    Je me suis donc tourné vers DKLang , simple, open source, possibilité de fournir les outils de traduction (même si un editeur de texte suffit c'est mieux) et un ou deux fichiers (traductions) à déployer par programme
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  5. #5
    Invité
    Invité(e)
    Par défaut
    Très bien, merci de ces précisions.
    Je vais essayer DKLang.

  6. #6
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 021
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 021
    Points : 40 935
    Points
    40 935
    Billets dans le blog
    62
    Par défaut
    Bon choix de mon point de vue, cela dit j'ai pu faire un test plus ou moins concluant.


    soit un programme très simple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    unit testTlang;
     
    interface
     
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
      FMX.Controls.Presentation, FMX.StdCtrls;
     
    type
      TForm16 = class(TForm)
        Label1: TLabel;
        Lang1: TLang;
        procedure FormCreate(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form16: TForm16;
     
    implementation
     
    resourcestring
      StrRestest = 'restest';
     
     
    {$R *.fmx}
     
    procedure TForm16.FormCreate(Sender: TObject);
    begin
    LoadLangFromStrings(Lang1.LangStr['en']);
    showmessage(translate(StrRestest));
    end;
     
    end.
    j'ai tout d'abord mis à false le AutoSelect de TLang
    puis constatant que TLang ne prenait en compte les chaines et pas les noms de variable j'ai rajouté la chaine 'restest' (voir resourcestring) au TLang
    Nom : Capture.PNG
Affichages : 387
Taille : 5,5 Ko
    l'astuce est de ne pas oublier le Translate et ça fonctionne
    Nom : Capture.PNG
Affichages : 388
Taille : 3,6 Ko

    un test plus ou moins concluant
    j'ai juste testé le showmessage pour l'utilisation d'une resourcestring, il faudrait certainement pousser l'expérimentation
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  7. #7
    Invité
    Invité(e)
    Par défaut
    Très bien, je testerais, cela peut suffire pour mes tests.
    Je te remercie.

  8. #8
    Invité
    Invité(e)
    Par défaut
    Cela fontionne très bien.
    Je joins mon code, cela pourra peut-être aider

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    unit Main;
     
    interface
     
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ScrollBox,
      FMX.Memo, FMX.ListBox, FMX.StdCtrls, FMX.Controls.Presentation;
     
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        Label1: TLabel;
        combo1: TComboBox;
        Memo1: TMemo;
        od1: TOpenDialog;
        sd1: TSaveDialog;
        btnClickMe: TButton;
        Lang1: TLang;
        procedure FormCreate(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure combo1Change(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure btnClickMeClick(Sender: TObject);
      private
        { Déclarations privées }
        procedure InitCombobox;
        function CheckCurrentLang: string;
        procedure MajText;
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    ResourceString
      MsgLang = 'Message in English';
      HintBtnClickMe = 'Show a message';
      TitleMain = 'Multilanguage application';
     
    const
      LANG_FILE: string = 'CheckLang.lng';
     
    implementation
     
    uses
      MyDatas,
      FMX.Platform;
     
    {$R *.fmx}
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      InitCombobox;
      MajText;
    end;
     
    { button }
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Lang1.Resources.Clear;
      Lang1.LoadFromFile(ExtractFilePath(ParamStr(0)) + LANG_FILE);
      InitCombobox;
    end;
     
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Lang1.SaveToFile(ExtractFilePath(ParamStr(0)) + LANG_FILE);
    end;
     
    procedure TForm1.Button3Click(Sender: TObject);
    var myLang: string;
    begin
      myLang := CheckCurrentLang;
      ShowMessageFmt('CurrentLangID:%s', [myLang]);
      LoadLangFromStrings(Lang1.LangStr[myLang]);
      combo1.ItemIndex := combo1.Items.IndexOf(myLang);
    end;
     
    procedure TForm1.Button4Click(Sender: TObject);
    begin
      if (combo1.ItemIndex > 0) then
        Memo1.Lines.Assign(TStrings(Lang1.Resources.Objects[combo1.ItemIndex-1]))
      else
        Memo1.Lines.Assign(Lang1.Original);
    end;
     
    procedure TForm1.combo1Change(Sender: TObject);
    begin
      if (combo1.ItemIndex > 0) then
        LoadLangFromStrings(Lang1.LangStr[combo1.Items[combo1.ItemIndex]])
      else
        ResetLang;
     
      MajText;
    end;
     
    procedure TForm1.btnClickMeClick(Sender: TObject);
    var pos: Integer;
    begin
      ShowMessage(Translate(MsgLang));
    end;
     
    { Others functions }
     
    procedure TForm1.InitCombobox;
    begin
      combo1.Items.Clear;
      combo1.Items.Add('Default');
      combo1.Items.AddStrings(Lang1.Resources);
      combo1.ItemIndex := combo1.Items.IndexOf(CheckCurrentLang);
    end;
     
    function TForm1.CheckCurrentLang: string;
    var lsv: IFMXLocaleService;
    begin
      Result := '';
     
      if (TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, lsv)) then
        Result := lsv.GetCurrentLangID;
    end;
     
    procedure TForm1.MajText;
    begin
      Caption := Translate(TitleMain);
      btnClickMe.Hint := Translate(HintBtnClickMe);
    end;
     
    end.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [D7/Win32] Problème de traduction avec dxGetText
    Par _Alain_ dans le forum Débuter
    Réponses: 3
    Dernier message: 30/03/2008, 23h03
  2. Traduction avec Gettext
    Par glsn dans le forum Langage
    Réponses: 3
    Dernier message: 25/07/2007, 11h29
  3. [FASM=>NASM] Problème traduction avec MOD et $
    Par SteelBox dans le forum Assembleur
    Réponses: 4
    Dernier message: 30/05/2005, 15h16
  4. Traduction avec gettext
    Par aA189 dans le forum Linux
    Réponses: 7
    Dernier message: 19/10/2004, 15h57
  5. Traduction avec Polyglot
    Par TheViviTouch' dans le forum Outils
    Réponses: 3
    Dernier message: 02/08/2004, 00h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo