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

From Lazarus wiki
Jump to navigationJump to search
m (partially translated)
Line 4: Line 4:
  
  
==Overview==
+
==概要==
  
This is about how a program can use different strings for various languages like english, chinese, german, finnish, italian, ... .
+
このページでは、プログラムで用いる文字列を英語、中国語、ドイツ語、フィンランド語、イタリア語…といった各国語にあわせて変更することができるようにする方法を紹介します。基本的には、次のようになります : 各々のキャプションに ''resourcestring'' (リソース文字列定義)を加え、コンパイルして .rst ファイルないしは .po ファイルを得ます(IDE が自動的に行います)。各国語用にそれぞれ一つの翻訳済み .po ファイルを生成し、LCL の ''translations'' ユニット内の関数を用いて、プログラムの起動時に、正しいものをロードします。
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==
 
==Resourcestrings==
  
For example
+
例えば
 
   resourcestring
 
   resourcestring
 
     Caption1 = 'Some text';
 
     Caption1 = 'Some text';
 
     HelloWorld1 = 'Hello World';
 
     HelloWorld1 = 'Hello World';
  
These are like normal string constants, that means you can assign them to any string. For example
+
これらは通常の文字列定数と同様に、いかなる文字列にも代入することができます。例えば
 
   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).
+
コンパイル時にfpc は '''unitname.rst''' を各ユニットに一つ生成します。その中にはリソース文字列のデータ(名前と中身)が含まれます。
  
==.po Files==
+
==.po ファイル==
  
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.
+
生成した .po ファイルを編集するためには、数多くのグラフィカルツールが無料で提供されています。実際 .po ファイルは .rst ファイル同様単なるテキストファイルですが、作者・文字コード・言語・日付といった要素を含んだヘッダのような付随的な要素を含んでいます。fpc をインストールすれば必ず '''rstconv''' というツールがついてきます (Windowsでは rstconv.exe)。このツールは .rst ファイルを .po ファイルに変換します。IDE を使うと、この変換操作を自動的に行うことができます。フリーなツールの例としては kbabel、poedit があります。
Examples for free tools: kbabel, poedit.
 
  
Example using rstconv directly:
+
直接 rstconv を用いる例:
 
   rstconv -i unit1.rst -o unit1.po
 
   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.
+
それぞれの言語用に .po ファイルをコピーして翻訳する必要があります。LCL の translation ユニットは標準言語コード (en=英語, de=ドイツ語, it=イタリア語, ...) を用いて言語を検索します。例えば、unit1.po のドイツ語版は unit1.de.po となります。つまり、unit1.po ファイルを unit1.de.po、unit1.it.po などなどサポートしようと思っている言語用の名前でコピーして、そのファイルを各国語の翻訳者が編集すればいいわけです。
  
'''Note to brazilians/portugueses:''': Lazarus IDE and LCL has only brazillian portuguese translations and these files are 'pb.po' extensions and not 'pt.po'.
+
'''ブラジル人/ポルトガル人への註:''': Lazarus IDE LCL はブラジルのポルトガル語(拡張子 'pb.po')だけを用意しており、 'pt.po' はありません。
  
==IDE options for automatic updates of .po files==
+
==自動的に .po ファイルをアップデートする IDE のオプション==
  
 
*The unit containing the resource strings must be added to the package or project.
 
*The unit containing the resource strings must be added to the package or project.

Revision as of 13:19, 8 September 2010

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

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報


概要

このページでは、プログラムで用いる文字列を英語、中国語、ドイツ語、フィンランド語、イタリア語…といった各国語にあわせて変更することができるようにする方法を紹介します。基本的には、次のようになります : 各々のキャプションに resourcestring (リソース文字列定義)を加え、コンパイルして .rst ファイルないしは .po ファイルを得ます(IDE が自動的に行います)。各国語用にそれぞれ一つの翻訳済み .po ファイルを生成し、LCL の translations ユニット内の関数を用いて、プログラムの起動時に、正しいものをロードします。

Resourcestrings

例えば

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

これらは通常の文字列定数と同様に、いかなる文字列にも代入することができます。例えば

 Label1.Caption := HelloWorld1;

コンパイル時にfpc は unitname.rst を各ユニットに一つ生成します。その中にはリソース文字列のデータ(名前と中身)が含まれます。

.po ファイル

生成した .po ファイルを編集するためには、数多くのグラフィカルツールが無料で提供されています。実際 .po ファイルは .rst ファイル同様単なるテキストファイルですが、作者・文字コード・言語・日付といった要素を含んだヘッダのような付随的な要素を含んでいます。fpc をインストールすれば必ず rstconv というツールがついてきます (Windowsでは rstconv.exe)。このツールは .rst ファイルを .po ファイルに変換します。IDE を使うと、この変換操作を自動的に行うことができます。フリーなツールの例としては kbabel、poedit があります。

直接 rstconv を用いる例:

 rstconv -i unit1.rst -o unit1.po

翻訳

それぞれの言語用に .po ファイルをコピーして翻訳する必要があります。LCL の translation ユニットは標準言語コード (en=英語, de=ドイツ語, it=イタリア語, ...) を用いて言語を検索します。例えば、unit1.po のドイツ語版は unit1.de.po となります。つまり、unit1.po ファイルを unit1.de.po、unit1.it.po などなどサポートしようと思っている言語用の名前でコピーして、そのファイルを各国語の翻訳者が編集すればいいわけです。

ブラジル人/ポルトガル人への註:: Lazarus IDE と LCL はブラジルのポルトガル語(拡張子 'pb.po')だけを用意しており、 'pt.po' はありません。

自動的に .po ファイルをアップデートする IDE のオプション

  • 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 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

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>

Future work / ToDos

IDE Development: Translations, i18n, lrt, po files


Daemons and Services