Changeset 416
- Timestamp:
- Nov 17, 2021, 10:47:48 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 6 edited
- 10 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Integrated.lpi
r396 r416 99 99 </Item3> 100 100 </RequiredPackages> 101 <Units Count="4 8">101 <Units Count="47"> 102 102 <Unit0> 103 103 <Filename Value="Integrated.lpr"/> … … 360 360 <IsPartOfProject Value="True"/> 361 361 </Unit46> 362 <Unit47>363 <Filename Value="ULanguages.pas"/>364 <IsPartOfProject Value="True"/>365 </Unit47>366 362 </Units> 367 363 </ProjectOptions> -
trunk/LocalPlayer/Help.pas
r410 r416 290 290 291 291 HelpText := TStringTable.Create; 292 HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + ' help.txt'));292 HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + 'Help.txt')); 293 293 hADVHELP := HelpText.Gethandle('ADVHELP'); 294 294 hIMPHELP := HelpText.Gethandle('IMPHELP'); -
trunk/Packages/Common/ULanguages.pas
r396 r416 1 1 unit ULanguages; 2 2 3 {$mode objfpc}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils, Contnrs;8 Classes, SysUtils, fgl; 9 9 10 10 type … … 15 15 end; 16 16 17 { TLanguage List}18 19 TLanguage List = class(TObjectList)17 { TLanguages } 18 19 TLanguages = class(TFPGObjectList<TLanguage>) 20 20 function SearchByCode(ACode: string): TLanguage; 21 21 procedure AddNew(Code: string; Name: string); 22 constructor Create ;22 constructor Create(FreeObjects: Boolean = True); 23 23 end; 24 24 … … 223 223 224 224 225 { TLanguage List}226 227 function TLanguage List.SearchByCode(ACode: string): TLanguage;225 { TLanguages } 226 227 function TLanguages.SearchByCode(ACode: string): TLanguage; 228 228 var 229 229 I: Integer; … … 235 235 end; 236 236 237 procedure TLanguage List.AddNew(Code: string; Name: string);237 procedure TLanguages.AddNew(Code: string; Name: string); 238 238 var 239 239 NewItem: TLanguage; … … 245 245 end; 246 246 247 constructor TLanguage List.Create;247 constructor TLanguages.Create(FreeObjects: Boolean); 248 248 begin 249 inherited Create;249 inherited; 250 250 AddNew('', SLangAuto); 251 251 AddNew('aa', SLang_aa); -
trunk/Packages/Common/UTranslator.pas
r396 r416 1 1 unit UTranslator; 2 2 3 {$mode Delphi}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils, Forms, ExtCtrls, Controls, Contnrs, LazFileUtils, LazUTF8,8 Classes, SysUtils, Forms, ExtCtrls, Controls, fgl, LazFileUtils, LazUTF8, 9 9 Translations, TypInfo, Dialogs, FileUtil, LCLProc, ULanguages, LCLType, 10 10 LCLVersion; … … 12 12 type 13 13 THandleStringEvent = function (AValue: string): string of object; 14 15 TPoFiles = class(TFPGObjectList<TPOFile>) 16 end; 14 17 15 18 { TComponentExcludes } … … 24 27 { TComponentExcludesList } 25 28 26 TComponentExcludesList = class(T ObjectList)29 TComponentExcludesList = class(TFPGObjectList<TComponentExcludes>) 27 30 function FindByClassType(AClassType: TClass): TComponentExcludes; 28 31 procedure DumpToStrings(Strings: TStrings); … … 36 39 FOnAutomaticLanguage: THandleStringEvent; 37 40 FOnTranslate: TNotifyEvent; 38 FP OFilesFolder: string;39 FP OFiles: TObjectList; // TObjectList<TPOFile>;41 FPoFilesFolder: string; 42 FPoFiles: TPoFiles; 40 43 function GetLocale: string; 41 44 function GetLocaleShort: string; … … 50 53 public 51 54 ComponentExcludes: TComponentExcludesList; 52 Languages: TLanguage List;55 Languages: TLanguages; 53 56 procedure Translate; 54 procedure LanguageListToStrings(Strings: TStrings );57 procedure LanguageListToStrings(Strings: TStrings; WithCode: Boolean = True); 55 58 procedure TranslateResourceStrings(PoFileName: string); 56 59 procedure TranslateUnitResourceStrings(UnitName: string; PoFileName: string); … … 63 66 destructor Destroy; override; 64 67 published 65 property POFilesFolder: string read FP OFilesFolder write SetPOFilesFolder;68 property POFilesFolder: string read FPoFilesFolder write SetPOFilesFolder; 66 69 property Language: TLanguage read FLanguage write SetLanguage; 67 70 property OnTranslate: TNotifyEvent read FOnTranslate write FOnTranslate; … … 71 74 72 75 procedure Register; 76 73 77 74 78 implementation … … 117 121 destructor TComponentExcludes.Destroy; 118 122 begin 119 PropertyExcludes.Free;120 inherited Destroy;123 FreeAndNil(PropertyExcludes); 124 inherited; 121 125 end; 122 126 … … 128 132 I, J: Integer; 129 133 Po: TPoFile; 130 Item: TP OFileItem;134 Item: TPoFileItem; 131 135 begin 132 136 TranslateComponentRecursive(Application); … … 134 138 // Merge files to single translation file 135 139 try 136 Po := TP OFile.Create;137 for I := 0 to FP OFiles.Count - 1 do140 Po := TPoFile.Create; 141 for I := 0 to FPoFiles.Count - 1 do 138 142 with TPoFile(FPoFiles[I]) do 139 143 for J := 0 to Items.Count - 1 do … … 162 166 SearchMask: string; 163 167 begin 164 FP OFiles.Clear;168 FPoFiles.Clear; 165 169 if Assigned(FLanguage) then 166 170 try … … 177 181 if FileExists(FileName) and ( 178 182 ((LocaleShort = '') and (Pos('.', FileName) = Pos('.po', FileName))) or 179 (LocaleShort <> '')) then FP OFiles.Add(TPOFile.Create(FileName));183 (LocaleShort <> '')) then FPoFiles.Add(TPOFile.Create(FileName)); 180 184 end; 181 185 finally … … 281 285 var 282 286 Item: TClass; 283 284 287 Excludes: TComponentExcludes; 285 288 begin … … 301 304 function TTranslator.GetLangFileDir: string; 302 305 begin 303 Result := FP OFilesFolder;306 Result := FPoFilesFolder; 304 307 if Copy(Result, 1, 1) <> DirectorySeparator then 305 308 Result := ExtractFileDir(Application.ExeName) + … … 307 310 end; 308 311 309 procedure TTranslator.LanguageListToStrings(Strings: TStrings );312 procedure TTranslator.LanguageListToStrings(Strings: TStrings; WithCode: Boolean = True); 310 313 var 311 314 I: Integer; … … 318 321 if Available then begin 319 322 ItemName := Name; 320 if Code <> ''then ItemName := ItemName + ' (' + Code + ')';323 if WithCode and (Code <> '') then ItemName := ItemName + ' (' + Code + ')'; 321 324 AddObject(ItemName, Languages[I]); 322 325 end; … … 342 345 if Text <> '' then begin 343 346 for I := 0 to FPoFiles.Count - 1 do begin 344 Result := TPoFile(FP OFiles[I]).Translate(Identifier, Text);347 Result := TPoFile(FPoFiles[I]).Translate(Identifier, Text); 345 348 if Result <> Text then Break; 346 349 end; … … 369 372 begin 370 373 LangDir := GetLangFileDir; 371 TLanguage(Languages[0]).Available := True; // Automatic374 Languages.SearchByCode('').Available := True; // Automatic 372 375 373 376 for I := 1 to Languages.Count - 1 do … … 381 384 begin 382 385 inherited; 383 FP OFiles := TObjectList.Create;386 FPoFiles := TPoFiles.Create; 384 387 ComponentExcludes := TComponentExcludesList.Create; 385 Languages := TLanguage List.Create;388 Languages := TLanguages.Create; 386 389 POFilesFolder := 'Languages'; 387 390 CheckLanguageFiles; … … 395 398 destructor TTranslator.Destroy; 396 399 begin 397 F POFiles.Free;398 Languages.Free;399 ComponentExcludes.Free;400 inherited Destroy;400 FreeAndNil(FPoFiles); 401 FreeAndNil(Languages); 402 FreeAndNil(ComponentExcludes); 403 inherited; 401 404 end; 402 405 -
trunk/Settings.pas
r408 r416 58 58 {$R *.lfm} 59 59 60 uses 61 Start; 62 60 63 var 61 64 SFullScreen, SGamma, SRestartMsg, SShortCutPrimary, SShortCutSecondary, … … 193 196 begin 194 197 ReloadLanguages; 195 Languages.LoadToStrings(ListLanguages.Items);198 StartDlg.Translator.LanguageListToStrings(ListLanguages.Items); 196 199 ListLanguages.Font.Color := MainTexture.ColorMark; 197 200 ListKeyBindings.Font.Color := MainTexture.ColorMark; … … 260 263 procedure TSettingsDlg.LoadData; 261 264 begin 262 ListLanguages.ItemIndex := Languages.Search(LocaleCode); 263 if (ListLanguages.ItemIndex = -1) and (Languages.Count > 0) then 264 ListLanguages.ItemIndex := 0; 265 StartDlg.Translator.Language := StartDlg.Translator.Languages.SearchByCode(LocaleCode); 266 StartDlg.Translator.LanguageListToStrings(ListLanguages.Items, False); 267 ListLanguages.ItemIndex := ListLanguages.Items.IndexOfObject(StartDlg.Translator.Language); 268 if ListLanguages.ItemIndex = -1 then ListLanguages.ItemIndex := 0; 265 269 if FullScreen then ButtonFullscreen.ButtonIndex := 3 266 270 else ButtonFullscreen.ButtonIndex := 2; … … 274 278 begin 275 279 NeedRestart := Gamma <> LocalGamma; 276 LocaleCode := Languages[ListLanguages.ItemIndex].ShortName; 280 if ListLanguages.ItemIndex <> -1 then begin 281 StartDlg.Translator.Language := TLanguage(ListLanguages.Items.Objects[ListLanguages.ItemIndex]); 282 LocaleCode := StartDlg.Translator.Language.Code; 283 end else begin 284 StartDlg.Translator.Language := nil; 285 LocaleCode := ''; 286 end; 277 287 FullScreen := (ButtonFullscreen.ButtonIndex and 1) = 1; 278 288 Gamma := LocalGamma; -
trunk/Start.pas
r385 r416 7 7 GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types, 8 8 LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, 9 Menus, Registry, DrawDlg, fgl, Protocol, UMiniMap, UBrain ;9 Menus, Registry, DrawDlg, fgl, Protocol, UMiniMap, UBrain, UTranslator; 10 10 11 11 type … … 133 133 procedure LoadConfig; 134 134 procedure SaveConfig; 135 procedure LoadLanguages; 135 136 procedure LoadAiBrainsPictures; 136 137 procedure UpdateInterface; … … 138 139 public 139 140 EmptyPicture: TBitmap; 141 Translator: TTranslator; 140 142 procedure UpdateFormerGames; 141 143 procedure UpdateMaps; … … 149 151 150 152 uses 151 Global, Directories, Direct, ScreenTools, Inp, Back, Settings, UKeyBindings; 153 Global, Directories, Direct, ScreenTools, Inp, Back, Settings, UKeyBindings, 154 ULanguages; 152 155 153 156 {$R *.lfm} … … 226 229 LoadConfig; 227 230 LoadAssets; 231 LoadLanguages; 228 232 229 233 ActionsOffered := [maConfig, maManual, maCredits, maWeb]; … … 325 329 begin 326 330 SaveConfig; 331 FreeAndNil(Translator); 327 332 FreeAndNil(FormerGames); 328 333 FreeAndNil(Maps); … … 454 459 455 460 KeyBindings.SaveToRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings'); 461 end; 462 463 procedure TStartDlg.LoadLanguages; 464 var 465 I: Integer; 466 begin 467 Translator := TTranslator.Create(nil); 468 with Translator, Languages do begin 469 AddNew('zh-Hant', 'Traditional Chinese'); 470 AddNew('zh-Hans', 'Simplified Chinese'); 471 SearchByCode('').Available := True; 472 473 for I := 1 to Languages.Count - 1 do 474 with Languages[I] do begin 475 Available := DirectoryExists(HomeDir + 'Localization' + DirectorySeparator + Code) or (Code = 'en'); 476 end; 477 end; 456 478 end; 457 479
Note:
See TracChangeset
for help on using the changeset viewer.