Changeset 269 for CoolTranslator
- Timestamp:
- Aug 22, 2011, 8:35:49 AM (13 years ago)
- Location:
- CoolTranslator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolTranslator/CoolTranslator.lpk
r229 r269 1 1 <?xml version="1.0"?> 2 2 <CONFIG> 3 <Package Version=" 3">3 <Package Version="4"> 4 4 <PathDelim Value="\"/> 5 5 <Name Value="CoolTranslator"/> 6 <AddToProjectUsesSection Value="True"/> 6 7 <Author Value="Chronos (robie@centrum.cz)"/> 7 8 <CompilerOptions> 8 <Version Value=" 9"/>9 <Version Value="10"/> 9 10 <PathDelim Value="\"/> 10 11 <SearchPaths> -
CoolTranslator/UCoolTranslator.pas
r258 r269 33 33 FOnTranslate: TNotifyEvent; 34 34 FPOFilesFolder: string; 35 FPOFile: TPOFile; 35 FPOFiles: TObjectList; // TObjectList<TPOFile>; 36 function GetLocale: string; 37 function GetLocaleShort: string; 36 38 function FindLocaleFileName(LCExt: string): string; 37 39 function GetLocaleFileName(const LangID, LCExt: string): string; … … 116 118 117 119 procedure TCoolTranslator.Translate; 118 begin 119 TranslateResourceStrings('ULanguages.cs.po'); 120 var 121 I, J: Integer; 122 Po: TPoFile; 123 begin 120 124 TranslateComponentRecursive(Application); 121 if Assigned(FPOFile) then 122 Translations.TranslateResourceStrings(FPOFile); 125 126 // Merge files to single translation file 127 try 128 Po := TPOFile.Create; 129 for I := 0 to FPOFiles.Count - 1 do 130 with TPoFile(FPoFiles[I]) do 131 for J := 0 to Items.Count - 1 do 132 with TPoFileItem(Items[J]) do 133 Po.Add(Identifier, Original, Translation, Comments, Context, 134 Flags, PreviousID); 135 Translations.TranslateResourceStrings(Po); 136 finally 137 Po.Free; 138 end; 123 139 end; 124 140 … … 126 142 var 127 143 FileName: string; 128 begin 129 FreeAndNil(FPOFile); 130 if Assigned(FLanguage) then begin 131 FileName := FindLocaleFileName('.po'); 132 if FileExistsUTF8(FileName) then FPOFile := TPOFile.Create(FileName); 144 FileList: TStringList; 145 I: Integer; 146 LocaleShort: string; 147 begin 148 FPOFiles.Clear; 149 if Assigned(FLanguage) then 150 try 151 LocaleShort := GetLocaleShort; 152 //ShowMessage(ExtractFileDir(Application.ExeName) + 153 // DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po'); 154 FileList := FindAllFiles(ExtractFileDir(Application.ExeName) + 155 DirectorySeparator + 'Languages', '*.' + LocaleShort + '.po'); 156 for I := 0 to FileList.Count - 1 do begin 157 FileName := FileList[I]; 158 //FileName := FindLocaleFileName('.po'); 159 if FileExistsUTF8(FileName) then FPOFiles.Add(TPOFile.Create(FileName)); 160 end; 161 finally 162 FileList.Free; 133 163 end; 134 164 end; … … 279 309 280 310 function TCoolTranslator.TranslateText(Identifier, Text: string): string; 281 begin 282 if Assigned(FPOFile) then 283 Result := FPOFile.Translate(Identifier, Text); 284 //ShowMessage(Text + ' => ' + Result); 311 var 312 I: Integer; 313 begin 314 if Text <> '' then begin 315 for I := 0 to FPoFiles.Count - 1 do begin 316 Result := TPoFile(FPOFiles[I]).Translate(Identifier, Text); 317 if Result <> Text then Break; 318 end; 319 if Result = '' then Result := Text; 320 end else Result := ''; 285 321 end; 286 322 … … 315 351 begin 316 352 inherited; 353 FPOFiles := TObjectList.Create; 317 354 ComponentExcludes := TComponentExcludesList.Create; 318 355 Languages := TLanguageList.Create; … … 328 365 destructor TCoolTranslator.Destroy; 329 366 begin 330 FPOFile .Free;367 FPOFiles.Free; 331 368 Languages.Free; 332 369 ComponentExcludes.Free; … … 334 371 end; 335 372 336 function TCoolTranslator.FindLocaleFileName(LCExt: string): string; 337 var 373 function TCoolTranslator.GetLocale: string; 374 var 375 Lang: string; 376 I: Integer; 338 377 T: string; 339 I: Integer; 340 Lang: string; 341 begin 342 Result := ''; 378 begin 343 379 // Win32 user may decide to override locale with LANG variable. 344 380 Lang := GetEnvironmentVariableUTF8('LANG'); … … 358 394 359 395 if Lang = 'en' then Lang := ''; // English files are without en code 396 Result := Lang; 397 end; 398 399 function TCoolTranslator.GetLocaleShort: string; 400 begin 401 Result := Copy(GetLocale, 1, 2); 402 end; 403 404 function TCoolTranslator.FindLocaleFileName(LCExt: string): string; 405 var 406 T: string; 407 I: Integer; 408 Lang: string; 409 begin 410 Result := ''; 411 Lang := GetLocale; 360 412 361 413 Result := GetLocaleFileName(Lang, LCExt); … … 365 417 Result := ChangeFileExt(ParamStrUTF8(0), LCExt); 366 418 if FileExistsUTF8(Result) then 367 exit;419 Exit; 368 420 369 421 Result := '';
Note:
See TracChangeset
for help on using the changeset viewer.