Difference between revisions of "Translations / i18n / localizations for programs/fr"
LazarusBob (talk | contribs) |
LazarusBob (talk | contribs) |
||
Line 1: | Line 1: | ||
==Overview== | ==Overview== | ||
− | + | Ceci concerne la façon dont un programme peut utiliser différentes chaînes pour différentes langues comme l'anglais, le chinois, l'allemand, le finois, l'italien, ... . | |
− | + | Basiquement cela fonctionne comme ceci: Ajoutez une ''resourcestring'' pour chaque caption, compilez pour obtenir le(s) fichier(s) .rst et/ou .po (l'IDE peut le faire automatiquement), créez un fichier traduit .po pour chaque langue (il existe des outils graphiques libres) et utilisez les fonctions de l'unité ''translations'' de la LCL pour charger la bonnee au lancement du programme. | |
==Resourcestrings== | ==Resourcestrings== |
Revision as of 21:43, 20 June 2008
Overview
Ceci concerne la façon dont un programme peut utiliser différentes chaînes pour différentes langues comme l'anglais, le chinois, l'allemand, le finois, l'italien, ... . Basiquement cela fonctionne comme ceci: Ajoutez une resourcestring pour chaque caption, compilez pour obtenir le(s) fichier(s) .rst et/ou .po (l'IDE peut le faire automatiquement), créez un fichier traduit .po pour chaque langue (il existe des outils graphiques libres) et utilisez les fonctions de l'unité translations de la LCL pour charger la bonnee au lancement du programme.
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 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
Translating
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.
Note to brazilians/portugueses:: Lazarus IDE and LCL has only brazillian portuguese translations and these files are 'pb.po' extensions and not 'pt.po'.
IDE options for automatic updates of .po files
- The unit containing the resource strings must be added to the package or project.
- 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.
Translating at start of program
For every .po file, you must call TranslateUnitResourceStrings of the LCL translations unit. For example:
<pascal>
{First of all: add "gettext" and "translations" units in uses clause} 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>