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

From Lazarus wiki
Jump to navigationJump to search
(New page: {{Translations_/_i18n_/_localizations_for_programs}} == Überblick == This is about how a program can use different strings for various languages like english, chinese, german, finnish, ...)
 
m
Line 16: Line 16:
 
   Label1.Caption := HelloWorld1;
 
   Label1.Caption := HelloWorld1;
  
When fpc compiles them, it creates for each unit a file '''unitname.rst''', containing the resourcestring data (name + content).
+
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 ==
 
== .po Dateien ==
Line 28: Line 28:
 
== Übersetzen ==
 
== Übersetzen ==
  
For every language the .po file must be copied and translated. The LCL translation unit uses the common language codes (en=english, de=german, it=italian, ...) to search. For example the german translation of unit1.po would be 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.
+
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.
  
'''Note to brazilians/portugueses:''': Lazarus IDE and LCL has only brazillian portuguese translations and these files are 'pb.po' extensions and not 'pt.po'.
+
'''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 options for automatic updates of .po files ==
+
== IDE Einstellungen für automatische Updates der .po Dateien ==
  
*The unit containing the resource strings must be added to the package or project.
+
*Die Unit, welche die Resourcenstrings enthält, muß zum Package oder Projekt hinzugefügt sein.
*You must provide a .po path, this means a separate directory. For example: create a sub directory ''language'' in the package / project directory. For projects go to the Project > Project Options. For packages go to Options > IDE integration.
+
*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 ==
 
== Translating Forms, Datamodules and Frames ==
Line 43: Line 43:
 
== Translating at start of program ==
 
== Translating at start of program ==
  
For every .po file, you must call TranslateUnitResourceStrings of the LCL translations unit. For example:
+
Für jede .po Datei müssen sie TranslateUnitResourceStrings aus der LCL translations Unit aufrufen. Zum Beispiel:
  
 
<pascal>
 
<pascal>
     {First of all: add "gettext" and "translations" units in uses clause}
+
     {Zuallererst: fügen sie die "gettext" und "translations" Units zum uses Abschnitt hinzu}
 
     procedure TForm1.FormCreate(Sender: TObject);
 
     procedure TForm1.FormCreate(Sender: TObject);
 
     var
 
     var

Revision as of 23:27, 21 June 2008

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

Überblick

This is about how a program can use different strings for various languages like english, chinese, german, finnish, italian, ... . Basically it works like this: Add a resourcestring for every caption, compile to get the .rst and/or .po files (the IDE can do this automatically), create one translated .po file for each language (there are free graphical tools) and use the functions of the LCL translations unit to load the right one at start of the program.

Resourcestrings

Zum Beispiel

 resourcestring
   Caption1 = 'Some 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). This tool can be used to convert a .rst file into a .po file. The IDE can do this automatically. Examples for free tools: 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

When the i18n option is enabled for the project / package then the IDE automatically creates .lrt files for every form. It creates the .lrt file on saving a unit. So, if you enable the option for the first time, you must open every form once, move it a little bit, so that it is modified, and save the form. 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>

Future work / ToDos

IDE Development: Translations, i18n, lrt, po files