hedgewars/uLocale.pas
changeset 2693 3207e0eacd43
parent 2630 079ef82eac75
child 2716 b9ca1bfca24f
equal deleted inserted replaced
2692:ce9992075118 2693:3207e0eacd43
    45 function Format(fmt: shortstring; var arg: shortstring): shortstring;
    45 function Format(fmt: shortstring; var arg: shortstring): shortstring;
    46 
    46 
    47 function GetEventString(e: TEventId): string;
    47 function GetEventString(e: TEventId): string;
    48 
    48 
    49 implementation
    49 implementation
    50 uses uMisc, uRandom;
    50 uses uMisc, uRandom, uConsole;
    51 
    51 
    52 var	trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of string;
    52 var	trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of string;
    53 	trevt_n: array[TEventId] of integer;
    53 	trevt_n: array[TEventId] of integer;
    54 
    54 
    55 procedure LoadLocale(FileName: string);
    55 procedure LoadLocale(FileName: string);
    60 	e: TEventId;
    60 	e: TEventId;
    61 begin
    61 begin
    62 trammo[sidNothing]:= ' ';
    62 trammo[sidNothing]:= ' ';
    63 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
    63 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
    64 
    64 
    65 {$I-}
    65 {$I-} //iochecks off
       
    66 filemode:=0; //readonly
    66 Assign(f, FileName);
    67 Assign(f, FileName);
    67 reset(f);
    68 reset(f);
    68 TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', true);
    69 // if the locale does not exist, fallback to the default one
       
    70 if (IOResult <> 0) then
       
    71 begin
       
    72 	WriteLnToConsole('Warning: Cannot load selected locale "' + FileName + '" fallback to default en.txt');
       
    73 	Assign(f, 'en.txt');
       
    74 	reset(f);
       
    75 end;
       
    76 
       
    77 TryDo(IOResult = 0, 'Cannot load locale "' + FileName + ' nor en.txt"', true);
    69 while not eof(f) do
    78 while not eof(f) do
    70 	begin
    79 	begin
    71 	readln(f, s);
    80 	readln(f, s);
    72 	if Length(s) = 0 then continue;
    81 	if Length(s) = 0 then continue;
    73 	if not (s[1] in ['0'..'9']) then continue;
    82 	if not (s[1] in ['0'..'9']) then continue;