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

From Free Pascal wiki
Jump to navigationJump to search
(New page: ==Overview== 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 ''resou...)
 
Line 3: Line 3:
 
This is about how a program can use different strings for various languages like english, chinese, german, finnish, italian, ... .
 
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.
 
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==
 +
 +
For example
 +
  resourcestring
 +
    Caption1 = 'Some text';
 +
    HelloWorld1 = 'Hello World';
 +
 +
These are like normal string constants, that means you can assign them to any string. For example
 +
  Label1.Caption := HelloWorld1;
 +
 +
When fpc compiles them, it creates for each unit a file '''unitname.rst''', containing the resourcestring data (name + content).
 +
 +
==.po Files==
 +
 +
There are many free graphical tools to edit .po files, which are like .rst files 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.

Revision as of 11:06, 12 September 2007

Overview

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

For example

 resourcestring
   Caption1 = 'Some text';
   HelloWorld1 = 'Hello World';

These are like normal string constants, that means you can assign them to any string. For example

 Label1.Caption := HelloWorld1;

When fpc compiles them, it creates for each unit a file unitname.rst, containing the resourcestring data (name + content).

.po Files

There are many free graphical tools to edit .po files, which are like .rst files 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.