From 85b2a51d0562f38912d22ec217b20c8bd8756188 Mon Sep 17 00:00:00 2001 From: riderkick Date: Sun, 7 Jun 2015 14:11:59 +0800 Subject: [PATCH] translate lcl --- baseunits/utranslation.pas | 75 +++++++++++++++++++++++--- mangadownloader/forms/frmMain.pas | 1 + mangadownloader/languages/fmd.en.po | 1 + mangadownloader/languages/fmd.id_ID.po | 1 + 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/baseunits/utranslation.pas b/baseunits/utranslation.pas index 5dc0a763b..c8b968930 100644 --- a/baseunits/utranslation.pas +++ b/baseunits/utranslation.pas @@ -25,7 +25,7 @@ interface uses - Classes, SysUtils, strutils, FileUtil, LCLTranslator; + Classes, SysUtils, strutils, FileUtil, LCLTranslator, Translations; type TPoLanguage = record @@ -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; @@ -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)); @@ -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; @@ -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; diff --git a/mangadownloader/forms/frmMain.pas b/mangadownloader/forms/frmMain.pas index e48147ac1..743992a0a 100644 --- a/mangadownloader/forms/frmMain.pas +++ b/mangadownloader/forms/frmMain.pas @@ -833,6 +833,7 @@ procedure TMainForm.FormCreate(Sender: TObject); FavoriteManager.Sort(vtFavorites.Header.SortColumn); vtFavorites.Repaint; end; + uTranslation.LangDir := GetCurrentDirUTF8 + PathDelim + 'languages'; LoadLanguage; end; diff --git a/mangadownloader/languages/fmd.en.po b/mangadownloader/languages/fmd.en.po index f9c245dfa..c4a9c4b0f 100644 --- a/mangadownloader/languages/fmd.en.po +++ b/mangadownloader/languages/fmd.en.po @@ -1601,3 +1601,4 @@ msgstr "Synchronizing data" #: uupdatethread.rs_updatinglist msgid "Updating list" msgstr "Updating list" + diff --git a/mangadownloader/languages/fmd.id_ID.po b/mangadownloader/languages/fmd.id_ID.po index eff2ba73f..9d52fce57 100644 --- a/mangadownloader/languages/fmd.id_ID.po +++ b/mangadownloader/languages/fmd.id_ID.po @@ -1601,3 +1601,4 @@ msgstr "Sinkronisasi data" #: uupdatethread.rs_updatinglist msgid "Updating list" msgstr "Memperbarui daftar" +