mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 13:19:28 +02:00
LCLTranslator: simplified FindLocaleFileName function by removing GetLocaleFileName nested function from it (no functional changes)
git-svn-id: trunk@61591 -
This commit is contained in:
parent
28f83647db
commit
4d435d832b
@ -123,141 +123,108 @@ begin
|
|||||||
LazGetLanguageIDs(Lang, T);
|
LazGetLanguageIDs(Lang, T);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FindLocaleFileName(LCExt: string; Lang: string; Dir: string; LocaleFileName: string): string;
|
function FindLocaleFileName(LCExt: string; LangID: string; Dir: string; LocaleFileName: string): string;
|
||||||
|
var
|
||||||
|
LangShortID: string;
|
||||||
|
AppDir,LCFileName,FullLCFileName: String;
|
||||||
|
absoluteDir: Boolean;
|
||||||
|
|
||||||
function GetLocaleFileName(const LangID, LCExt: string; Dir: string; LocaleFileName: string): string;
|
function GetLCFileName: string;
|
||||||
var
|
begin
|
||||||
LangShortID: string;
|
if LocaleFileName = '' then
|
||||||
AppDir,LCFileName,FullLCFileName: String;
|
Result := ExtractFileName(ParamStrUTF8(0))
|
||||||
absoluteDir: Boolean;
|
else
|
||||||
|
Result := LocaleFileName;
|
||||||
|
end;
|
||||||
|
|
||||||
function GetLCFileName: string;
|
begin
|
||||||
|
Result := '';
|
||||||
|
FindLang(LangID);
|
||||||
|
|
||||||
|
DefaultLang := LangID;
|
||||||
|
|
||||||
|
AppDir := ExtractFilePath(ParamStrUTF8(0));
|
||||||
|
LCFileName := ChangeFileExt(GetLCFileName, LCExt);
|
||||||
|
|
||||||
|
if LangID <> '' then
|
||||||
|
begin
|
||||||
|
FullLCFileName := ChangeFileExt(GetLCFileName, '.' + LangID) + LCExt;
|
||||||
|
|
||||||
|
if Dir<>'' then
|
||||||
begin
|
begin
|
||||||
if LocaleFileName = '' then
|
Dir := AppendPathDelim(Dir);
|
||||||
Result := ExtractFileName(ParamStrUTF8(0))
|
absoluteDir := FilenameIsAbsolute(Dir);
|
||||||
|
if absoluteDir then
|
||||||
|
Result := Dir + LangID + DirectorySeparator + LCFileName
|
||||||
else
|
else
|
||||||
Result := LocaleFileName;
|
Result := AppDir + Dir + LangID + DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
//ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
|
||||||
DefaultLang := LangID;
|
Result := AppDir + LangID + DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
AppDir := ExtractFilePath(ParamStrUTF8(0));
|
Result := AppDir + 'languages' + DirectorySeparator + LangID +
|
||||||
LCFileName := ChangeFileExt(GetLCFileName, LCExt);
|
DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
if LangID <> '' then
|
Result := AppDir + 'locale' + DirectorySeparator + LangID +
|
||||||
|
DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
Result := AppDir + 'locale' + DirectorySeparator + LangID +
|
||||||
|
DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
{$IFDEF UNIX}
|
||||||
|
//In unix-like systems we can try to search for global locale
|
||||||
|
Result := '/usr/share/locale/' + LangID + '/LC_MESSAGES/' + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
{$ENDIF}
|
||||||
|
//Let us search for short id files
|
||||||
|
LangShortID := copy(LangID, 1, 2);
|
||||||
|
Defaultlang := LangShortID;
|
||||||
|
|
||||||
|
if Dir<>'' then
|
||||||
begin
|
begin
|
||||||
FullLCFileName := ChangeFileExt(GetLCFileName, '.' + LangID) + LCExt;
|
if absoluteDir then
|
||||||
|
Result := Dir + LangShortID + DirectorySeparator + LCFileName
|
||||||
if Dir<>'' then
|
else
|
||||||
begin
|
Result := AppDir + Dir + LangShortID + DirectorySeparator + LCFileName;
|
||||||
Dir := AppendPathDelim(Dir);
|
|
||||||
absoluteDir := FilenameIsAbsolute(Dir);
|
|
||||||
if absoluteDir then
|
|
||||||
Result := Dir + LangID + DirectorySeparator + LCFileName
|
|
||||||
else
|
|
||||||
Result := AppDir + Dir + LangID + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
//ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
|
|
||||||
Result := AppDir + LangID + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
Result := AppDir + 'languages' + DirectorySeparator + LangID +
|
//At first, check all was checked
|
||||||
DirectorySeparator + LCFileName;
|
Result := AppDir + LangShortID + DirectorySeparator + LCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
Result := AppDir + 'locale' + DirectorySeparator + LangID +
|
Result := AppDir + 'languages' + DirectorySeparator +
|
||||||
DirectorySeparator + LCFileName;
|
LangShortID + DirectorySeparator + LCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
Result := AppDir + 'locale' + DirectorySeparator + LangID +
|
Result := AppDir + 'locale' + DirectorySeparator
|
||||||
DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
|
+ LangShortID + DirectorySeparator + LCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
{$IFDEF UNIX}
|
Result := AppDir + 'locale' + DirectorySeparator + LangShortID +
|
||||||
//In unix-like systems we can try to search for global locale
|
DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
|
||||||
Result := '/usr/share/locale/' + LangID + '/LC_MESSAGES/' + LCFileName;
|
if FileExistsUTF8(Result) then
|
||||||
if FileExistsUTF8(Result) then
|
exit;
|
||||||
exit;
|
|
||||||
{$ENDIF}
|
|
||||||
//Let us search for short id files
|
|
||||||
LangShortID := copy(LangID, 1, 2);
|
|
||||||
Defaultlang := LangShortID;
|
|
||||||
|
|
||||||
if Dir<>'' then
|
|
||||||
begin
|
|
||||||
if absoluteDir then
|
|
||||||
Result := Dir + LangShortID + DirectorySeparator + LCFileName
|
|
||||||
else
|
|
||||||
Result := AppDir + Dir + LangShortID + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
//At first, check all was checked
|
|
||||||
Result := AppDir + LangShortID + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
Result := AppDir + 'languages' + DirectorySeparator +
|
|
||||||
LangShortID + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
Result := AppDir + 'locale' + DirectorySeparator
|
|
||||||
+ LangShortID + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
Result := AppDir + 'locale' + DirectorySeparator + LangShortID +
|
|
||||||
DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
//Full language in file name - this will be default for the project
|
|
||||||
//We need more careful handling, as it MAY result in incorrect filename
|
|
||||||
try
|
|
||||||
if Dir<>'' then
|
|
||||||
begin
|
|
||||||
if absoluteDir then
|
|
||||||
Result := Dir + FullLCFileName
|
|
||||||
else
|
|
||||||
Result := AppDir + Dir + FullLCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Result := AppDir + FullLCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
//Common location (like in Lazarus)
|
|
||||||
Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
except
|
|
||||||
Result := '';//Or do something else (useless)
|
|
||||||
end;
|
|
||||||
{$IFDEF UNIX}
|
|
||||||
Result := '/usr/share/locale/' + LangShortID + '/LC_MESSAGES/' +
|
|
||||||
LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
|
||||||
exit;
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
FullLCFileName := ChangeFileExt(GetLCFileName, '.' + LangShortID) + LCExt;
|
|
||||||
|
|
||||||
|
//Full language in file name - this will be default for the project
|
||||||
|
//We need more careful handling, as it MAY result in incorrect filename
|
||||||
|
try
|
||||||
if Dir<>'' then
|
if Dir<>'' then
|
||||||
begin
|
begin
|
||||||
if absoluteDir then
|
if absoluteDir then
|
||||||
@ -272,6 +239,7 @@ function FindLocaleFileName(LCExt: string; Lang: string; Dir: string; LocaleFile
|
|||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
//Common location (like in Lazarus)
|
||||||
Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
|
Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
@ -279,33 +247,59 @@ function FindLocaleFileName(LCExt: string; Lang: string; Dir: string; LocaleFile
|
|||||||
Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
|
Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
except
|
||||||
|
Result := '';//Or do something else (useless)
|
||||||
|
end;
|
||||||
|
{$IFDEF UNIX}
|
||||||
|
Result := '/usr/share/locale/' + LangShortID + '/LC_MESSAGES/' +
|
||||||
|
LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
FullLCFileName := ChangeFileExt(GetLCFileName, '.' + LangShortID) + LCExt;
|
||||||
|
|
||||||
|
if Dir<>'' then
|
||||||
|
begin
|
||||||
|
if absoluteDir then
|
||||||
|
Result := Dir + FullLCFileName
|
||||||
|
else
|
||||||
|
Result := AppDir + Dir + FullLCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//master files have .pot extension
|
Result := AppDir + FullLCFileName;
|
||||||
if LCExt = '.po' then
|
|
||||||
LCFileName := ChangeFileExt(GetLCFileName, '.pot');
|
|
||||||
|
|
||||||
Result := AppDir + LCFileName;
|
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
Result := AppDir + 'locale' + DirectorySeparator + LCFileName;
|
Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
Result := AppDir + 'languages' + DirectorySeparator + LCFileName;
|
Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
|
||||||
if FileExistsUTF8(Result) then
|
if FileExistsUTF8(Result) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
Result := '';
|
|
||||||
DefaultLang := '';
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
//master files have .pot extension
|
||||||
Result := '';
|
if LCExt = '.po' then
|
||||||
FindLang(Lang);
|
LCFileName := ChangeFileExt(GetLCFileName, '.pot');
|
||||||
|
|
||||||
Result := GetLocaleFileName(Lang, LCExt, Dir, LocaleFileName);
|
Result := AppDir + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
Result := AppDir + 'locale' + DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
Result := AppDir + 'languages' + DirectorySeparator + LCFileName;
|
||||||
|
if FileExistsUTF8(Result) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
Result := '';
|
||||||
|
DefaultLang := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetIdentifierPath(Sender: TObject;
|
function GetIdentifierPath(Sender: TObject;
|
||||||
|
Loading…
Reference in New Issue
Block a user