Skip to content

Commit

Permalink
Reveal yet hidden languages in language selector on preferences dialo…
Browse files Browse the repository at this point in the history
…g. Reveals hr_HR Croatian, which was present on Transifex but missing in hardcoded language list from dxgettext/languagecodes.pas
  • Loading branch information
ansgarbecker committed Mar 17, 2019
1 parent d5fe0eb commit c0dcc87
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/Delphi10.3/heidisql.dpr
Expand Up @@ -71,6 +71,7 @@ begin
Application.Terminate;
end else begin
AppLanguage := AppSettings.ReadString(asAppLanguage);
SysLanguage := DefaultInstance.GetCurrentLocaleName;
UseLanguage(AppLanguage);
Application.Initialize;
Application.Title := APPNAME;
Expand Down
10 changes: 9 additions & 1 deletion source/apphelpers.pas
Expand Up @@ -283,7 +283,8 @@ TAppSettings = class(TObject)
function FormatNumber( flt: Double; decimals: Integer = 0; Thousands: Boolean=True): String; Overload;
procedure ShellExec(cmd: String; path: String=''; params: String='');
function getFirstWord(text: String; MustStartWithWordChar: Boolean=True): String;
function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum: Integer; DeleteFromSource: Boolean): String;
function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum: Integer; DeleteFromSource: Boolean): String; Overload;
function RegExprGetMatch(Expression: String; Input: String; ReturnMatchNum: Integer): String; Overload;
function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload;
function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload;
function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean): String;
Expand Down Expand Up @@ -1070,6 +1071,13 @@ function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum:
end;


function RegExprGetMatch(Expression: String; Input: String; ReturnMatchNum: Integer): String;
begin
// Version without possibility to delete captured match from input
Result := RegExprGetMatch(Expression, Input, ReturnMatchNum, False);
end;


{**
Format a filesize to automatically use the best fitting expression
16 100 000 Bytes -> 16,1 MB
Expand Down
1 change: 1 addition & 0 deletions source/main.pas
Expand Up @@ -1188,6 +1188,7 @@ TMainForm = class(TForm)
var
MainForm: TMainForm;
SecondInstMsgId: UINT = 0;
SysLanguage: String;

const
CheckedStates = [csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed];
Expand Down
56 changes: 39 additions & 17 deletions source/options.pas
Expand Up @@ -322,16 +322,15 @@ procedure Toptionsform.Apply(Sender: TObject);
AppSettings.WriteBool(asDisplayBars, chkColorBars.Checked);
AppSettings.WriteString(asMySQLBinaries, editMySQLBinaries.Text);
AppSettings.WriteString(asCustomSnippetsDirectory, editCustomSnippetsDirectory.Text);

if comboAppLanguage.ItemIndex > 0 then begin
// There is no TStringList.Names[Value] getter, so we find the language code via loop
// Get language code from the left text in the dropdown item text, up to the colon
LangCode := RegExprGetMatch('^(\w+)\b', comboAppLanguage.Text, 1);
end else begin
LangCode := '';
for i:=0 to FLanguages.Count-1 do begin
if FLanguages.ValueFromIndex[i] = comboAppLanguage.Text then
LangCode := FLanguages.Names[i];
end;
AppSettings.WriteString(asAppLanguage, LangCode);
end else
AppSettings.WriteString(asAppLanguage, '');
end;
AppSettings.WriteString(asAppLanguage, LangCode);

if comboGUIFont.ItemIndex = 0 then
AppSettings.WriteString(asGUIFontName, '')
else
Expand Down Expand Up @@ -484,9 +483,7 @@ procedure Toptionsform.FormCreate(Sender: TObject);
end;

InitLanguages;
for i:=0 to FLanguages.Count-1 do begin
comboAppLanguage.Items.Add(FLanguages.ValueFromIndex[i]);
end;
comboAppLanguage.Items.AddStrings(FLanguages);

comboGUIFont.Items.Assign(Screen.Fonts);
comboGUIFont.Items.Insert(0, '<'+_('Default system font')+'>');
Expand Down Expand Up @@ -606,6 +603,7 @@ procedure Toptionsform.FormDestroy(Sender: TObject);
procedure Toptionsform.FormShow(Sender: TObject);
var
LangCode, GUIFont: String;
i: Integer;
begin
screen.Cursor := crHourGlass;

Expand All @@ -629,7 +627,14 @@ procedure Toptionsform.FormShow(Sender: TObject);
editMySQLBinaries.Text := AppSettings.ReadString(asMySQLBinaries);
editCustomSnippetsDirectory.Text := AppSettings.ReadString(asCustomSnippetsDirectory);
LangCode := AppSettings.ReadString(asAppLanguage);
comboAppLanguage.ItemIndex := comboAppLanguage.Items.IndexOf(FLanguages.Values[LangCode]);
for i:=0 to comboAppLanguage.Items.Count-1 do begin
if RegExprGetMatch('^(\w+)\b', comboAppLanguage.Items[i], 1) = LangCode then begin
comboAppLanguage.ItemIndex := i;
Break;
end;
end;
if comboAppLanguage.ItemIndex = -1 then
comboAppLanguage.ItemIndex := 0;
GUIFont := AppSettings.ReadString(asGUIFontName);
if GUIFont.IsEmpty then
comboGUIFont.ItemIndex := 0
Expand Down Expand Up @@ -1213,21 +1218,33 @@ procedure Toptionsform.ShortcutExit(Sender: TObject);
procedure Toptionsform.InitLanguages;
var
AvailLangCodes: TStringList;
i: Integer;

procedure AddLang(LangCode, LangName: String);
var j: Integer;
begin
LangCode := LowerCase(LangCode);
if AvailLangCodes.IndexOf(LangCode) > -1 then
FLanguages.Add(LangCode + FLanguages.NameValueSeparator + LangName);
if AvailLangCodes.IndexOf(LangCode) = -1 then
Exit;
// Delete potentially existing lang code without long name
for j:=FLanguages.Count-1 downto 0 do begin
if CompareText(RegExprGetMatch('^(\w+)\b', FLanguages[j], 1), LangCode) = 0 then begin
FLanguages.Delete(j);
end;
end;

FLanguages.Add(LangCode + ': ' + LangName);
end;

begin
// Create list with present language code => language name
// List taken from dxgettext/languagecodes.pas
FLanguages := TStringList.Create;
FLanguages.Add('' + FLanguages.NameValueSeparator + f_('Auto detect (%s)', [DefaultInstance.GetCurrentLanguage]));
AvailLangCodes := TStringList.Create;
AvailLangCodes.CaseSensitive := False;
DefaultInstance.GetListOfLanguages('default', AvailLangCodes);
for i:=0 to AvailLangCodes.Count-1 do begin
AddLang(AvailLangCodes[i], '');
end;
AddLang('aa', 'Afar');
AddLang('aa', 'Afar');
AddLang('ab', 'Abkhazian');
Expand Down Expand Up @@ -1295,6 +1312,7 @@ procedure Toptionsform.InitLanguages;
AddLang('hi', 'Hindi');
AddLang('ho', 'Hiri Motu');
AddLang('hr', 'Croatian');
AddLang('hr_HR', 'Croatian'); // Added, exists on Transifex
AddLang('ht', 'Haitian');
AddLang('hu', 'Hungarian');
AddLang('hy', 'Armenian');
Expand Down Expand Up @@ -1420,10 +1438,14 @@ procedure Toptionsform.InitLanguages;
AddLang('yi', 'Yiddish');
AddLang('yo', 'Yoruba');
AddLang('za', 'Zhuang');
AddLang('zh', 'Chinese (Simplified)');
AddLang('zh', 'Chinese (Simplified)'); // Added, see #498
AddLang('zh_CN', 'Chinese (China)');
AddLang('zh_TW', 'Chinese (Traditional)');
AddLang('zu', 'Zulu');

FLanguages.Sort;
FLanguages.Insert(0, '*** '+f_('Auto detect (%s)', [SysLanguage]));

AvailLangCodes.Free;
end;

Expand Down

0 comments on commit c0dcc87

Please sign in to comment.