텍스트를 저장시 UTF-8로 저장 안하면 타언어에서는 100% 읽기 어렵습니다.
만약 UTF-8코드로 저장하면 UTF8Decode로해서 타언어OS에서 읽으면 되는데,
보통 안씨로했다면 읽기는하되 100%번역이 안됩니다
아래 테스트는
1. UTF-8가 로저장하지 않은 한국어텍스트를 일본어OS에서 읽기입니다
2. UTF-8가 로저장하지 않은 일본어텍스트를 한국어OS에서 읽기입니다
3. UTF-8가 로저장란 일본어텍스트를 한국어OS에서 읽기입니다
3번은 Unicode컴포넌트를 사용하면 읽어집니다
필요한 예제 텍스트 파일은 자료실에 예제로 등록합니다
{$R *.dfm}
////////////////////////////////////////////////////////////////////////////////
constructor UnicodeResClass.Create;
begin
resourceStringList := TList.Create;
end;
destructor UnicodeResClass.Destroy;
begin
Clear;
resourceStringList.Free;
inherited;
end;
procedure UnicodeResClass.LoadResourceStr(stream: TStream; UniCodeOK :Boolean);
var
strings : TStringList;
i : integer;
index : integer;
aRecord : TranslateListRecordPointer;
s : WideString;
begin
Clear;
if stream <> nil then begin
strings := TStringList.Create;
strings.LoadFromStream(stream);
i := 0;
while i < strings.Count do begin
if UniCodeOK then s := UTF8Decode(strings[i])
else s := (strings[i]);
New(aRecord);
aRecord.RecordText := s;
resourceStringList.Add(aRecord);
if not TryStrToInt(Copy(s,pos('=',s)+1,length(s)), index) then
aRecord.ID := -1
else
aRecord.ID := index;
Inc(i);
end;
strings.Free;
end;
end;
procedure UnicodeResClass.Clear;
var
i : integer;
begin
for i := 0 to resourceStringList.Count - 1 do
Dispose(TranslateListRecordPointer(resourceStringList[i]));
resourceStringList.Clear;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
var
GDK30Res : UnicodeResClass;
resourceStream : TFileStream;
i : integer;
aRecord : TranslateListRecordPointer;
begin
Memo1.Font.Charset := HANGEUL_CHARSET;//SHIFTJIS_CHARSET;
Memo1.Font.Name := 'MS Sans Serif'; //'MS Pゴシック'
GDK30Res := UnicodeResClass.Create;
GDK30Res.Clear;
resourceStream := TFileStream.Create(ExtractFilePath(Forms.Application.ExeName) + 'TransLang1042.lng', fmOpenRead);
GDK30Res.LoadResourceStr(resourceStream, False);
for i := 0 to GDK30Res.resourceStringList.Count-1 do begin
aRecord := GDK30Res.ResourceStringList[i];
if aRecord <> nil then
Memo1.Lines.Add(aRecord.RecordText);
end;
resourceStream.Free;
GDK30Res.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
GDK30Res : UnicodeResClass;
resourceStream : TFileStream;
i : integer;
aRecord : TranslateListRecordPointer;
begin
Memo1.Font.Charset := SHIFTJIS_CHARSET;
Memo1.Font.Name := 'MS Pゴシック';
GDK30Res := UnicodeResClass.Create;
GDK30Res.Clear;
resourceStream := TFileStream.Create(ExtractFilePath(Forms.Application.ExeName) + 'TransLang1041.lng', fmOpenRead);
GDK30Res.LoadResourceStr(resourceStream, False);
for i := 0 to GDK30Res.resourceStringList.Count-1 do begin
aRecord := GDK30Res.ResourceStringList[i];
if aRecord <> nil then
Memo1.Lines.Add(aRecord.RecordText);
end;
resourceStream.Free;
GDK30Res.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
GDK30Res : UnicodeResClass;
resourceStream : TFileStream;
i : integer;
aRecord : TranslateListRecordPointer;
begin
Memo1.Font.Charset := SHIFTJIS_CHARSET;
Memo1.Font.Name := 'MS Pゴシック';
GDK30Res := UnicodeResClass.Create;
GDK30Res.Clear;
resourceStream := TFileStream.Create(ExtractFilePath(Forms.Application.ExeName) + 'ResourceStrings.txt', fmOpenRead);
GDK30Res.LoadResourceStr(resourceStream, True);
for i := 0 to GDK30Res.resourceStringList.Count-1 do begin
aRecord := GDK30Res.ResourceStringList[i];
if aRecord <> nil then
Memo1.Lines.Add(aRecord.RecordText);
end;
resourceStream.Free;
GDK30Res.Free;
end;
그렇지요.잠깐 해보려다 지금 조금 바빠서리..디폴드론 어렵네요.
만약에 압축 파일안에 헤더가 있다면 그 헤더에 UTF-8형식으로 파일명리스트가 있다면
위의 3번 예제에서 (TForm1.Button3Click) 처럼 읽어서 TntMemo로 읽은후 에 그메모장에서 읽으면 안되나 싶네요...
해보지 않아서요...탐색기나 워드등 처럼 파일명을 읽는 방법만 알면 저도 써먹을때 많은데....
만약 UTF-8코드로 저장하면 UTF8Decode로해서 타언어OS에서 읽으면 되는데,
보통 안씨로했다면 읽기는하되 100%번역이 안됩니다
아래 테스트는
1. UTF-8가 로저장하지 않은 한국어텍스트를 일본어OS에서 읽기입니다
2. UTF-8가 로저장하지 않은 일본어텍스트를 한국어OS에서 읽기입니다
3. UTF-8가 로저장란 일본어텍스트를 한국어OS에서 읽기입니다
3번은 Unicode컴포넌트를 사용하면 읽어집니다
필요한 예제 텍스트 파일은 자료실에 예제로 등록합니다
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TranslateListRecord = record
ID : int64;
RecordText : WideString;
end;
TranslateListRecordPointer = ^TranslateListRecord;
UnicodeResClass = class
resourceStringList : TList;
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure LoadResourceStr(stream : TStream; UniCodeOK :Boolean);
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
////////////////////////////////////////////////////////////////////////////////
constructor UnicodeResClass.Create;
begin
resourceStringList := TList.Create;
end;
destructor UnicodeResClass.Destroy;
begin
Clear;
resourceStringList.Free;
inherited;
end;
procedure UnicodeResClass.LoadResourceStr(stream: TStream; UniCodeOK :Boolean);
var
strings : TStringList;
i : integer;
index : integer;
aRecord : TranslateListRecordPointer;
s : WideString;
begin
Clear;
if stream <> nil then begin
strings := TStringList.Create;
strings.LoadFromStream(stream);
i := 0;
while i < strings.Count do begin
if UniCodeOK then s := UTF8Decode(strings[i])
else s := (strings[i]);
New(aRecord);
aRecord.RecordText := s;
resourceStringList.Add(aRecord);
if not TryStrToInt(Copy(s,pos('=',s)+1,length(s)), index) then
aRecord.ID := -1
else
aRecord.ID := index;
Inc(i);
end;
strings.Free;
end;
end;
procedure UnicodeResClass.Clear;
var
i : integer;
begin
for i := 0 to resourceStringList.Count - 1 do
Dispose(TranslateListRecordPointer(resourceStringList[i]));
resourceStringList.Clear;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
var
GDK30Res : UnicodeResClass;
resourceStream : TFileStream;
i : integer;
aRecord : TranslateListRecordPointer;
begin
Memo1.Font.Charset := HANGEUL_CHARSET;//SHIFTJIS_CHARSET;
Memo1.Font.Name := 'MS Sans Serif'; //'MS Pゴシック'
GDK30Res := UnicodeResClass.Create;
GDK30Res.Clear;
resourceStream := TFileStream.Create(ExtractFilePath(Forms.Application.ExeName) + 'TransLang1042.lng', fmOpenRead);
GDK30Res.LoadResourceStr(resourceStream, False);
for i := 0 to GDK30Res.resourceStringList.Count-1 do begin
aRecord := GDK30Res.ResourceStringList[i];
if aRecord <> nil then
Memo1.Lines.Add(aRecord.RecordText);
end;
resourceStream.Free;
GDK30Res.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
GDK30Res : UnicodeResClass;
resourceStream : TFileStream;
i : integer;
aRecord : TranslateListRecordPointer;
begin
Memo1.Font.Charset := SHIFTJIS_CHARSET;
Memo1.Font.Name := 'MS Pゴシック';
GDK30Res := UnicodeResClass.Create;
GDK30Res.Clear;
resourceStream := TFileStream.Create(ExtractFilePath(Forms.Application.ExeName) + 'TransLang1041.lng', fmOpenRead);
GDK30Res.LoadResourceStr(resourceStream, False);
for i := 0 to GDK30Res.resourceStringList.Count-1 do begin
aRecord := GDK30Res.ResourceStringList[i];
if aRecord <> nil then
Memo1.Lines.Add(aRecord.RecordText);
end;
resourceStream.Free;
GDK30Res.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
GDK30Res : UnicodeResClass;
resourceStream : TFileStream;
i : integer;
aRecord : TranslateListRecordPointer;
begin
Memo1.Font.Charset := SHIFTJIS_CHARSET;
Memo1.Font.Name := 'MS Pゴシック';
GDK30Res := UnicodeResClass.Create;
GDK30Res.Clear;
resourceStream := TFileStream.Create(ExtractFilePath(Forms.Application.ExeName) + 'ResourceStrings.txt', fmOpenRead);
GDK30Res.LoadResourceStr(resourceStream, True);
for i := 0 to GDK30Res.resourceStringList.Count-1 do begin
aRecord := GDK30Res.ResourceStringList[i];
if aRecord <> nil then
Memo1.Lines.Add(aRecord.RecordText);
end;
resourceStream.Free;
GDK30Res.Free;
end;
end.