Einzelnen Beitrag anzeigen

Wishmaster

Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
 
Delphi XE2 Architect
 
#9

AW: Ini als Sprachdatei nutzen ?

  Alt 23. Jun 2011, 04:53
Hi

ich benutze XML für die Sprach und Programm Einstellungen
dabei kannst du all sprachen in die selbe Datei stecken wen du willst.

Delphi-Quellcode:
unit Language_Classe;

interface
 uses SysUtils, NativeXml;


Function Language_Load_File(const FileName : String) : Boolean;
Function Language_UnLoad_File() : Boolean;
Function Language_Loaded(): boolean;
Function Language_Get_Text(LangID : UTF8String; LangName : UnicodeString) : Widestring;



implementation

var LanguageFile : TNativeXml;
    Loaded : boolean = false;

(***************************** Load Language File *****************************)

Function Language_Load_File(const FileName : String) : Boolean;
begin
  Result:= false;

 if not FileExists(FileName) then
  exit;

 if Loaded then
  begin
   if (Assigned(LanguageFile)) then
    begin
     FreeAndNil(LanguageFile);
     Loaded:= false;
    end;
  end;


 try
   LanguageFile:= TNativeXml.CreateName('Language');
   LanguageFile.LoadFromFile(Filename);
  if (Assigned(LanguageFile)) then
   begin
    Loaded:= true;
    Result:= true;
   end;
 except // Could not load the language file'
   on E: Exception do
    begin
     if (Assigned(LanguageFile)) then
      FreeAndNil(LanguageFile);
      Loaded:= false;
      Result:= false;
      Exit;
    end;
 end;
end;

(**************************** UnLoad Language File ****************************)

Function Language_UnLoad_File() : Boolean;
begin
  Result:= false;

 if Loaded then
  begin
  if (Assigned(LanguageFile)) then
   begin
    FreeAndNil(LanguageFile);
    Result:= true;
    Loaded:= false;
   end;
  end;
end;

(*************************** IsLoadded Language File **************************)

Function Language_Loaded(): boolean;
begin
  Result:= Loaded;
end;

(***************************** Load Language File *****************************)
(*
  NodeByName('LangID').ReadString('ID_INF_0001=');
  NodeByName('LangID').ReadString('ID_OBJ_0001=');
*)


Function Language_Get_Text(LangID : UTF8String; LangName : UnicodeString) : Widestring;
var Str : Widestring;
begin
   Result:= '';

 if Loaded then
  begin
   With LanguageFile.Root do
    begin
      Str:= NodeByName(LangID).ReadUnicodeString(LangName);
     if (Trim(Str) = '') or (Length(Str) = 0) then
      Result:= ''
     else
      Result:= Str;
    end;
  end;
end;


end.
Code:
<?xml version="1.0" encoding="UTF-16"?>
<Language>
  <Info>
    <ID_INF_0001=>Wishmaster</ID_INF_0001=>
    <ID_INF_0002=>1.0</ID_INF_0002=>
    <ID_INF_0003=>support@blabla.com</ID_INF_0003=>
    <ID_INF_0004=>User</ID_INF_0004=>
    <ID_INF_0005=>User</ID_INF_0005=>
  </Info>
  <LangID>
   <!-- Mein Form -->
    <ID_OBJ_0001=>Drive</ID_OBJ_0001=>
    <ID_OBJ_0002=>Drive Action</ID_OBJ_0002=>
    <ID_OBJ_0003=>Close</ID_OBJ_0003=>
    <ID_OBJ_0004=>Eject</ID_OBJ_0004=>
    <ID_OBJ_0005=>Lock</ID_OBJ_0005=>
    <ID_OBJ_0006=>Unlock</ID_OBJ_0006=>
    <ID_OBJ_0007=>CDDB</ID_OBJ_0007=>   
    <ID_OBJ_0008=>Read CD-Text</ID_OBJ_0008=>   
    <ID_OBJ_0009=>Read Remote freedb</ID_OBJ_0009=>
    <ID_OBJ_0010=>Read From CD Player.ini</ID_OBJ_0010=>


     blablabla
  Mit Zitat antworten Zitat