Changeset 229 for CoolTranslator


Ignore:
Timestamp:
Apr 7, 2011, 9:24:06 AM (14 years ago)
Author:
george
Message:
  • Added: ReadMe text file.
  • Modified: Instead property exclusion now using TTranslateString type.
  • Added: Automatic check of language files.
  • Added: Experimental translation of TStrings.
Location:
CoolTranslator
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • CoolTranslator/CoolTranslator.lpk

    r228 r229  
    1818    <License Value="GNU/GPL"/>
    1919    <Version Minor="1"/>
    20     <Files Count="2">
     20    <Files Count="3">
    2121      <Item1>
    2222        <Filename Value="UCoolTranslator.pas"/>
     
    2828        <UnitName Value="ULanguages"/>
    2929      </Item2>
     30      <Item3>
     31        <Filename Value="ReadMe.txt"/>
     32        <Type Value="Text"/>
     33      </Item3>
    3034    </Files>
    3135    <i18n>
  • CoolTranslator/UCoolTranslator.pas

    r228 r229  
    77uses
    88  Classes, SysUtils, Forms, StdCtrls, ExtCtrls, StrUtils, Controls, Contnrs,
    9   Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages;
     9  Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType;
    1010
    1111type
     
    5252    function TranslateText(Identifier, Text: string): string;
    5353    procedure AddExcludes(AClassType: TClass; PropertyName: string);
     54    procedure CheckLanguageFiles;
    5455    constructor Create(AOwner: TComponent); override;
    5556    destructor Destroy; override;
     
    116117procedure TCoolTranslator.Translate;
    117118begin
     119  TranslateResourceStrings('ULanguages.cs.po');
    118120  TranslateComponentRecursive(Application);
    119121  if Assigned(FPOFile) then
     
    205207      case PropType^.Kind of
    206208        tkString, tkLString, tkWString, tkAString: begin
    207           if not IsExcluded(Component, PropInfo^.Name) then
     209          if (UpperCase(PropType.Name) = 'TTRANSLATESTRING') then
     210          //if not IsExcluded(Component, PropInfo^.Name) then
    208211              SetStrProp(Component, PropInfo, TranslateText(PropInfo^.Name, GetWideStrProp(Component, PropInfo)));
    209212        end;
     
    214217              with TCollection(Obj).Items[I] do
    215218                TranslateComponent(TCollection(Obj).Items[I]);
     219          if Obj is TStrings then
     220            for I := 0 to TStrings(Obj).Count - 1 do
     221              with TStrings(Obj) do
     222                Strings[I] := TranslateText(Strings[I], Strings[I]);
    216223        end;
    217224      end;
     
    245252var
    246253  I: Integer;
     254  ItemName: string;
    247255begin
    248256  with Strings do begin
    249257    Clear;
    250     for I := 0 to Languages.Count - 1 do begin
    251       AddObject(TLanguage(Languages[I]).Name, Languages[I]);
    252     end;
     258    for I := 0 to Languages.Count - 1 do
     259    with TLanguage(Languages[I]) do
     260      if Available then begin
     261        ItemName := Name;
     262        if Code <> '' then ItemName := ItemName + ' (' + Code + ')';
     263        AddObject(ItemName, Languages[I]);
     264      end;
    253265  end;
    254266end;
     
    286298end;
    287299
     300procedure TCoolTranslator.CheckLanguageFiles;
     301var
     302  I: Integer;
     303begin
     304  TLanguage(Languages[0]).Available := True; // Automatic
     305
     306  for I := 1 to Languages.Count - 1 do
     307  with TLanguage(Languages[I]) do begin
     308    Available := FileExistsUTF8(POFilesFolder + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) +
     309      '.' + Code + ExtensionSeparator + 'po') or (Code = 'en');
     310  end;
     311end;
     312
    288313constructor TCoolTranslator.Create(AOwner: TComponent);
    289314begin
     
    292317  Languages := TLanguageList.Create;
    293318  POFilesFolder := 'Languages';
     319  CheckLanguageFiles;
    294320
    295321  // LCL
  • CoolTranslator/ULanguages.pas

    r228 r229  
    1212    Name: string;
    1313    Code: string;
     14    Available: Boolean;
    1415  end;
    1516
Note: See TracChangeset for help on using the changeset viewer.