<commit_before>unit uLanguage;

interface

uses uTypes, Classes;

type
  TLanguage = class(TObject)
  private
    FID: TStringList;
    FValue: TStringList;
    FCurrent: string;
  public
    FSL: TStringList;
    function Get(const AValue: string): string;
    constructor Create;
    destructor Destroy; override;
    procedure Clear;
    procedure SaveLanguage;
    procedure LoadFromFile(AFileName: string);
    procedure SaveToFile(AFileName: string);
    procedure UseLanguage(ACurrentLanguage: string);
    property Current: string read FCurrent write FCurrent;
  end;

function _(const AValue: string): string;

implementation

uses SysUtils, uGame;

{ TLanguage }

function _(const AValue: string): string;
begin
  if Assigned(Game) then
  begin
    if Mode.Language then
      Game.Language.FSL.Append(AValue + '=');
    Result := Game.Language.Get(AValue);
  end else Result := AValue;
end;

procedure TLanguage.Clear;
begin
  FID.Clear;
  FValue.Clear;
end;

constructor TLanguage.Create;
begin
  FSL := TStringList.Create;
  FSL.Sorted := True;
  FSL.Duplicates := dupIgnore;
  FSL.LoadFromFile(Game.GetPath('languages') + 'default.lng');
  FID := TStringList.Create;
  FValue := TStringList.Create;
  FCurrent := 'en';
end;

destructor TLanguage.Destroy;
begin
  FreeAndNil(FValue);
  FreeAndNil(FID);
  FreeAndNil(FSL);
  inherited;
end;

procedure TLanguage.LoadFromFile(AFileName: string);
var
  S: string;
  I, J: Int;
  SL: TStringList;
begin
  if not FileExists(AFileName) then
    Exit;<commit_msg>Bug fix.<commit_after>unit uLanguage;

interface

uses uTypes, Classes;

type
  TLanguage = class(TObject)
  private
    FID: TStringList;
    FValue: TStringList;
    FCurrent: string;
  public
    FSL: TStringList;
    function Get(const AValue: string): string;
    constructor Create;
    destructor Destroy; override;
    procedure Clear;
    procedure SaveLanguage;
    procedure LoadFromFile(AFileName: string);
    procedure SaveToFile(AFileName: string);
    procedure UseLanguage(ACurrentLanguage: string);
    property Current: string read FCurrent write FCurrent;
  end;

function _(const AValue: string): string;

implementation

uses SysUtils, uGame;

{ TLanguage }

function _(const AValue: string): string;
begin
  if Assigned(Game) then
  begin
    if Mode.Language then
      Game.Language.FSL.Append(AValue + '=');
    Result := Game.Language.Get(AValue);
  end
  else
    Result := AValue;
end;

procedure TLanguage.Clear;
begin
  FID.Clear;
  FValue.Clear;
end;

constructor TLanguage.Create;
var
  F: string;
begin
  FSL := TStringList.Create;
  FSL.Sorted := True;
  FSL.Duplicates := dupIgnore;
  F := Game.GetPath('languages') + 'default.lng';
  if FileExists(F) then
    FSL.LoadFromFile(F);
  FID := TStringList.Create;
  FValue := TStringList.Create;
  FCurrent := 'en';
end;

destructor TLanguage.Destroy;
begin
  FreeAndNil(FValue);
  FreeAndNil(FID);
  FreeAndNil(FSL);
  inherited;
end;

procedure TLanguage.LoadFromFile(AFileName: string);
var
  S: string;
  I, J: Int;
  SL: TStringList;
begin
  if not FileExists(AFileName) then
    Exit;
{'fraction_non_alphanumeric': 0.1034928848641656, 'fraction_numerical': 0.0, 'mean_word_length': 4.053921568627451, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5953148', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1029, 'n_words': 268}