diff options
-rw-r--r-- | examples/apps/uidesigner/newformdesigner.pas | 43 | ||||
-rw-r--r-- | examples/apps/uidesigner/vfdpropeditgrid.pas | 6 | ||||
-rw-r--r-- | examples/gui/fontselect/fontselect.af.po (renamed from examples/gui/fontselect/fontselect.af_ZA.po) | 0 | ||||
-rw-r--r-- | languages/README.txt | 11 | ||||
-rw-r--r-- | src/corelib/gfx_pofiles.pas | 64 | ||||
-rw-r--r-- | src/corelib/gfx_translations.pas | 14 | ||||
-rw-r--r-- | src/gui/gui_dialogs.pas | 5 |
7 files changed, 115 insertions, 28 deletions
diff --git a/examples/apps/uidesigner/newformdesigner.pas b/examples/apps/uidesigner/newformdesigner.pas index 429556fc..f9a111e8 100644 --- a/examples/apps/uidesigner/newformdesigner.pas +++ b/examples/apps/uidesigner/newformdesigner.pas @@ -145,6 +145,8 @@ type TfrmAbout = class(TfpgForm) + private + procedure ApplyScreenRatio; public {@VFD_HEAD_BEGIN: frmAbout} lblName1: TfpgLabel; @@ -181,7 +183,37 @@ uses {@VFD_NEWFORM_IMPL} +procedure TfrmAbout.ApplyScreenRatio; +var + i: integer; + wg: TfpgWidget; + ratio: double; +begin +// writeln('dpi = ', fpgApplication.Screen_dpi); + // Form was designed at 96 dpi. + ratio := 96 / fpgApplication.Screen_dpi; + for i := 0 to ComponentCount-1 do + begin + if Components[i] is TfpgWidget then + begin + wg := TfpgWidget(Components[i]); + wg.Top := round(wg.Top * ratio); + wg.Left := round(wg.Left * ratio); + wg.Width := round(wg.Width * ratio); + wg.Height := round(wg.Height * ratio); + end; + end; +end; + procedure TfrmAbout.AfterCreate; + function FontRatio(ASize: integer): string; + begin + Result := Format('%d', [round(ASize*((96/fpgApplication.Screen_dpi)-0.1))]); + if StrToInt(Result) <= 6 then // sanity check + Result := '8'; + writeln('Old:', ASize, ' New:', Result); + end; + begin {@VFD_BODY_BEGIN: frmAbout} Name := 'frmAbout'; @@ -196,7 +228,8 @@ begin Name := 'lblName1'; SetPosition(12, 16, 255, 31); Text := 'fpGUI UI Designer'; - FontDesc := 'Arial-20'; + FontDesc := 'Arial-' + FontRatio(20); + backgroundcolor := clGreen; end; lblVersion := TfpgLabel.Create(self); @@ -226,7 +259,7 @@ begin Name := 'lblName3'; SetPosition(12, 100, 241, 14); Text := 'Written by Graeme Geldenhuys'; - FontDesc := 'Arial-9'; + FontDesc := 'Arial-' + FontRatio(9); end; lblName4 := TfpgLabel.Create(self); @@ -235,7 +268,7 @@ begin Name := 'lblName4'; SetPosition(12, 116, 246, 14); Text := 'http://opensoft.homeip.net/fpgui/'; - FontDesc := 'Arial-9:underline'; + FontDesc := 'Arial-' + FontRatio(9) + ':underline'; end; lblCompiled := TfpgLabel.Create(self); @@ -244,10 +277,12 @@ begin Name := 'lblCompiled'; SetPosition(12, 132, 191, 13); Text := 'Compiled on: %s'; - FontDesc := 'Arial-8'; + FontDesc := 'Arial-' + FontRatio(8); end; {@VFD_BODY_END: frmAbout} + + ApplyScreenRatio; end; class procedure TfrmAbout.Execute; diff --git a/examples/apps/uidesigner/vfdpropeditgrid.pas b/examples/apps/uidesigner/vfdpropeditgrid.pas index f123eba4..1ded9366 100644 --- a/examples/apps/uidesigner/vfdpropeditgrid.pas +++ b/examples/apps/uidesigner/vfdpropeditgrid.pas @@ -127,6 +127,7 @@ begin SetPosition(8, 4, 110, 16); Text := 'String Grid columns:'; FontDesc := '#Label1'; + AutoSize := True; end; grid := TColumnsGrid.Create(self); @@ -144,6 +145,7 @@ begin SetPosition(344, 24, 56, 16); Text := 'Column:'; FontDesc := '#Label1'; + AutoSize := True; end; lbLabel3 := TfpgLabel.Create(self); @@ -153,6 +155,7 @@ begin SetPosition(344, 56, 34, 16); Text := 'Title:'; FontDesc := '#Label1'; + AutoSize := True; end; lbLabel6 := TfpgLabel.Create(self); @@ -162,6 +165,7 @@ begin SetPosition(344, 100, 88, 16); Text := 'Column width:'; FontDesc := '#Label1'; + AutoSize := True; end; lbLabel5 := TfpgLabel.Create(self); @@ -171,6 +175,7 @@ begin SetPosition(344, 144, 83, 16); Text := 'Alignment:'; FontDesc := '#Label1'; + AutoSize := True; end; lbCOLNO := TfpgLabel.Create(self); @@ -180,6 +185,7 @@ begin SetPosition(404, 24, 54, 16); Text := '--'; FontDesc := '#Label1'; + AutoSize := True; end; edTITLE := TfpgEdit.Create(self); diff --git a/examples/gui/fontselect/fontselect.af_ZA.po b/examples/gui/fontselect/fontselect.af.po index 07a13d9f..07a13d9f 100644 --- a/examples/gui/fontselect/fontselect.af_ZA.po +++ b/examples/gui/fontselect/fontselect.af.po diff --git a/languages/README.txt b/languages/README.txt index 5619c107..91d8e8a1 100644 --- a/languages/README.txt +++ b/languages/README.txt @@ -1,4 +1,5 @@ Quick Start for translators: +---------------------------- For example finnish translation: Search for all *.fi.po files. They are simple text files, with an easy format. @@ -10,7 +11,7 @@ Do not send diffs for .po files. Now the background: - +------------------- The <fpGUIdir>/languages directory contains all the stuff for internationalization of the fpGUI Toolkit. @@ -32,13 +33,15 @@ This is done by <fpGUIdir>/tools/localize.sh or <fpGUIdir>\tools\localize.bat. This will create the file fpgui.po, which should be translated in all required languages to a fpgui.xx.po file. For the xx see the gettext unit -in the procedure TranslateResourceStrings. +in the procedure TranslateResourceStrings. All translation .po files are +in UTF-8 encoding. +english: fpgui.en.po german: fpgui.de.po -russian (KOI8-R): fpgui.ru.po +russian: fpgui.ru.po spanish: fpgui.es.po french: fpgui.fr.po italian: fpgui.it.po afrikaans: fpgui.af.po - +portuguese: fpgui.pt.po diff --git a/src/corelib/gfx_pofiles.pas b/src/corelib/gfx_pofiles.pas index 30600680..4a50213a 100644 --- a/src/corelib/gfx_pofiles.pas +++ b/src/corelib/gfx_pofiles.pas @@ -180,22 +180,46 @@ var po: TPOFile; lPath, lFile: string; lPos: integer; + ToolkitOnly: Boolean; begin + {$IFDEF DEBUG} + writeln('TranslateUnitResourceStrings:'); + {$ENDIF} Result := False; - //debugln('TranslateUnitResourceStrings) ResUnitName="',ResUnitName,'" AFilename="',AFilename,'"'); + ToolkitOnly := False; + + // build correct filename for fpGUI Toolkit translations. + lPath := ExtractFilePath(AFilename); + lFile := ExtractFileName(AFilename); + lPos := Pos('.', lFile); + lFile := lPath + 'fpgui' + Copy(lFile, lPos, Length(lFile)-lPos+1); + {$IFDEF DEBUG} + writeln(' lFile = ', lFile); + writeln(' ResUnitName="', ResUnitName, '"'); + writeln(' AFilename="', AFilename, '"'); + {$ENDIF} + if {(ResUnitName = '') or} (AFilename = '') or (not FileExists(AFilename)) then - Exit; + ToolkitOnly := True; // we don't have a application translation file try po := nil; // read .po file - po := TPOFile.Create(AFilename); - // Now append fpGUI translations - lPath := ExtractFilePath(AFilename); - lFile := ExtractFileName(AFilename); - lPos := Pos('.', lFile); - lFile := lPath + 'fpgui' + Copy(lFile, lPos, Length(lFile)-lPos+1); -// writeln('lFile = ', lFile); - po.AppendFile(lFile); + if ToolkitOnly then + begin + if not FileExists(lFile) then + Exit; + {$IFDEF DEBUG} + writeln(' ************ Only translating the toolkit ***********'); + {$ENDIF} + po := TPOFile.Create(nil); + po.AppendFile(lFile); + end + else + begin + po := TPOFile.Create(AFilename); + // Now append fpGUI translations + po.AppendFile(lFile); + end; try {$ifdef ver2_0} for TableID := 0 to ResourceStringTableCount - 1 do @@ -247,11 +271,20 @@ begin if {(ResUnitName = '') or} (BaseFilename = '') then Exit; - //debugln('TranslateUnitResourceStrings BaseFilename="',BaseFilename,'"'); if (FallbackLang <> '') then + begin + {$IFDEF DEBUG} + writeln('1) Trying fallback language... ', Fallbacklang); + {$ENDIF} TranslateUnitResourceStrings(ResUnitName, Format(BaseFilename, [FallbackLang])); + end; if (Lang <> '') then + begin + {$IFDEF DEBUG} + writeln('2) Trying language... ', Lang); + {$ENDIF} TranslateUnitResourceStrings(ResUnitName, Format(BaseFilename, [Lang])); + end; end; { TPOFile } @@ -260,11 +293,13 @@ constructor TPOFile.Create(const AFilename: string); var f: TStream; begin - f := TFileStream.Create(AFilename, fmOpenRead); + if AFilename <> '' then + f := TFileStream.Create(AFilename, fmOpenRead); try Self.Create(f); finally - f.Free; + if Assigned(f) then + f.Free; end; end; @@ -277,6 +312,9 @@ begin FItems := TFPList.Create; FIdentifierToItem := TStringHashList.Create(False); FOriginalToItem := TStringHashList.Create(True); + + if AStream = nil then + Exit; Size := AStream.Size - AStream.Position; if Size <= 0 then diff --git a/src/corelib/gfx_translations.pas b/src/corelib/gfx_translations.pas index 5481b24d..251427e8 100644 --- a/src/corelib/gfx_translations.pas +++ b/src/corelib/gfx_translations.pas @@ -126,6 +126,13 @@ begin // writeln('TranslateResourceStrings A Lang=',Lang,' FallbackLang=',FallbackLang); Dir := fpgAddTrailingValue(BaseDirectory, PathDelim, false); + {$IFDEF DEBUG} + writeln('Lang = ' + Lang); + writeln('SystemLanguageID1 = ' + SystemLanguageID1); + writeln('SystemLanguageID2 = ' + SystemLanguageID2); + writeln('Translation file = ' +Dir + BaseAppName + Ext); + {$ENDIF} + // We use one translation file for all fpGUI Toolkit related text and one // translation file for all fpGUI based application text // if BaseAppName = 'fpgui' then @@ -134,13 +141,6 @@ begin // else TranslateUnitResourceStrings('fake', Dir + BaseAppName + Ext, Lang, FallbackLang); - - {$IFDEF DEBUG} - writeln('Lang = ' + Lang); - writeln('SystemLanguageID1 = ' + SystemLanguageID1); - writeln('SystemLanguageID2 = ' + SystemLanguageID2); - writeln('Translation file = ' +Dir + BaseAppName + Ext); - {$ENDIF} end; // Strip the '.' onwards part. eg: en_ZA.UTF-8 -> en_ZA diff --git a/src/gui/gui_dialogs.pas b/src/gui/gui_dialogs.pas index 46c8acd9..77bb5ece 100644 --- a/src/gui/gui_dialogs.pas +++ b/src/gui/gui_dialogs.pas @@ -725,6 +725,7 @@ begin with lblLabel5 do begin SetPosition(8, 8, 73, 16); + AutoSize := True; Text := fpgAddColon(rsCollection); end; @@ -752,6 +753,7 @@ begin with lblLabel1 do begin SetPosition(161, 8, 73, 16); + AutoSize := True; Text := fpgAddColon(rsName); end; @@ -769,6 +771,7 @@ begin begin Name := 'lblSize'; SetPosition(401, 8, 54, 16); + AutoSize := True; Text := fpgAddColon(rsSize); end; @@ -805,6 +808,7 @@ begin begin Name := 'lblTypeface'; SetPosition(461, 8, 54, 16); + AutoSize := True; Text := fpgAddColon(rsTypeface); end; @@ -845,6 +849,7 @@ begin with lblLabel4 do begin SetPosition(8, 268, 584, 16); + AutoSize := True; Text := fpgAddColon(rsExampleText); end; |