Difference between revisions of "Translations / i18n / localizations for programs/de"

From Lazarus wiki
Jump to navigationJump to search
m
Line 9: Line 9:
 
Zum Beispiel
 
Zum Beispiel
 
   resourcestring
 
   resourcestring
     Caption1 = 'Some text';
+
     Caption1 = 'Irgendein Text';
 
     HelloWorld1 = 'Hello World';
 
     HelloWorld1 = 'Hello World';
  
Line 19: Line 19:
 
== .po Dateien ==
 
== .po Dateien ==
  
There are many free graphical tools to edit .po files, which are simple text like the .rst files, but with some more options, like a header providing fields for author, encoding, language and date. Every fpc installation provides the tool '''rstconv''' (windows: rstconv.exe). This tool can be used to convert a .rst file into a .po file. The IDE can do this automatically.
+
There are many free graphical tools to edit .po files, which are simple text like the .rst files, but with some more options, like a header providing fields for author, encoding, language and date. Every fpc installation provides the tool '''rstconv''' (windows: rstconv.exe). Dieses Werkzeug kann verwendet werden, um eine .rst Datei in eine .po Datei zu konvertieren. The IDE can do this automatically.
Examples for free tools: kbabel, poedit.
+
Beispiele für freie Werkzeuge: [http://kbabel.kde.org/ kbabel], [http://www.poedit.net/ Poedit].
  
 
Example using rstconv directly:
 
Example using rstconv directly:

Revision as of 00:04, 20 February 2009

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) 한국어 (ko) polski (pl) português (pt) русский (ru) 中文(中国大陆)‎ (zh_CN)

Überblick

Hier wird gezeigt, wie Sie in Ihrem Programm verschiedene Strings für verschiedene Sprachen (Englisch, Deutsch, Chinesisch...) ausgeben können. Dazu müssen Sie nur Folgendes tun: Einen resourcestring für jeden String, den Sie ausgeben möchten hinzufügen, kompilieren um .rst und/oder .po Dateien zu erhalten (kann die IDE automatisch erzeugen), für jede Sprache eine .po Datei erstellen (dazu gibt es graphische Programme), und zuletzt die richtige .po Datei beim Programmstart mittels der unit translations laden.

Resourcestrings

Zum Beispiel

 resourcestring
   Caption1 = 'Irgendein Text';
   HelloWorld1 = 'Hello World';

Diese sind wie normale string Konstanten. Das bedeutet, daß sie sie jedem string zuweisen können, etwa

 Label1.Caption := HelloWorld1;

Wenn FPC diese kompiliert, dann wird für jede Unit eine Datei unitname.rst erzeugt, welche die Resourcestring Daten (Name + Inhalt) enthält.

.po Dateien

There are many free graphical tools to edit .po files, which are simple text like the .rst files, but with some more options, like a header providing fields for author, encoding, language and date. Every fpc installation provides the tool rstconv (windows: rstconv.exe). Dieses Werkzeug kann verwendet werden, um eine .rst Datei in eine .po Datei zu konvertieren. The IDE can do this automatically. Beispiele für freie Werkzeuge: kbabel, Poedit.

Example using rstconv directly:

 rstconv -i unit1.rst -o unit1.po

Übersetzen

Für jede Sprache muß die .po Datei kopiert und übersetzt werden. Die LCL translation Unit verwendet die üblichen Sprachcodes (en=english, de=deutsch, it=italienisch, ...) für die Suche. Zum Beispiel wäre die deutsche Übersetzung von unit1.po die unit1.de.po. This means, copy the unit1.po file to unit1.de.po, unit1.it.po, and whatever language you want to support and then the translators can edit their specific .po file.

Anmerkung für Brasilianer/Portugiesen:: Lazarus IDE und LCL haben nur eine brazillian portuguese Übersetzung und diese Dateien enden auf 'pb.po' und nicht auf 'pt.po'.

IDE Einstellungen für automatische Updates der .po Dateien

  • Die Unit, welche die Resourcenstrings enthält, muß zum Package oder Projekt hinzugefügt sein.
  • Sie müssen einen .po Pfad angeben. Dies bedeutet ein separates Verzeichnis. Zum Beispiel: erzeugen sie ein Unterverzeichnis language im Package / Projekt Verzeichnis. Für Projekte wählen sie im Menü Projekt > Projekteinstellungen -> i18n. Für Packages wählen sie in den Package-Einstellungen 'i18n'.

Translating Forms, Datamodules and Frames

Wenn die i18n Einstellung für das Projekt / Package aktiviert ist, dann erzeugt die IDE automatisch .lrt Dateien für jedes Formular. Die .lrt Dateien werden beim Speichern einer Unit erzeugt. Wenn sie die Einstellung zum ersten Mal aktivieren, dann müssen sie jedes Formular einmal öffnen und eine Änderung vornehmen (damit es als geändert markiert ist) und dann speichern. For example if you save a form unit1.pas the IDE creates a unit1.lrt. And on compile the IDE gathers all strings of all .lrt files and all .rst file into a single .po file (projectname.po or packagename.po) in the i18n directory.

Translating at start of program

Für jede .po Datei müssen sie TranslateUnitResourceStrings aus der LCL translations Unit aufrufen. Zum Beispiel:

<pascal>

   {Zuallererst: fügen sie die "gettext" und "translations" Units zum uses Abschnitt hinzu}
   procedure TForm1.FormCreate(Sender: TObject);
   var
     PODirectory, Lang, FallbackLang: String;
   begin
     PODirectory := '/path/to/lazarus/lcl/languages/';
     GetLanguageIDs(Lang, FallbackLang); // in unit gettext
     TranslateUnitResourceStrings('LCLStrConsts', PODirectory + 'lclstrconsts.%s.po', Lang, FallbackLang);
     MessageDlg('Title', 'Text', mtInformation, [mbOk, mbCancel, mbYes], 0);
   end;

</pascal>

Compiling po files into the executable

If you don't want to install the .po files, but put all files of the application into the executable, use the following:

  • Erzeugen sie eine neue Unit (kein Formular!).
  • Konvertieren sie die .po Datei(en) in .lrs unter Verwendung von tools/lazres:
./lazres unit1.lrs unit1.de.po

This will create an include file unit1.lrs beginning with <pascal> LazarusResources.Add('unit1.de','PO',[

 ...

</pascal>

  • Add the code:

<pascal> uses LResources, Translations;

resourcestring

 MyCaption = 'Caption';

function TranslateUnitResourceStrings: boolean; var

 r: TLResource;
 POFile: TPOFile;

begin

 r:=LazarusResources.Find('unit1.de','PO');
 POFile:=TPOFile.Create;
 try
   POFile.ReadPOText(r.Value);
   Result:=Translations.TranslateUnitResourceStrings('unit1',POFile);
 finally
   POFile.Free;
 end;

end;

initialization

 {$I unit1.lrs}

</pascal>

  • Rufen sie TranslateUnitResourceStrings am Beginn des Programms auf. Sie können das im initialization Abschnitt machen wenn sie wollen.

Future work / ToDos

IDE Development: Translations, i18n, lrt, po files