Changeset 74 for trunk/Packages/CoolTranslator/UCoolTranslator.pas
- Timestamp:
- Dec 17, 2016, 6:33:13 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/CoolTranslator/UCoolTranslator.pas
r72 r74 6 6 7 7 uses 8 Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs, 9 Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType, 10 LazFileUtils, LazUTF8; 8 Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs, LazFileUtils, LazUTF8, 9 Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType; 11 10 12 11 type … … 47 46 procedure TranslateProperty(Component: TPersistent; PropInfo: PPropInfo); 48 47 function IsExcluded(Component: TPersistent; PropertyName: string): Boolean; 48 function GetLangFileDir: string; 49 49 public 50 50 ComponentExcludes: TComponentExcludesList; 51 51 Languages: TLanguageList; 52 procedure Translate; 52 53 procedure LanguageListToStrings(Strings: TStrings); 53 procedure Translate;54 54 procedure TranslateResourceStrings(PoFileName: string); 55 55 procedure TranslateUnitResourceStrings(UnitName: string; PoFileName: string); … … 151 151 I: Integer; 152 152 LocaleShort: string; 153 SearchMask: string; 153 154 begin 154 155 FPOFiles.Clear; … … 158 159 //ShowMessage(ExtractFileDir(Application.ExeName) + 159 160 // DirectorySeparator + 'Languages' + ' ' + '*.' + LocaleShort + '.po'); 160 FileList := FindAllFiles(ExtractFileDir(UTF8Encode(Application.ExeName)) + 161 DirectorySeparator + FPOFilesFolder, '*.' + LocaleShort + '.po'); 161 SearchMask := '*'; 162 if LocaleShort <> '' then SearchMask := SearchMask + '.' + LocaleShort; 163 SearchMask := SearchMask + '.po'; 164 FileList := FindAllFiles(GetLangFileDir, SearchMask); 162 165 for I := 0 to FileList.Count - 1 do begin 163 166 FileName := FileList[I]; 164 167 //FileName := FindLocaleFileName('.po'); 165 if FileExistsUTF8(FileName) then FPOFiles.Add(TPOFile.Create(FileName)); 168 if FileExists(FileName) and ( 169 ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', FileName))) or 170 (LocaleShort <> '')) then FPOFiles.Add(TPOFile.Create(FileName)); 166 171 end; 167 172 finally … … 175 180 FPoFilesFolder := AValue; 176 181 ReloadFiles; 182 CheckLanguageFiles; 177 183 end; 178 184 … … 191 197 PropInfo: PPropInfo; 192 198 PropList: PPropList; 199 Excludes: TComponentExcludes; 193 200 begin 194 201 Count := GetTypeData(Component.ClassInfo)^.PropCount; … … 243 250 if (UpperCase(PropType.Name) = 'TTRANSLATESTRING') then 244 251 //if not IsExcluded(Component, PropInfo^.Name) then 245 SetStrProp(Component, PropInfo, TranslateText(PropInfo^.Name, Get StrProp(Component, PropInfo)));252 SetStrProp(Component, PropInfo, TranslateText(PropInfo^.Name, GetWideStrProp(Component, PropInfo))); 246 253 end; 247 254 tkClass: begin … … 284 291 end; 285 292 293 function TCoolTranslator.GetLangFileDir: string; 294 begin 295 Result := FPOFilesFolder; 296 if Copy(Result, 1, 1) <> DirectorySeparator then 297 Result := ExtractFileDir(UTF8Encode(Application.ExeName)) + 298 DirectorySeparator + Result; 299 end; 300 286 301 procedure TCoolTranslator.LanguageListToStrings(Strings: TStrings); 287 302 var … … 316 331 I: Integer; 317 332 begin 333 Result := ''; 318 334 if Text <> '' then begin 319 335 for I := 0 to FPoFiles.Count - 1 do begin … … 342 358 var 343 359 I: Integer; 344 begin 360 LangDir: string; 361 begin 362 LangDir := GetLangFileDir; 345 363 TLanguage(Languages[0]).Available := True; // Automatic 346 364 347 365 for I := 1 to Languages.Count - 1 do 348 366 with TLanguage(Languages[I]) do begin 349 Available := FileExists UTF8(POFilesFolder + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) +367 Available := FileExists(LangDir + DirectorySeparator + ExtractFileNameOnly(Application.ExeName) + 350 368 '.' + Code + ExtensionSeparator + 'po') or (Code = 'en'); 351 369 end; … … 381 399 T: string; 382 400 begin 383 T := '';384 385 401 // Win32 user may decide to override locale with LANG variable. 386 Lang := GetEnvironmentVariable UTF8('LANG');402 Lang := GetEnvironmentVariable('LANG'); 387 403 388 404 // Use user selected language … … 392 408 if Lang = '' then begin 393 409 for i := 1 to Paramcount - 1 do 394 if (ParamStr UTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or395 (ParamStr UTF8(i) = '--lang') then396 Lang := ParamStr UTF8(i + 1);410 if (ParamStr(i) = '--LANG') or (ParamStr(i) = '-l') or 411 (ParamStr(i) = '--lang') then 412 Lang := ParamStr(i + 1); 397 413 end; 398 414 if Lang = '' then 399 L azGetLanguageIDs(Lang, T);415 LCLGetLanguageIDs(Lang, T); 400 416 401 417 if Assigned(Language) and (Language.Code = '') and Assigned(FOnAutomaticLanguage) then begin … … 403 419 end; 404 420 405 if Lang = 'en' then Lang := ''; // English files are without en code406 407 421 Result := Lang; 408 422 end; … … 415 429 function TCoolTranslator.FindLocaleFileName(LCExt: string): string; 416 430 var 431 T: string; 417 432 Lang: string; 418 433 begin … … 424 439 Exit; 425 440 426 Result := ChangeFileExt(ParamStr UTF8(0), LCExt);441 Result := ChangeFileExt(ParamStr(0), LCExt); 427 442 if FileExistsUTF8(Result) then 428 443 Exit;
Note:
See TracChangeset
for help on using the changeset viewer.