Ours is essentially a tragic age, so we refuse to take it tragically. The cataclysm has happened, we are among the ruins, we start to build up new little habitats, to have new little hopes. It is rather hard work: there is now no smooth road into the future: but we go round, or scramble over the obstacles. We've got to live, no matter how many skies have fallen.
在前文《增强版 Traymond 让任意窗口最小化到系统托盘》中介绍了一款可以将任意窗口最小化到系统托盘的 Windows 桌面小工具。该工具代码 fork 自另一个同名项目,新增了一些功能并做了界面中文化。不过原项目是基于 Windows API 开发的,没有使用任何 GUI 框架,想要在此之上做进一步扩展非常麻烦,索性推倒重来。
pascalfunction SetDefaultLang(Lang: string; Dir: string = ''; LocaleFileName: string = ''; ForceUpdate: boolean = true): string;
{ Arguments:
Lang - language (e.g. 'ru', 'de', 'zh_CN'); empty argument is default language.
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
called from unit Initialization section. User code normally should not specify it.
}
var
lcfn: string;
LocalTranslator: TUpdateTranslator;
i: integer;
begin
Result := '';
LocalTranslator := nil;
// search first po translation resources
try
lcfn := FindLocaleFileName('.po', Lang, Dir, LocaleFileName, Result);
if lcfn <> '' then
begin
Translations.TranslateResourceStrings(lcfn);
LocalTranslator := TPOTranslator.Create(lcfn);
end
else
begin
// try now with MO translation resources
lcfn := FindLocaleFileName('.mo', Lang, Dir, LocaleFileName, Result);
if lcfn <> '' then
begin
GetText.TranslateResourceStrings(UTF8ToSys(lcfn));
LocalTranslator := TDefaultTranslator.Create(lcfn);
end;
end;
except
Result := '';
lcfn := '';
end;
if lcfn<>'' then
TranslateLCLResourceStrings(Lang, lcfn);
if LocalTranslator<>nil then
begin
if Assigned(LRSTranslator) then
LRSTranslator.Free;
LRSTranslator := LocalTranslator;
// Do not update the translations when this function is called from within
// the unit initialization.
if ForceUpdate=true then
begin
for i := 0 to Screen.CustomFormCount-1 do
LocalTranslator.UpdateTranslation(Screen.CustomForms[i]);
for i := 0 to Screen.DataModuleCount-1 do
LocalTranslator.UpdateTranslation(Screen.DataModules[i]);
end;
end;
end;