tvplanit: Add a single-language translation demo project.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8557 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-10-14 12:38:21 +00:00
parent 4af2571d9f
commit da3ba0f2a2
8 changed files with 538 additions and 0 deletions

View File

@ -0,0 +1,60 @@
--------------------------------------------------------------------------------
translations_demo
--------------------------------------------------------------------------------
This project shows how a single-language (non-English) application with
TvPlanIt components can be created. The example will be for a German application.
These are the general instructions:
- Create a folder "languages" for the translation files. Normally it is in the
folder of the binary, but in order so share the translation files with other
sample projects, we've put it in the top level of the TvPlanIt installation
folder structure.
- After compilation a .pot file is created in the languages folder. Copy it and
rename it to have the "double" extension .de.po where "de" indicates the
German translation
- Install a translation tool (e.g. "poedit") and open this file in it. Translate
all the strings to German. Save.
- The TvPlanIt translation files have the names vpsr.<country>.po where <country>
is the two-digit symbol of the country, in our example: vpsr.de.po
- Copy the file vpsr.de.po (from (tvplanit)/languages) to the languages folder
of the project.
- Copy the LCL strings file, lclstrconsts.de.po, from the lcl/languages folder
of the Lazarus installation to the languages folder of the project.
- Repeat with other packages needed by the project.
- Add the units LCLTranslator and translations to the uses clause of the main
form.
- In the OnCreate handler of the main form call the following function
procedure TMainForm.SelectLanguage(ALang: String);
var
langDir: String;
begin
// Calculate the path to the directory with the translation files.
langDir := ExpandFileName(Application.Location + '../../languages/'); // Adapt to the true location of the languages folder...
// Switch language of the application. This is a function in LCLTranslator.
SetDefaultLang(ALang, langDir);
// Translate all package string files needed.
TranslateUnitResourceStrings('vpsr', langDir + 'vpsr.' + ALang + '.po');
TranslateUnitResourceStrings('lclstrconsts', langDir + 'lclstrconsts.' + ALang + '.po');
// We must call the method LoadLanguage for all used TvPlanIt visual
// components in order to use the translated strings in the popup menus
// and other places not automatically handled by LCLTranslator.
VpDayView1.LoadLanguage;
VpWeekView1.LoadLanguage;
VpMonthView1.LoadLanguage;
VpTaskList1.LoadLanguage;
VpContactGrid1.LoadLanguage;
end;

View File

@ -0,0 +1,212 @@
object MainForm: TMainForm
Left = 225
Height = 686
Top = 155
Width = 980
Caption = 'MainForm'
ClientHeight = 686
ClientWidth = 980
OnCreate = FormCreate
object PageControl1: TPageControl
Left = 0
Height = 686
Top = 0
Width = 980
ActivePage = TabSheet1
Align = alClient
TabIndex = 0
TabOrder = 0
object TabSheet1: TTabSheet
Caption = 'Events and tasks'
ClientHeight = 658
ClientWidth = 972
object VpDayView1: TVpDayView
Left = 0
Height = 658
Top = 0
Width = 301
PopupMenu = VpDayView1.default
DataStore = VpIniDatastore1
ControlLink = VpControlLink1
Align = alLeft
TabOrder = 0
AllowDragAndDrop = True
ShowEventTimes = False
DrawingStyle = dsFlat
TimeSlotColors.Active = clWhite
TimeSlotColors.Inactive = 8454143
TimeSlotColors.Holiday = 16744703
TimeSlotColors.Weekend = 16777088
TimeSlotColors.ActiveRange.RangeBegin = h_00
TimeSlotColors.ActiveRange.RangeEnd = h_00
HeadAttributes.Font.Height = -13
RowHeadAttributes.HourFont.Height = -24
RowHeadAttributes.MinuteFont.Height = -12
LineColor = clGray
DateLabelFormat = 'dddd, mmmm dd, yyyy'
TimeFormat = tf24Hour
end
object Panel2: TPanel
Left = 306
Height = 658
Top = 0
Width = 386
Align = alLeft
BevelOuter = bvNone
Caption = 'Panel2'
ClientHeight = 658
ClientWidth = 386
TabOrder = 1
object VpWeekView1: TVpWeekView
Left = 0
Height = 412
Top = 0
Width = 386
PopupMenu = VpWeekView1.default
DataStore = VpIniDatastore1
ControlLink = VpControlLink1
AllDayEventAttributes.BackgroundColor = clWindow
AllDayEventAttributes.EventBorderColor = clGray
DateLabelFormat = 'dddd, mmmm dd, yyyy'
DayHeadAttributes.DateFormat = 'ddddd'
DayHeadAttributes.Font.Height = -13
DayHeadAttributes.Font.Name = 'Tahoma'
DrawingStyle = dsFlat
LineColor = clGray
TimeFormat = tf24Hour
WeekStartsOn = dtMonday
Align = alClient
TabOrder = 0
end
object VpMonthView1: TVpMonthView
Left = 0
Height = 241
Top = 417
Width = 386
PopupMenu = VpMonthView1.default
DataStore = VpIniDatastore1
ControlLink = VpControlLink1
Align = alBottom
TabOrder = 1
DayHeadAttributes.Font.Height = -13
DayHeadAttributes.Font.Name = 'Tahoma'
DrawingStyle = dsFlat
OffDayColor = clSilver
TimeFormat = tf24Hour
TodayAttributes.Color = clSilver
TodayAttributes.BorderPen.Color = clRed
TodayAttributes.BorderPen.Width = 3
WeekStartsOn = dtMonday
end
object Splitter2: TSplitter
Cursor = crVSplit
Left = 0
Height = 5
Top = 412
Width = 386
Align = alBottom
ResizeAnchor = akBottom
end
end
object VpTaskList1: TVpTaskList
Left = 697
Height = 658
Top = 0
Width = 275
PopupMenu = VpTaskList1.default
DataStore = VpIniDatastore1
ControlLink = VpControlLink1
Align = alClient
TabOrder = 2
DisplayOptions.ShowAll = True
DisplayOptions.NormalColor = clBlack
DrawingStyle = dsFlat
LineColor = clGray
TaskHeadAttributes.Color = clSilver
end
object Splitter1: TSplitter
Left = 692
Height = 658
Top = 0
Width = 5
end
object Splitter3: TSplitter
Left = 301
Height = 658
Top = 0
Width = 5
end
end
object TabSheet2: TTabSheet
Caption = 'Contacts'
ClientHeight = 658
ClientWidth = 972
object VpContactButtonBar1: TVpContactButtonBar
Left = 0
Height = 658
Top = 0
Width = 40
DrawingStyle = dsFlat
RadioStyle = False
Align = alLeft
end
object VpContactGrid1: TVpContactGrid
Left = 40
Height = 658
Top = 0
Width = 932
PopupMenu = VpContactGrid1.default
DataStore = VpIniDatastore1
ControlLink = VpControlLink1
Align = alClient
TabOrder = 1
ColumnWidth = 200
DrawingStyle = dsFlat
end
end
end
object VpControlLink1: TVpControlLink
DataStore = VpIniDatastore1
Printer.DayStart = h_08
Printer.DayEnd = h_05
Printer.Granularity = gr30Min
Printer.MarginUnits = imAbsolutePixel
Printer.PrintFormats = <>
Left = 136
Top = 264
end
object VpResourceEditDialog1: TVpResourceEditDialog
Version = 'v1.0.7'
DataStore = VpIniDatastore1
Options = []
Placement.Position = mpCenter
Placement.Top = 10
Placement.Left = 10
Placement.Height = 250
Placement.Width = 400
Left = 136
Top = 335
end
object VpIniDatastore1: TVpIniDatastore
CategoryColorMap.Category0.Description = 'Category 0'
CategoryColorMap.Category1.Description = 'Category 1'
CategoryColorMap.Category2.Description = 'Category 2'
CategoryColorMap.Category3.Description = 'Category 3'
CategoryColorMap.Category4.Description = 'Category 4'
CategoryColorMap.Category5.Description = 'Category 5'
CategoryColorMap.Category6.Description = 'Category 6'
CategoryColorMap.Category7.Description = 'Category 7'
CategoryColorMap.Category8.Description = 'Category 8'
CategoryColorMap.Category9.Description = 'Category 9'
HiddenCategories.BackgroundColor = clSilver
HiddenCategories.Color = clGray
AutoConnect = True
FileName = 'data.ini'
Left = 136
Top = 200
end
object PopupMenu1: TPopupMenu
Left = 129
Top = 527
end
end

View File

@ -0,0 +1,6 @@
{"version":1,"strings":[
{"hash":134403005,"name":"tmainform.caption","sourcebytes":[77,97,105,110,70,111,114,109],"value":"MainForm"},
{"hash":63645347,"name":"tmainform.tabsheet1.caption","sourcebytes":[69,118,101,110,116,115,32,97,110,100,32,116,97,115,107,115],"value":"Events and tasks"},
{"hash":90721266,"name":"tmainform.panel2.caption","sourcebytes":[80,97,110,101,108,50],"value":"Panel2"},
{"hash":106593811,"name":"tmainform.tabsheet2.caption","sourcebytes":[67,111,110,116,97,99,116,115],"value":"Contacts"}
]}

View File

@ -0,0 +1,101 @@
unit tdmain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, ComCtrls, Menus,
Translations, LCLTranslator,
VpBaseDS, VpDayView, VpWeekView, VpTaskList, VpContactGrid, VpMonthView,
VpResEditDlg, VpContactButtons, VpIniDs;
type
{ TMainForm }
TMainForm = class(TForm)
PageControl1: TPageControl;
Panel2: TPanel;
PopupMenu1: TPopupMenu;
Splitter1: TSplitter;
Splitter2: TSplitter;
Splitter3: TSplitter;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
VpContactButtonBar1: TVpContactButtonBar;
VpContactGrid1: TVpContactGrid;
VpControlLink1: TVpControlLink;
VpDayView1: TVpDayView;
VpIniDatastore1: TVpIniDatastore;
VpMonthView1: TVpMonthView;
VpResourceEditDialog1: TVpResourceEditDialog;
VpTaskList1: TVpTaskList;
VpWeekView1: TVpWeekView;
procedure FormCreate(Sender: TObject);
private
{ private declarations }
procedure SelectLanguage(ALang: String);
public
{ public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
uses
LazFileUtils,
VpData;
{ TMainForm }
// Load the last resource.
procedure TMainForm.FormCreate(Sender: TObject);
var
lastRes: TVpResource;
datastore: TVpCustomDatastore;
begin
datastore := VpControlLink1.Datastore;
if datastore.Resources.Count > 0 then
begin
lastRes := datastore.Resources.Items[datastore.Resources.Count-1];
datastore.ResourceID := lastRes.ResourceID;
end;
SelectLanguage('de');
end;
procedure TMainForm.SelectLanguage(ALang: String);
var
langDir: String;
begin
// Calculate the path to the directory with the translation files.
langDir := ExpandFileName(Application.Location + '../../languages/');
// Switch language of the application. This is a function in LCLTranslator.
SetDefaultLang(ALang, langDir);
// Translate all package string files needed.
// IMPORTANT: All these files must be copied from their original places into
// the "languages" directory of the application.
TranslateUnitResourceStrings('vpsr', langDir + 'vpsr.' + ALang + '.po');
TranslateUnitResourceStrings('lclstrconsts', langDir + 'lclstrconsts.' + ALang + '.po');
// We must call the method LoadLanguage of all visual TvPlanIt components
// in order to use the translated strings in the popup menus and other places
// not automatically handled by LCLTranslator.
VpDayView1.LoadLanguage;
VpWeekView1.LoadLanguage;
VpMonthView1.LoadLanguage;
VpTaskList1.LoadLanguage;
VpContactGrid1.LoadLanguage;
end;
end.

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="translations_demo"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
</General>
<i18n>
<EnableI18N Value="True"/>
<OutDir Value="..\..\languages"/>
</i18n>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
</Modes>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="laz_visualplanit"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="3">
<Unit0>
<Filename Value="translations_demo.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="tdmain.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
<Unit2>
<Filename Value="readme.txt"/>
<IsPartOfProject Value="True"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="translations_demo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
<UseExternalDbgSyms Value="True"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,20 @@
program translations_demo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, tdmain, laz_visualplanit;
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.

View File

@ -0,0 +1,28 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.1.1\n"
#: tmainform.caption
msgid "MainForm"
msgstr "Haupt-Formular"
#: tmainform.panel2.caption
msgid "Panel2"
msgstr ""
#: tmainform.tabsheet1.caption
msgid "Events and tasks"
msgstr "Termine und Aufgaben"
#: tmainform.tabsheet2.caption
msgid "Contacts"
msgstr "Kontakte"

View File

@ -0,0 +1,19 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
#: tmainform.caption
msgid "MainForm"
msgstr ""
#: tmainform.panel2.caption
msgid "Panel2"
msgstr ""
#: tmainform.tabsheet1.caption
msgid "Events and tasks"
msgstr ""
#: tmainform.tabsheet2.caption
msgid "Contacts"
msgstr ""