mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 11:01:20 +02:00
LCLTranslator: allow to optionally specify the name of translation file. Based on patch by Alfred, bug #34836. As SetDefaultLang signature is changed (in order to not force users specify 'obscure' ForceUpdate parameter if they want to set translation name), adapted DefaultTranslator unit to these changes.
git-svn-id: trunk@60097 -
This commit is contained in:
parent
cd32b50fa8
commit
114df2b6b6
@ -35,6 +35,6 @@ implementation
|
|||||||
initialization
|
initialization
|
||||||
//It is safe to place code here as no form is initialized before unit
|
//It is safe to place code here as no form is initialized before unit
|
||||||
//initialization is made
|
//initialization is made
|
||||||
SetDefaultLang('', '', false);
|
SetDefaultLang('', '', '', false);
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -80,7 +80,7 @@ type
|
|||||||
PropInfo: PPropInfo; var Content: string); override;
|
PropInfo: PPropInfo; var Content: string); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetDefaultLang(Lang: string; Dir: string = ''; ForceUpdate: boolean = true);
|
procedure SetDefaultLang(Lang: string; Dir: string = ''; LocaleFileName: string = ''; ForceUpdate: boolean = true);
|
||||||
function GetDefaultLang: String;
|
function GetDefaultLang: String;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -92,25 +92,34 @@ type
|
|||||||
var
|
var
|
||||||
DefaultLang: String = '';
|
DefaultLang: String = '';
|
||||||
|
|
||||||
function FindLocaleFileName(LCExt: string; Lang: string; Dir: string): string;
|
function FindLocaleFileName(LCExt: string; Lang: string; Dir: string; LocaleFileName: string): string;
|
||||||
var
|
var
|
||||||
T: string;
|
T: string;
|
||||||
i: integer;
|
i: integer;
|
||||||
|
|
||||||
function GetLocaleFileName(const LangID, LCExt: string; Dir: string): string;
|
function GetLocaleFileName(const LangID, LCExt: string; Dir: string; LocaleFileName: string): string;
|
||||||
var
|
var
|
||||||
LangShortID: string;
|
LangShortID: string;
|
||||||
AppDir,LCFileName,FullLCFileName: String;
|
AppDir,LCFileName,FullLCFileName: String;
|
||||||
absoluteDir: Boolean;
|
absoluteDir: Boolean;
|
||||||
|
|
||||||
|
function GetLCFileName: string;
|
||||||
|
begin
|
||||||
|
if LocaleFileName = '' then
|
||||||
|
Result := ExtractFileName(ParamStrUTF8(0))
|
||||||
|
else
|
||||||
|
Result := LocaleFileName;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
DefaultLang := LangID;
|
DefaultLang := LangID;
|
||||||
|
|
||||||
AppDir := ExtractFilePath(ParamStrUTF8(0));
|
AppDir := ExtractFilePath(ParamStrUTF8(0));
|
||||||
LCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
|
LCFileName := ChangeFileExt(GetLCFileName, LCExt);
|
||||||
|
|
||||||
if LangID <> '' then
|
if LangID <> '' then
|
||||||
begin
|
begin
|
||||||
FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
|
FullLCFileName := ChangeFileExt(GetLCFileName, '.' + LangID) + LCExt;
|
||||||
|
|
||||||
if Dir<>'' then
|
if Dir<>'' then
|
||||||
begin
|
begin
|
||||||
@ -219,7 +228,7 @@ var
|
|||||||
exit;
|
exit;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
|
FullLCFileName := ChangeFileExt(GetLCFileName, '.' + LangShortID) + LCExt;
|
||||||
|
|
||||||
if Dir<>'' then
|
if Dir<>'' then
|
||||||
begin
|
begin
|
||||||
@ -276,7 +285,7 @@ begin
|
|||||||
if Lang = '' then
|
if Lang = '' then
|
||||||
LazGetLanguageIDs(Lang, T);
|
LazGetLanguageIDs(Lang, T);
|
||||||
|
|
||||||
Result := GetLocaleFileName(Lang, LCExt, Dir);
|
Result := GetLocaleFileName(Lang, LCExt, Dir, LocaleFileName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetIdentifierPath(Sender: TObject;
|
function GetIdentifierPath(Sender: TObject;
|
||||||
@ -502,10 +511,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetDefaultLang(Lang: string; Dir: string = ''; ForceUpdate: boolean = true);
|
procedure SetDefaultLang(Lang: string; Dir: string = ''; LocaleFileName: string = ''; ForceUpdate: boolean = true);
|
||||||
{ Arguments:
|
{ Arguments:
|
||||||
Lang - language (e.g. 'ru', 'de'); empty argument is default language.
|
Lang - language (e.g. 'ru', 'de'); empty argument is default language.
|
||||||
Dir - custom translation files subdirectory (e.g. 'mylng'); empty argument means searching only in predefined subdirectories.
|
Dir - custom translation files subdirectory (e.g. 'mylng'); empty argument means searching only in predefined subdirectories.
|
||||||
|
LocaleFileName - custom translation file name; empty argument means that the name is the same as the one of executable.
|
||||||
ForceUpdate - true means forcing immediate interface update. Only should be set to false when the procedure is
|
ForceUpdate - true means forcing immediate interface update. Only should be set to false when the procedure is
|
||||||
called from unit Initialization section. User code normally should not specify it.
|
called from unit Initialization section. User code normally should not specify it.
|
||||||
}
|
}
|
||||||
@ -519,7 +529,7 @@ begin
|
|||||||
LocalTranslator := nil;
|
LocalTranslator := nil;
|
||||||
// search first po translation resources
|
// search first po translation resources
|
||||||
try
|
try
|
||||||
lcfn := FindLocaleFileName('.po', Lang, Dir);
|
lcfn := FindLocaleFileName('.po', Lang, Dir, LocaleFileName);
|
||||||
if lcfn <> '' then
|
if lcfn <> '' then
|
||||||
begin
|
begin
|
||||||
Translations.TranslateResourceStrings(lcfn);
|
Translations.TranslateResourceStrings(lcfn);
|
||||||
@ -541,7 +551,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
// try now with MO translation resources
|
// try now with MO translation resources
|
||||||
try
|
try
|
||||||
lcfn := FindLocaleFileName('.mo', Lang, Dir);
|
lcfn := FindLocaleFileName('.mo', Lang, Dir, LocaleFileName);
|
||||||
if lcfn <> '' then
|
if lcfn <> '' then
|
||||||
begin
|
begin
|
||||||
GetText.TranslateResourceStrings(UTF8ToSys(lcfn));
|
GetText.TranslateResourceStrings(UTF8ToSys(lcfn));
|
||||||
|
Loading…
Reference in New Issue
Block a user