Skip to content

Commit

Permalink
translate lcl
Browse files Browse the repository at this point in the history
  • Loading branch information
riderkick committed Jun 7, 2015
1 parent 2bac7b3 commit 85b2a51
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
75 changes: 69 additions & 6 deletions baseunits/utranslation.pas
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
interface

uses
Classes, SysUtils, strutils, FileUtil, LCLTranslator;
Classes, SysUtils, strutils, FileUtil, LCLTranslator, Translations;

type
TPoLanguage = record
Expand Down Expand Up @@ -661,13 +661,18 @@ TPoLanguage = record
('ZM', 'Zambia'),
('ZW', 'Zimbabwe'));

ldir: array[0..3] of string =
('LANG', 'languages', 'locale', 'locale' + PathDelim + 'LC_MESSAGES');

var
AvailableLanguages: TStringList;
LastSelected: string = '';
LangDir: string = '';

procedure CollectLanguagesFiles(appname: string = ''; dir: string = ''; useNativeName: Boolean = True);
function GetLangName(lcode: string; useNativeName: Boolean = True): string;

function SetLang(Lang: string): Boolean;
function SetLangByIndex(Idx: Integer): Boolean;
function GetDefaultLang: string;

Expand Down Expand Up @@ -719,14 +724,16 @@ procedure CollectLanguagesFiles(appname: string; dir: string;
sdir: string;
lauto: Boolean = False;
i: Integer;
const
ldir: array[0..3] of string =
('LANG', 'languages', 'locale', 'locale' + PathDelim + 'LC_MESSAGES');
begin
if dir = '' then
begin
dir := GetCurrentDirUTF8 + PathDelim;
lauto := True;
if LangDir <> '' then
dir := LangDir
else
begin
dir := GetCurrentDirUTF8 + PathDelim;
lauto := True;
end;
end;
if appname = '' then
appname := ExtractFileNameOnly(ParamStrUTF8(0));
Expand Down Expand Up @@ -815,6 +822,61 @@ function GetLangName(lcode: string; useNativeName: Boolean): string;
Result := GetLang(s);
end;

function TranslateLCL(Lang: string): Boolean;
var
lcllangdir, lcllangpath, fallbacklang: string;
lcllangfound: Boolean = False;
i: Integer;

procedure SearchLangPath;
begin
if FileExistsUTF8(lcllangdir + 'lclstrconsts.' + Lang + '.po') then
begin
lcllangfound := True;
lcllangpath := lcllangdir + 'lclstrconsts.' + Lang + '.po';
end;
end;

begin
Result := False;
if LangDir <> '' then
begin
lcllangdir := LangDir;
if RightStr(lcllangdir, 1) <> PathDelim then
lcllangdir := lcllangdir + PathDelim;
SearchLangPath;
end
else
begin
for i := Low(ldir) to High(ldir) do
begin
lcllangdir := GetCurrentDirUTF8 + PathDelim + ldir[i];
SearchLangPath;
if lcllangfound then
Break;
end;
end;
if lcllangfound then
begin
fallbacklang := '';
TranslateUnitResourceStrings('LclStrConsts', lcllangpath, Lang, fallbacklang);
Result := True;
end;
end;

function SetLang(Lang: string): Boolean;
begin
Result := False;
if (LastSelected <> Lang) and
(AvailableLanguages.IndexOfName(lang) > 0) then
begin
SetDefaultLang(Lang);
LastSelected := Lang;
TranslateLCL(Lang);
Result := True;
end;
end;

function SetLangByIndex(Idx: Integer): Boolean;
begin
Result := False;
Expand All @@ -823,6 +885,7 @@ function SetLangByIndex(Idx: Integer): Boolean;
begin
SetDefaultLang(AvailableLanguages.Names[Idx]);
LastSelected := AvailableLanguages.Names[Idx];
TranslateLCL(AvailableLanguages.Names[Idx]);
Result := True;
end;
end;
Expand Down
1 change: 1 addition & 0 deletions mangadownloader/forms/frmMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
FavoriteManager.Sort(vtFavorites.Header.SortColumn);
vtFavorites.Repaint;
end;
uTranslation.LangDir := GetCurrentDirUTF8 + PathDelim + 'languages';
LoadLanguage;
end;

Expand Down
1 change: 1 addition & 0 deletions mangadownloader/languages/fmd.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -1601,3 +1601,4 @@ msgstr "Synchronizing data"
#: uupdatethread.rs_updatinglist
msgid "Updating list"
msgstr "Updating list"

1 change: 1 addition & 0 deletions mangadownloader/languages/fmd.id_ID.po
Original file line number Diff line number Diff line change
Expand Up @@ -1601,3 +1601,4 @@ msgstr "Sinkronisasi data"
#: uupdatethread.rs_updatinglist
msgid "Updating list"
msgstr "Memperbarui daftar"

0 comments on commit 85b2a51

Please sign in to comment.