Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2002.03.25;
Скачать: [xml.tar.bz2];

Вниз

Помогите перевести компонент из D5 в CB5   Найти похожие ветки 

 
Aser17   (2002-03-08 06:22) [0]

unit janLanguage;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,TypInfo,Inifiles;

type
TjanLanguage = class(TComponent)
private
LanguageFile:string;
procedure LoadLanguage(AForm: TForm; Afile: string);
procedure SaveLanguage(AForm: TForm; Afile: string);
function appldir: string;
function inifile: string;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
procedure InitLanguage(AForm:TForm);
procedure ChangeLanguage(AForm:Tform);
published
{ Published declarations }
end;

procedure Register;

implementation

const
cr = chr(13)+chr(10);
tab = chr(9);

procedure Register;
begin
RegisterComponents("Jans 2", [TjanLanguage]);
end;

function TjanLanguage.appldir:string;
begin
result:=extractfilepath(application.exename);
end;

function TjanLanguage.inifile:string;
begin
result:=changefileext(application.exename,".ini");
end;

procedure TjanLanguage.ChangeLanguage(AForm: Tform);
var
ini:TIniFile;
od:TOpendialog;
begin
od:=TOpendialog.Create(self) ;
od.InitialDir :=appldir;
od.Filter :="Language Files |*.lng";
if od.Execute then
begin
LanguageFile:=od.FileName ;
ini:=TInifile.Create (inifile);
ini.WriteString ("Language",Aform.name,LanguageFile);
ini.free;
LoadLanguage (Aform,LanguageFile)
end;
od.free;
end;

procedure TjanLanguage.InitLanguage(AForm: TForm);
var
ini:TIniFile;
begin
LanguageFile:=appldir+"Language.lng";
SaveLanguage (Aform,LanguageFile);
ini:=TInifile.Create (inifile);
LanguageFile:=ini.readString ("Language",Aform.name,LanguageFile);
if fileexists(LanguageFile) then
LoadLanguage (Aform,LanguageFile);
ini.WriteString ("Language",Aform.name,LanguageFile);
ini.free;
end;

procedure TjanLanguage.LoadLanguage(AForm:TForm;Afile:string);
var c:Tcomponent;
ini:tinifile;
langfile:string;
langs:TStringlist;
i,p:integer;
aname,avalue:string;
afrm,acomp,aprop:string;
AComponent:Tcomponent;
PropInfo:PPropInfo;

procedure split(s:string);
var p:integer;
begin
p:=pos("=",s);
aname:=copy(s,1,p-1);
avalue:=copy(s,p+1,length(s));
avalue:=stringreplace(avalue,"~~",cr,[rfreplaceall]);
p:=pos(".",aname);
afrm:=copy(aname,1,p-1);
aname:=copy(aname,p+1,length(aname));
p:=pos(".",aname);
acomp:=copy(aname,1,p-1);
aprop:=copy(aname,p+1,length(aname));
end;
begin
langfile:=Afile;
ini:=tinifile.Create (langfile);
langs:=tstringlist.create;
ini.ReadSectionValues ("TRANSLATIONS",langs);
if langs.Count >0 then
begin
for i:=0 to langs.count-1 do
begin
split(langs[i]);
if Aform.name<>Afrm then continue;
AComponent:=Aform.findcomponent(acomp);
if AComponent= nil then continue;
PropInfo:=GetPropInfo(Acomponent,aprop);
if PropInfo<>nil then
if propinfo^.PropType^.Kind= tkLString then
setStrProp(Acomponent,aprop,avalue);
end;
end;
ini.free;
langs.free;
end;

procedure TjanLanguage.SaveLanguage(AForm:TForm;Afile:string);
var
i:integer;
langini:TInifile;
LangFile:string;
acap:string;
ahint:string;
atext:string;
PropInfo:PPropInfo;
m:Tcomponent;
begin
LangFile:=Afile;
langini:=TInifile.Create(LangFile);
for i:=0 to Aform.ComponentCount-1 do
begin
m:=Aform.components[i];
PropInfo:=GetPropInfo(m,"caption");
if PropInfo<>nil then
begin
acap:=GetStrProp(m,PropInfo);
acap:=stringreplace(acap,cr,"~~",[rfreplaceall]);
if ((acap<>"")and(acap<>"-")) then
Langini.WriteString ("Translations",AForm.name+"."+m.name+".Caption",acap)
end;
PropInfo:=GetPropInfo(m,"hint");
if PropInfo<>nil then
begin
ahint:=GetStrProp(m,PropInfo);
ahint:=stringreplace(ahint,cr,"~~",[rfreplaceall]);
if ahint<>"" then
Langini.WriteString ("Translations",AForm.name+"."+m.name+".Hint",ahint)
end;
PropInfo:=GetPropInfo(m,"text");
if PropInfo<>nil then
begin
atext:=GetStrProp(m,PropInfo);
atext:=stringreplace(atext,cr,"~~",[rfreplaceall]);
if atext<>"" then
Langini.WriteString ("Translations",AForm.name+"."+m.name+".Text",atext)
end;
end;
Langini.Free;
end;


end.



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2002.03.25;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.005 c
6-80637
Jam
2002-01-09 13:29
2002.03.25
ClientSocket отправка


1-80563
Alev
2002-03-08 11:01
2002.03.25
Как удалить файл минуя корзины


3-80443
prorok
2002-02-27 13:51
2002.03.25
Индексирование


3-80406
pilot
2002-02-26 07:18
2002.03.25
Считывание текста в базу


1-80491
dimmu
2002-03-06 10:06
2002.03.25
Работа с классами в Delphi





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский