From a6646fec5a449463487e71793929ee8663c7ea34 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Wed, 7 Jan 2015 23:35:16 +0900 Subject: [PATCH 1/5] docs/guide-ja/tutorial-i18n.md - WIP [ci skip] --- docs/guide-ja/tutorial-i18n.md | 563 +++++++++++++++++++++++++++++++++ 1 file changed, 563 insertions(+) create mode 100644 docs/guide-ja/tutorial-i18n.md diff --git a/docs/guide-ja/tutorial-i18n.md b/docs/guide-ja/tutorial-i18n.md new file mode 100644 index 0000000000..02d7ef0fab --- /dev/null +++ b/docs/guide-ja/tutorial-i18n.md @@ -0,0 +1,563 @@ +国際化 +====== + +> Note|注意: この節はまだ執筆中です。 + +国際化 (I18N) とは、工学的な変更を伴わずにさまざまな言語と地域に順応できるように、ソフトウェアアプリケーションを設計するプロセスを指します。 +潜在的なユーザが世界中にいるウェブアプリケーションにとっては、このことは特に重要な意味を持ちます。 + +Yii は、メッセージの翻訳、数字や日付の書式設定など、ウェブサイトの国際化を手助けするいくつかのツールを提供しています。 + +ロケールと言語 +-------------- + +Yii のアプリケーションでは二つの言語が定義されます。 +すなわち、[[yii\base\Application::$sourceLanguage|ソース言語]] と [[yii\base\Application::$language|ターゲット言語]] です。 + +ソース言語とは、次のように、コードに直接書かれているオリジナルのアプリケーションメッセージの言語です。 + +```php +echo \Yii::t('app', 'I am a message!'); +``` + +ターゲット言語は、現在のページを表示するのに使用されるべき言語、すなわち、オリジナルのメッセージの翻訳先となるべき言語です。 +これはアプリケーションの構成情報において、次のように定義されているものです。 + +```php +return [ + 'id' => 'applicationID', + 'basePath' => dirname(__DIR__), + // ... + 'language' => 'ru-RU', // <- ここ ! + // ... +] +``` + +> **Tip**|ヒント: [[yii\base\Application::$sourceLanguage|ソース言語]] のデフォルト値は英語であり、この値は変えないことが推奨されます。 +> 理由は、英語から他の言語への翻訳者を見つける方が、非英語から非英語への翻訳者を見つけるより簡単だからです。 + +アプリケーションの言語を実行時に設定して、ユーザが選択した言語をターゲットにすることが可能です。 +この操作は、全ての出力に対して正しく効果を発揮するように、まだ出力が何も生成されていない時点で行われなければなりません。 +そのためには、アプリケーションのターゲット言語プロパティを望ましい値に変更するだけです。 + +```php +\Yii::$app->language = 'zh-CN'; +``` + +言語/ロケールの書式は `ll-CC` です。`ll` は [ISO-639](http://www.loc.gov/standards/iso639-2/) に従った二文字または三文字の小文字の言語コードであり、`CC` は [ISO-3166](http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html) に従った国コードです。 + +> **Note**|注意: ロケールの概念と構文に関する詳細な情報については、[ICU プロジェクトのドキュメント](http://userguide.icu-project.org/locale#TOC-The-Locale-Concept) を参照してください。 + + +メッセージ翻訳 +-------------- + +メッセージ翻訳は、アプリケーションによって出力されたメッセージを別の言語に翻訳して、さまざまな国のユーザが自国語でアプリケーションを使えるようにするために使用されるものです。 + +Yii におけるメッセージ翻訳機能は、ソース言語からターゲット言語へとメッセージの翻訳を探すという単純な動作をします。 +メッセージ翻訳機能を使うためには、オリジナルのメッセージ文字列を [[Yii::t()]] メソッドで包みます。 +このメソッドの最初のパラメータは、メッセージの生成元であるアプリケーションのさまざまな部分を区別するためのカテゴリであり、二番目のパラメータはメッセージそのものです。 + +```php +echo \Yii::t('app', 'This is a string to translate!'); +``` + +Yii は `i18n` [アプリケーションコンポーネント](structure-application-components.md) に定義されているメッセージソースの中から、現在の [[yii\base\Application::$language|アプリケーション言語]] に従って、適切な翻訳を読み込もうと試みます。 +メッセージソースは、翻訳メッセージを提供する一群のファイルまたはデータベースです。 +次の構成情報の例は、メッセージを PHP ファイルから取得するメッセージソースを定義するものです。 + +```php +'components' => [ + // ... + 'i18n' => [ + 'translations' => [ + 'app*' => [ + 'class' => 'yii\i18n\PhpMessageSource', + //'basePath' => '@app/messages', + //'sourceLanguage' => 'en-US', + 'fileMap' => [ + 'app' => 'app.php', + 'app/error' => 'error.php', + ], + ], + ], + ], +], +``` + +上記において `app*` は、このメッセージソースによって扱われるカテゴリを指定するパターンです。 +この例では、`app` から始まる全てのカテゴリをこのメッセージソースで処理します。 +メッセージファイルは `@app/messages`、すなわち、アプリケーションディレクトリの下の `messages` ディレクトリに配置されています。 +[[yii\i18n\PhpMessageSource::fileMap|fileMap]] 配列が、どのカテゴリに対してどのファイルが使われるべきかを定義しています。 +`fileMap` を構成する代りに、カテゴリ名をファイル名として使用する規約 (例えば、`app/error` というカテゴリは、[[yii\i18n\PhpMessageSource::basePath|basePath]] の下の `app/error.php` というファイル名に帰結します) に依存することも出来ます。 + +`\Yii::t('app', 'This is a string to translate!')` というメッセージを翻訳するとき、アプリケーション言語が `ja-JP` である場合は、Yii は利用できるメッセージのリストを取得するために、まず `@app/messages/ja-JP/app.php` というファイルを探します。 +`ja-JP` ディレクトリにファイルが無い場合は、失敗であるとする前に、`ja` ディレクトリも探します。 + +メッセージを PHP ファイルに保存する [[yii\i18n\PhpMessageSource|PhpMessageSource]] に加えて、Yii は二つのクラスを提供しています。 + +- [[yii\i18n\GettextMessageSource]] - GNU Gettext の MO ファイルまたは PO ファイルを使用 +- [[yii\i18n\DbMessageSource]] - データベースを使用 + + +> Info|情報: 以下においては、メッセージ書式の理解を助けるために、原文にはない日本語へのメッセージの翻訳例 (と出力結果) を追加している個所があります。 + +### 名前付きプレースホルダ + +翻訳メッセージには、翻訳後に対応する値に置き換えられるパラメータを追加することが出来ます。 +このパラメータの形式は、次の例で示すように、パラメータ名を波括弧で囲むものです。 + +```php +$username = 'Alexander'; +echo \Yii::t('app', 'Hello, {username}!', [ + 'username' => $username, +]); + +// 翻訳例: '{username} さん、こんにちは!' +``` + +パラメータへの代入には波括弧を使わないことに注意してください。 + +### 序数プレースホルダ + +```php +$sum = 42; +echo \Yii::t('app', 'Balance: {0}', $sum); + +// 翻訳例: '差引残高: {0}' +``` + +> **Tip**|ヒント: メッセージ文字列の意味が分らなくならないように努めて、あまりに多くの序数プレースホルダを使うことは避けてください。 +> 翻訳者にはソース文字列しか無く、従って、各プレースホルダに何が入るのかは自明でなければならない、ということを忘れないでください。 + +### 高度なプレースホルダの書式 + +高度な機能を使うためには、[intl PHP 拡張](http://www.php.net/manual/ja/intro.intl.php) をインストールして有効にする必要があります。 +それをインストールして有効にして初めて、プレースホルダのための拡張構文を使うことが出来るようになります。 +すなわち、デフォルトの書式を意味する短い形式 `{placeholderName, argumentType}`、あるいは、書式のスタイルを指定できる完全な形式 `{placeholderName, argumentType, argumentStyle}` を使うことが出来るようになります。 + +完全なリファレンスは [ICU ウェブサイト](http://icu-project.org/apiref/icu4c/classMessageFormat.html) で入手可能ですが、以下においてはいくつかの例を示します。 + +#### 数値 + +```php +$sum = 42; +echo \Yii::t('app', 'Balance: {0, number}', $sum); + +// 翻訳例: '差引残高: {0, number}' +// 出力例: '差引残高: 12,345' +``` + +内蔵のスタイル (`integer`、`currency`、`percent`) の一つを指定することが出来ます。 + +```php +$sum = 42; +echo \Yii::t('app', 'Balance: {0, number, currency}', $sum); + +// 翻訳例: '差引残高: {0, number, currency}' +// 出力例: '差引残高: ¥ 12,345' +``` + +または、カスタムパターンを指定することも出来ます。 + +```php +$sum = 42; +echo \Yii::t('app', 'Balance: {0, number, ,000,000000}', $sum); + +// 翻訳例: '差引残高: {0, number, ,000,000000}' +// 出力例: '差引残高: 000,012345' +``` + +[書式のリファレンス](http://icu-project.org/apiref/icu4c/classicu_1_1DecimalFormat.html). + +#### 日付 + +```php +echo \Yii::t('app', 'Today is {0, date}', time()); + +// 翻訳例: '今日は {0, date} です。' +// 出力例: '今日は 2015/01/07 です。' +``` + +内蔵の書式は、`short`、`medium`、`long`、そして `full` です。 + +```php +echo \Yii::t('app', 'Today is {0, date, short}', time()); + +// 翻訳例: '今日は {0, date, short} です。' +// 出力例: '今日は 2015/01/07 です。' +``` + +カスタムパターンを指定することも出来ます。 + +```php +echo \Yii::t('app', 'Today is {0, date, yyyy-MM-dd}', time()); + +// 翻訳例: '今日は {0, date, yyyy-MM-dd} です。' +// 出力例: '今日は 2015-01-07 です。' +``` + +[書式のリファレンス](http://icu-project.org/apiref/icu4c/classicu_1_1SimpleDateFormat.html). + +#### 時刻 + +```php +echo \Yii::t('app', 'It is {0, time}', time()); + +// 翻訳例: '現在 {0, time} です。' +// 出力例: '現在 22:37:47 です。' +``` + +内蔵の書式は、`short`、`medium`、`long`、そして `full` です。 + +```php +echo \Yii::t('app', 'It is {0, time, short}', time()); + +// 翻訳例: '現在 {0, time, short} です。' +// 出力例: '現在 22:37 です。' +``` + +カスタムパターンを指定することも出来ます。 + +```php +echo \Yii::t('app', 'It is {0, date, HH:mm}', time()); + +// 翻訳例: '現在 {0, time, HH:mm} です。' +// 出力例: '現在 22:37 です。' +``` + +[書式のリファレンス](http://icu-project.org/apiref/icu4c/classicu_1_1SimpleDateFormat.html). + + +#### 綴り + +```php +echo \Yii::t('app', '{n, number} is spelled as {n, spellout}', ['n' => 12345]); + +// 翻訳例: '{n, number} は、文字で綴ると {n, spellout} です。' +// 出力例: '12,345 は、文字で綴ると 一万二千三百四十五 です。' +``` + +#### 序数 + +```php +echo \Yii::t('app', 'You are the {n, ordinal} visitor here!', ['n' => 42]); +``` + +これは、"You are the 42nd visitor here!" というメッセージになります。 + +> Tip|ヒント: 上記のソースメッセージを、プレースホルダの書式指定を守って日本語に翻訳すると、'あなたはこのサイトの {n, ordinal} の訪問者です。' となります。 +> しかし、その出力結果は、'あなたはこのサイトの 第42 の訪問者です。' となり、意味は通じますが、日本語としては若干不自然なものになります。 +> この場合は、'あなたはこのサイトの {n} 番目の訪問者です。' のように、プレースホルダの書式も含めて全体を翻訳する方が良いでしょう。 + +#### 継続時間 + +```php +echo \Yii::t('app', 'You are here for {n, duration} already!', ['n' => 47]); +``` + +これは、"You are here for 47 sec. already!" というメッセージになります。 + +> Tip|ヒント: このソースメッセージを 'あなたはこのサイトに既に {n, duration} 滞在しています。' と翻訳した場合の出力結果は、'あなたはこのサイトに既に 47 滞在しています。' となります。 +> これも、プレースホルダの書式も含めて全体を翻訳し直す方が良いようです。 + + +#### Plurals + +Different languages have different ways to inflect plurals. Yii provides a convenient way for translating messages in +different plural forms that works well even for very complex rules. Instead of dealing with the inflection rules directly +it is sufficient to provide the translation of inflected words in certain situations only. + +```php +echo \Yii::t('app', 'There {n, plural, =0{are no cats} =1{is one cat} other{are # cats}}!', ['n' => $n]); +``` + +Will give us + +- "There are no cats!" for `$n = 0`, +- "There is one cat!" for `$n = 1`, +- and "There are 42 cats!" for `$n = 42`. + +In the plural rule arguments above `=0` means exactly zero, `=1` stands for exactly one, and `other` is for any other number. +`#` is replaced with the value of `n`. It's not that simple for languages other than English. Here's an example +for Russian: + +``` +Здесь {n, plural, =0{котов нет} =1{есть один кот} one{# кот} few{# кота} many{# котов} other{# кота}}! +``` + +In the above it's worth mentioning that `=1` matches exactly `n = 1` while `one` matches `21` or `101`. + +Note, that you can not use the Russian example in `Yii::t()` directly if your +[[yii\base\Application::$sourceLanguage|source language]] isn't set to `ru_RU`. This however is not recommended, instead such +strings should go into message files or message database (in case DB source is used). Yii uses plural rules of the +translated language strings and is falling back to plural rules of source language if translation isn't available. + +To learn which inflection forms you should specify for your language you can referrer to the +[rules reference at unicode.org](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html). + +#### Selections + +You can select phrases based on keywords. The pattern in this case specifies how to map keywords to phrases and +provides a default phrase. + +```php +echo \Yii::t('app', '{name} is {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!', [ + 'name' => 'Snoopy', + 'gender' => 'dog', +]); +``` + +Will produce "Snoopy is dog and it loves Yii!". + +In the expression `female` and `male` are possible values. `other` handles values that do not match. Strings inside +brackets are sub-expressions so could be just a string or a string with more placeholders. + +### Specifying default translation + +You can specify default translations that will be used as a fallback for categories that don't match any other translation. +This translation should be marked with `*`. In order to do it add the following to the application config: + +```php +//configure i18n component + +'i18n' => [ + 'translations' => [ + '*' => [ + 'class' => 'yii\i18n\PhpMessageSource' + ], + ], +], +``` + +Now you can use categories without configuring each one, which is similar to Yii 1.1 behavior. +Messages for the category will be loaded from a file under the default translation `basePath` that is `@app/messages`: + +```php +echo Yii::t('not_specified_category', 'message from unspecified category'); +``` + +Message will be loaded from `@app/messages//not_specified_category.php`. + +### Translating module messages + +If you want to translate messages for a module and avoid using a single translation file for all messages, you can do it like the following: + +```php +registerTranslations(); + } + + public function registerTranslations() + { + Yii::$app->i18n->translations['modules/users/*'] = [ + 'class' => 'yii\i18n\PhpMessageSource', + 'sourceLanguage' => 'en-US', + 'basePath' => '@app/modules/users/messages', + 'fileMap' => [ + 'modules/users/validation' => 'validation.php', + 'modules/users/form' => 'form.php', + ... + ], + ]; + } + + public static function t($category, $message, $params = [], $language = null) + { + return Yii::t('modules/users/' . $category, $message, $params, $language); + } + +} +``` + +In the example above we are using wildcard for matching and then filtering each category per needed file. Instead of using `fileMap` you can simply +use convention of category mapping to the same named file and use `Module::t('validation', 'your custom validation message')` or `Module::t('form', 'some form label')` directly. + +### Translating widgets messages + +The same rule as applied for Modules above can be applied for widgets too, for example: + +```php +registerTranslations(); + } + + public function registerTranslations() + { + $i18n = Yii::$app->i18n; + $i18n->translations['widgets/menu/*'] = [ + 'class' => 'yii\i18n\PhpMessageSource', + 'sourceLanguage' => 'en-US', + 'basePath' => '@app/widgets/menu/messages', + 'fileMap' => [ + 'widgets/menu/messages' => 'messages.php', + ], + ]; + } + + public function run() + { + echo $this->render('index'); + } + + public static function t($category, $message, $params = [], $language = null) + { + return Yii::t('widgets/menu/' . $category, $message, $params, $language); + } + +} +``` + +Instead of using `fileMap` you can simply use convention of category mapping to the same named file and use `Menu::t('messages', 'new messages {messages}', ['{messages}' => 10])` directly. + +> **Note**: For widgets you also can use i18n views, same rules as for controllers are applied to them too. + + +### Translating framework messages + +Yii comes with default translation messages for validation errors and some other strings. These messages are all +in the category `yii`. Sometimes you want to correct default framework message translation for your application. +In order to do so configure the `i18n` [application component](structure-application-components.md) like the following: + +```php +'i18n' => [ + 'translations' => [ + 'yii' => [ + 'class' => 'yii\i18n\PhpMessageSource', + 'sourceLanguage' => 'en-US', + 'basePath' => '@app/messages' + ], + ], +], +``` + +Now you can place your adjusted translations to `@app/messages//yii.php`. + +### Handling missing translations + +If the translation is missing at the source, Yii displays the requested message content. Such behavior is very convenient +in case your raw message is a valid verbose text. However, sometimes it is not enough. +You may need to perform some custom processing of the situation, when requested translation is missing at the source. +This can be achieved using the [[yii\i18n\MessageSource::EVENT_MISSING_TRANSLATION|missingTranslation]]-event of [[yii\i18n\MessageSource]]. + +For example to mark all missing translations with something notable, so they can be easily found at the page we +first we need to setup event handler. This can be done in the application configuration: + +```php +'components' => [ + // ... + 'i18n' => [ + 'translations' => [ + 'app*' => [ + 'class' => 'yii\i18n\PhpMessageSource', + 'fileMap' => [ + 'app' => 'app.php', + 'app/error' => 'error.php', + ], + 'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation'] + ], + ], + ], +], +``` + +Now we need to implement our own event handler: + +```php +translatedMessage = "@MISSING: {$event->category}.{$event->message} FOR LANGUAGE {$event->language} @"; + } +} +``` + +If [[yii\i18n\MissingTranslationEvent::translatedMessage]] is set by the event handler it will be displayed as the translation result. + +> Attention: each message source handles its missing translations separately. If you are using several message sources +> and wish them treat missing translation in the same way, you should assign corresponding event handler to each of them. + + +Views +----- + +Instead of translating messages as described in the last section, +you can also use `i18n` in your views to provide support for different languages. For example, if you have a view `views/site/index.php` and +you want to create a special version for russian language of it, you create a `ru-RU` folder under the view path of the current controller/widget and +put the file for russian language as follows `views/site/ru-RU/index.php`. Yii will then load the file for the current language if it exists +and fall back to the original view file if none was found. + +> **Note**: If language is specified as `en-US` and there are no corresponding views, Yii will try views under `en` +> before using original ones. + + +Formatting Number and Date values +--------------------------------- + +See the [data formatter section](output-formatter.md) for details. + + +Setting up your PHP environment +------------------------------- + +Yii uses the [PHP intl extension](http://php.net/manual/en/book.intl.php) to provide most of its internationalization features +such as the number and date formatting of the [[yii\i18n\Formatter]] class and the message formatting using [[yii\i18n\MessageFormatter]]. +Both classes provides a fallback implementation that provides basic functionality in case intl is not installed. +This fallback implementation however only works well for sites in english language and even there can not provide the +rich set of features that is available with the PHP intl extension, so its installation is highly recommended. + +The [PHP intl extension](http://php.net/manual/en/book.intl.php) is based on the [ICU library](http://site.icu-project.org/) which +provides the knowledge and formatting rules for all the different locales. According to this fact the formatting of dates and numbers +and also the supported syntax available for message formatting differs between different versions of the ICU library that is compiled with +you PHP binary. + +To ensure your website works with the same output in all environments it is recommended to install the PHP intl extension +in all environments and verify that the version of the ICU library compiled with PHP is the same. + +To find out which version of ICU is used by PHP you can run the following script, which will give you the PHP and ICU version used. + +```php + for a list of available ICU versions. Note that the version numbering has changed after the +4.8 release so that the first digits are now merged: the sequence is ICU 4.8, ICU 49, ICU 50. + +Additionally the information in the time zone database shipped with the ICU library may be outdated. Please refer +to the [ICU manual](http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data) for details +on updating the time zone database. While for output formatting the ICU timezone database is used, the time zone database +used by PHP may be relevant too. You can update it by installing the latest version of the [pecl package `timezonedb`](http://pecl.php.net/package/timezonedb). From 0d7fe0bd7db2988f0d47ee67e374a52129951d97 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Thu, 8 Jan 2015 01:11:44 +0900 Subject: [PATCH 2/5] docs/guide-ja/tutorial-i18n.md - WIP [ci skip] --- docs/guide-ja/tutorial-i18n.md | 105 ++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/docs/guide-ja/tutorial-i18n.md b/docs/guide-ja/tutorial-i18n.md index 02d7ef0fab..c3443d96f0 100644 --- a/docs/guide-ja/tutorial-i18n.md +++ b/docs/guide-ja/tutorial-i18n.md @@ -100,7 +100,7 @@ Yii は `i18n` [アプリケーションコンポーネント](structure-applica - [[yii\i18n\DbMessageSource]] - データベースを使用 -> Info|情報: 以下においては、メッセージ書式の理解を助けるために、原文にはない日本語へのメッセージの翻訳例 (と出力結果) を追加している個所があります。 +> Note|訳注: 以下においては、メッセージ書式の理解を助けるために、コード例に原文にはない日本語への翻訳例 (とその出力結果) を追加しています。 ### 名前付きプレースホルダ @@ -113,7 +113,7 @@ echo \Yii::t('app', 'Hello, {username}!', [ 'username' => $username, ]); -// 翻訳例: '{username} さん、こんにちは!' +// 翻訳: '{username} さん、こんにちは!' ``` パラメータへの代入には波括弧を使わないことに注意してください。 @@ -124,7 +124,7 @@ echo \Yii::t('app', 'Hello, {username}!', [ $sum = 42; echo \Yii::t('app', 'Balance: {0}', $sum); -// 翻訳例: '差引残高: {0}' +// 翻訳: '差引残高: {0}' ``` > **Tip**|ヒント: メッセージ文字列の意味が分らなくならないように努めて、あまりに多くの序数プレースホルダを使うことは避けてください。 @@ -134,7 +134,7 @@ echo \Yii::t('app', 'Balance: {0}', $sum); 高度な機能を使うためには、[intl PHP 拡張](http://www.php.net/manual/ja/intro.intl.php) をインストールして有効にする必要があります。 それをインストールして有効にして初めて、プレースホルダのための拡張構文を使うことが出来るようになります。 -すなわち、デフォルトの書式を意味する短い形式 `{placeholderName, argumentType}`、あるいは、書式のスタイルを指定できる完全な形式 `{placeholderName, argumentType, argumentStyle}` を使うことが出来るようになります。 +すなわち、デフォルトの書式を意味する短い形式 `{プレースホルダ名, タイプ}`、あるいは、書式のスタイルを指定できる完全な形式 `{プレースホルダ名, タイプ, スタイル}` を使うことが出来るようになります。 完全なリファレンスは [ICU ウェブサイト](http://icu-project.org/apiref/icu4c/classMessageFormat.html) で入手可能ですが、以下においてはいくつかの例を示します。 @@ -144,8 +144,8 @@ echo \Yii::t('app', 'Balance: {0}', $sum); $sum = 42; echo \Yii::t('app', 'Balance: {0, number}', $sum); -// 翻訳例: '差引残高: {0, number}' -// 出力例: '差引残高: 12,345' +// 翻訳: '差引残高: {0, number}' +// 出力: '差引残高: 12,345' ``` 内蔵のスタイル (`integer`、`currency`、`percent`) の一つを指定することが出来ます。 @@ -154,8 +154,8 @@ echo \Yii::t('app', 'Balance: {0, number}', $sum); $sum = 42; echo \Yii::t('app', 'Balance: {0, number, currency}', $sum); -// 翻訳例: '差引残高: {0, number, currency}' -// 出力例: '差引残高: ¥ 12,345' +// 翻訳: '差引残高: {0, number, currency}' +// 出力: '差引残高: ¥ 12,345' ``` または、カスタムパターンを指定することも出来ます。 @@ -164,8 +164,8 @@ echo \Yii::t('app', 'Balance: {0, number, currency}', $sum); $sum = 42; echo \Yii::t('app', 'Balance: {0, number, ,000,000000}', $sum); -// 翻訳例: '差引残高: {0, number, ,000,000000}' -// 出力例: '差引残高: 000,012345' +// 翻訳: '差引残高: {0, number, ,000,000000}' +// 出力: '差引残高: 000,012345' ``` [書式のリファレンス](http://icu-project.org/apiref/icu4c/classicu_1_1DecimalFormat.html). @@ -175,8 +175,8 @@ echo \Yii::t('app', 'Balance: {0, number, ,000,000000}', $sum); ```php echo \Yii::t('app', 'Today is {0, date}', time()); -// 翻訳例: '今日は {0, date} です。' -// 出力例: '今日は 2015/01/07 です。' +// 翻訳: '今日は {0, date} です。' +// 出力: '今日は 2015/01/07 です。' ``` 内蔵の書式は、`short`、`medium`、`long`、そして `full` です。 @@ -184,8 +184,8 @@ echo \Yii::t('app', 'Today is {0, date}', time()); ```php echo \Yii::t('app', 'Today is {0, date, short}', time()); -// 翻訳例: '今日は {0, date, short} です。' -// 出力例: '今日は 2015/01/07 です。' +// 翻訳: '今日は {0, date, short} です。' +// 出力: '今日は 2015/01/07 です。' ``` カスタムパターンを指定することも出来ます。 @@ -193,8 +193,8 @@ echo \Yii::t('app', 'Today is {0, date, short}', time()); ```php echo \Yii::t('app', 'Today is {0, date, yyyy-MM-dd}', time()); -// 翻訳例: '今日は {0, date, yyyy-MM-dd} です。' -// 出力例: '今日は 2015-01-07 です。' +// 翻訳: '今日は {0, date, yyyy-MM-dd} です。' +// 出力: '今日は 2015-01-07 です。' ``` [書式のリファレンス](http://icu-project.org/apiref/icu4c/classicu_1_1SimpleDateFormat.html). @@ -204,8 +204,8 @@ echo \Yii::t('app', 'Today is {0, date, yyyy-MM-dd}', time()); ```php echo \Yii::t('app', 'It is {0, time}', time()); -// 翻訳例: '現在 {0, time} です。' -// 出力例: '現在 22:37:47 です。' +// 翻訳: '現在 {0, time} です。' +// 出力: '現在 22:37:47 です。' ``` 内蔵の書式は、`short`、`medium`、`long`、そして `full` です。 @@ -213,8 +213,8 @@ echo \Yii::t('app', 'It is {0, time}', time()); ```php echo \Yii::t('app', 'It is {0, time, short}', time()); -// 翻訳例: '現在 {0, time, short} です。' -// 出力例: '現在 22:37 です。' +// 翻訳: '現在 {0, time, short} です。' +// 出力: '現在 22:37 です。' ``` カスタムパターンを指定することも出来ます。 @@ -222,8 +222,8 @@ echo \Yii::t('app', 'It is {0, time, short}', time()); ```php echo \Yii::t('app', 'It is {0, date, HH:mm}', time()); -// 翻訳例: '現在 {0, time, HH:mm} です。' -// 出力例: '現在 22:37 です。' +// 翻訳: '現在 {0, time, HH:mm} です。' +// 出力: '現在 22:37 です。' ``` [書式のリファレンス](http://icu-project.org/apiref/icu4c/classicu_1_1SimpleDateFormat.html). @@ -234,8 +234,8 @@ echo \Yii::t('app', 'It is {0, date, HH:mm}', time()); ```php echo \Yii::t('app', '{n, number} is spelled as {n, spellout}', ['n' => 12345]); -// 翻訳例: '{n, number} は、文字で綴ると {n, spellout} です。' -// 出力例: '12,345 は、文字で綴ると 一万二千三百四十五 です。' +// 翻訳: '{n, number} は、文字で綴ると {n, spellout} です。' +// 出力: '12,345 は、文字で綴ると 一万二千三百四十五 です。' ``` #### 序数 @@ -246,9 +246,12 @@ echo \Yii::t('app', 'You are the {n, ordinal} visitor here!', ['n' => 42]); これは、"You are the 42nd visitor here!" というメッセージになります。 -> Tip|ヒント: 上記のソースメッセージを、プレースホルダの書式指定を守って日本語に翻訳すると、'あなたはこのサイトの {n, ordinal} の訪問者です。' となります。 -> しかし、その出力結果は、'あなたはこのサイトの 第42 の訪問者です。' となり、意味は通じますが、日本語としては若干不自然なものになります。 -> この場合は、'あなたはこのサイトの {n} 番目の訪問者です。' のように、プレースホルダの書式も含めて全体を翻訳する方が良いでしょう。 +> Note|訳注: 上記のソースメッセージを、プレースホルダの書式指定を守って日本語に翻訳すると、'あなたはこのサイトの {n, ordinal} の訪問者です' となります。 +> しかし、その出力結果は、'あなたはこのサイトの 第42 の訪問者です' となり、意味は通じますが、日本語としては若干不自然なものになります。 +> +> プレースホルダの書式指定は、翻訳時に変更することが可能であるだけでなく、進んで変更すべき場合すらあります。 +> +> この場合も、'あなたはこのサイトの {n} 番目の訪問者です' のように、プレースホルダの書式も含めて全体を翻訳する方が良いでしょう。 #### 継続時間 @@ -258,43 +261,51 @@ echo \Yii::t('app', 'You are here for {n, duration} already!', ['n' => 47]); これは、"You are here for 47 sec. already!" というメッセージになります。 -> Tip|ヒント: このソースメッセージを 'あなたはこのサイトに既に {n, duration} 滞在しています。' と翻訳した場合の出力結果は、'あなたはこのサイトに既に 47 滞在しています。' となります。 -> これも、プレースホルダの書式も含めて全体を翻訳し直す方が良いようです。 +> Note|訳注: このソースメッセージを 'あなたはこのサイトに既に {n, duration} の間滞在しています' と翻訳した場合の出力結果は、'あなたはこのサイトに既に 47 の間滞在しています' となります。 +> ICU ライブラリのバグでしょうか。これも、プレースホルダの書式も含めて全体を翻訳し直す方が良いようです。 -#### Plurals +#### 複数形 -Different languages have different ways to inflect plurals. Yii provides a convenient way for translating messages in -different plural forms that works well even for very complex rules. Instead of dealing with the inflection rules directly -it is sufficient to provide the translation of inflected words in certain situations only. +言語によって、複数形の語形変化はさまざまに異なります。 +Yii は、さまざまな形式の複数形語形変化に対応したメッセージ翻訳のための便利な方法を提供しています。 +それは、非常に複雑な規則に対しても、十分に機能するものです。 +語形変化の規則を直接に処理する代りに、特定の状況における語形変化した言葉の翻訳を提供するだけで十分です。 ```php echo \Yii::t('app', 'There {n, plural, =0{are no cats} =1{is one cat} other{are # cats}}!', ['n' => $n]); ``` -Will give us +結果は以下のようになります。 -- "There are no cats!" for `$n = 0`, -- "There is one cat!" for `$n = 1`, -- and "There are 42 cats!" for `$n = 42`. +- `$n = 0` の場合は "There are no cats!" +- `$n = 1` の場合は "There is one cat!" +- そして `$n = 42` の場合は "There are 42 cats!" -In the plural rule arguments above `=0` means exactly zero, `=1` stands for exactly one, and `other` is for any other number. -`#` is replaced with the value of `n`. It's not that simple for languages other than English. Here's an example -for Russian: +上記の複数形規則の引数において、`=0` はぴったりゼロ、`=1` はぴったり 1、そして `other` はそれ以外の数を表します。 +`#` は `n` の値によって置き換えられます。 +英語以外の言語では、これほど単純ではありません。 +例えば、次はロシア語の例です。 ``` Здесь {n, plural, =0{котов нет} =1{есть один кот} one{# кот} few{# кота} many{# котов} other{# кота}}! ``` -In the above it's worth mentioning that `=1` matches exactly `n = 1` while `one` matches `21` or `101`. +上の例について言及する価値があると思われるのは、`=1` が `n = 1` にぴったりと一致するのに対して、`one` が `21` や `101` などに一致する、ということです。 -Note, that you can not use the Russian example in `Yii::t()` directly if your -[[yii\base\Application::$sourceLanguage|source language]] isn't set to `ru_RU`. This however is not recommended, instead such -strings should go into message files or message database (in case DB source is used). Yii uses plural rules of the -translated language strings and is falling back to plural rules of source language if translation isn't available. +注意して欲しいのは、あなたの [[yii\base\Application::$sourceLanguage|ソース言語]] を `ru_RU` に設定しなければ、このロシア語のメッセージを `Yii::t()` の中に直接に書くことは出来ない、ということです。 +ただし、ソース言語を `ru_RU` に設定することは推奨されません。 +むしろ、このような文字列はメッセージファイルまたは (DB ソースが使われている場合は) メッセージデータベースに入れるべきです。 +Yii は翻訳された言語の文字列の複数形規則を使い、翻訳が入手できない場合にはソース言語の複数形規則に後退します。 -To learn which inflection forms you should specify for your language you can referrer to the -[rules reference at unicode.org](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html). +あなたの言語について、どのような語形変化を指定すべきかを学習するためには、[unicode.org にある規則のリファレンス](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html) を参照してください。 + +> Note|訳注: 最初のソースメッセージの日本語翻訳は以下のようなものになります。 +> +> '猫は{n, plural, =0{いません} other{#匹います}}。' +> +> 日本語では単数形と複数形を区別しませんので、たいていの場合、`=0` と `other` を指定するだけで事足ります。 +> 横着をして、`{n, plural, ...}` を `{n, number}` に置き換えても、多分、大きな問題は生じないでしょう。 #### Selections From 66bbe4d981b1af54cd9d65dfcb6f56aa25965f1b Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Thu, 8 Jan 2015 08:15:00 +0900 Subject: [PATCH 3/5] docs/guide-ja/tutorial-i18n.md - WIP --- docs/guide-ja/tutorial-i18n.md | 57 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/docs/guide-ja/tutorial-i18n.md b/docs/guide-ja/tutorial-i18n.md index c3443d96f0..7683097e2e 100644 --- a/docs/guide-ja/tutorial-i18n.md +++ b/docs/guide-ja/tutorial-i18n.md @@ -100,7 +100,7 @@ Yii は `i18n` [アプリケーションコンポーネント](structure-applica - [[yii\i18n\DbMessageSource]] - データベースを使用 -> Note|訳注: 以下においては、メッセージ書式の理解を助けるために、コード例に原文にはない日本語への翻訳例 (とその出力結果) を追加しています。 +> Note|訳注: 以下においては、メッセージ書式の理解を助けるために、原文にはない日本語への翻訳例 (とその出力結果) をコードサンプルに追加しています。 ### 名前付きプレースホルダ @@ -296,41 +296,46 @@ echo \Yii::t('app', 'There {n, plural, =0{are no cats} =1{is one cat} other{are 注意して欲しいのは、あなたの [[yii\base\Application::$sourceLanguage|ソース言語]] を `ru_RU` に設定しなければ、このロシア語のメッセージを `Yii::t()` の中に直接に書くことは出来ない、ということです。 ただし、ソース言語を `ru_RU` に設定することは推奨されません。 むしろ、このような文字列はメッセージファイルまたは (DB ソースが使われている場合は) メッセージデータベースに入れるべきです。 -Yii は翻訳された言語の文字列の複数形規則を使い、翻訳が入手できない場合にはソース言語の複数形規則に後退します。 +Yii は翻訳された言語の文字列にある複数形規則を使います。翻訳が入手できない場合にはソース言語の複数形規則にフォールバックします。 あなたの言語について、どのような語形変化を指定すべきかを学習するためには、[unicode.org にある規則のリファレンス](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html) を参照してください。 -> Note|訳注: 最初のソースメッセージの日本語翻訳は以下のようなものになります。 +> Note|訳注: 上記のソースメッセージの日本語翻訳は以下のようなものになります。 > > '猫は{n, plural, =0{いません} other{#匹います}}。' > > 日本語では単数形と複数形を区別しませんので、たいていの場合、`=0` と `other` を指定するだけで事足ります。 > 横着をして、`{n, plural, ...}` を `{n, number}` に置き換えても、多分、大きな問題は生じないでしょう。 -#### Selections +#### 選択肢 -You can select phrases based on keywords. The pattern in this case specifies how to map keywords to phrases and -provides a default phrase. +キーワードに基づいて表現を選択することが出来ます。 +この場合のパターンは、キーワードに対する表現の割り当てを指定し、デフォルトの表現を提供するものです。 ```php -echo \Yii::t('app', '{name} is {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!', [ +echo \Yii::t('app', '{name} is a {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!', [ 'name' => 'Snoopy', 'gender' => 'dog', ]); ``` -Will produce "Snoopy is dog and it loves Yii!". +これは "Snoopy is a dog and it loves Yii!" となります。 -In the expression `female` and `male` are possible values. `other` handles values that do not match. Strings inside -brackets are sub-expressions so could be just a string or a string with more placeholders. +式の中で、`female` と `male` が `gender` が取り得る値であり、`other` がそれらに一致しない値を処理します。 +波括弧の中の文字列は下位の式であり、単なる文字列でも、さらにプレースホルダを持つ文字列でも構いません。 -### Specifying default translation +> Note|訳注: 翻訳: '{name} は {gender} であり、{gender, select, female{彼女} male{彼} other{それ}}は Yii を愛しています。' +> +> 出力: 'Snoopy は dog であり、それは Yii を愛しています。' -You can specify default translations that will be used as a fallback for categories that don't match any other translation. -This translation should be marked with `*`. In order to do it add the following to the application config: +### デフォルトのメッセージソースを指定する + +他のメッセージソースにマッチしないカテゴリのフォールバックとして使用されるデフォルトのメッセージソースを指定することが出来ます。 +このメッセージソースは `*` によってマークされなければなりません。 +そうするためには、アプリケーションの構成情報に次のように追加します。 ```php -//configure i18n component +// i18n コンポーネントを構成する 'i18n' => [ 'translations' => [ @@ -341,18 +346,18 @@ This translation should be marked with `*`. In order to do it add the following ], ``` -Now you can use categories without configuring each one, which is similar to Yii 1.1 behavior. -Messages for the category will be loaded from a file under the default translation `basePath` that is `@app/messages`: +こうすることで、個別に構成することなくカテゴリを使うことが可能になり、Yii 1.1 の振る舞いと同じになります。 +カテゴリのメッセージは、デフォルトの翻訳の `basePath` すなわち `@app/messages` の下にあるファイルから読み込まれます。 ```php echo Yii::t('not_specified_category', 'message from unspecified category'); ``` -Message will be loaded from `@app/messages//not_specified_category.php`. +この場合、メッセージは `@app/messages//not_specified_category.php` から読み込まれます。 -### Translating module messages +### モジュールのメッセージを翻訳する -If you want to translate messages for a module and avoid using a single translation file for all messages, you can do it like the following: +モジュール用のメッセージを翻訳したいけれども、全てのメッセージに対して一つの翻訳ファイルを使うことは避けたい、という場合には、次のようにすることが出来ます。 ```php 10])` directly. +`fileMap` を使わずに、カテゴリを同じ名前のファイルにマップする規約を使って済ませることも出来ます。 +これで、直接に `Menu::t('messages', 'new messages {messages}', ['{messages}' => 10])` を使用することが出来ます。 -> **Note**: For widgets you also can use i18n views, same rules as for controllers are applied to them too. +> **Note**|注意: ウィジェットのためには i18n ビューも使うことが出来ます。コントローラのための同じ規則がウィジェットにも適用されます。 ### Translating framework messages From bdf5e62486c0b4d6dc180cb23fdda903887a48e3 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Thu, 8 Jan 2015 22:06:06 +0900 Subject: [PATCH 4/5] docs/guide-ja/tutorial-i18n.md - completed [ci skip] --- docs/guide-ja/README.md | 2 +- docs/guide-ja/tutorial-i18n.md | 97 ++++++++++++++++------------------ 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/docs/guide-ja/README.md b/docs/guide-ja/README.md index 4662f1ff29..e0cb3f4268 100644 --- a/docs/guide-ja/README.md +++ b/docs/guide-ja/README.md @@ -165,7 +165,7 @@ RESTful ウェブサービス * [アプリケーションを一から構築する](tutorial-start-from-scratch.md) * [コンソールコマンド](tutorial-console.md) * [コアバリデータ](tutorial-core-validators.md) -* **翻訳中** [国際化](tutorial-i18n.md) +* [国際化](tutorial-i18n.md) * **翻訳中** [メール](tutorial-mailing.md) * **翻訳中** [パフォーマンスチューニング](tutorial-performance-tuning.md) * **翻訳中** [共有ホスト環境](tutorial-shared-hosting.md) diff --git a/docs/guide-ja/tutorial-i18n.md b/docs/guide-ja/tutorial-i18n.md index 7683097e2e..0d02a1475d 100644 --- a/docs/guide-ja/tutorial-i18n.md +++ b/docs/guide-ja/tutorial-i18n.md @@ -455,11 +455,12 @@ class Menu extends Widget > **Note**|注意: ウィジェットのためには i18n ビューも使うことが出来ます。コントローラのための同じ規則がウィジェットにも適用されます。 -### Translating framework messages +### フレームワークメッセージを翻訳する -Yii comes with default translation messages for validation errors and some other strings. These messages are all -in the category `yii`. Sometimes you want to correct default framework message translation for your application. -In order to do so configure the `i18n` [application component](structure-application-components.md) like the following: +Yii には、バリデーションエラーとその他いくつかの文字列に対するデフォルトの翻訳メッセージが付属しています。 +これらのメッセージは、全て 'yii' というカテゴリの中にあります。 +場合によっては、あなたのアプリケーションのために、デフォルトのフレームワークメッセージの翻訳を修正したいことがあるでしょう。 +そうするためには、`i18n` [アプリケーションコンポーネント](structure-application-components.md) を以下のように構成してください。 ```php 'i18n' => [ @@ -473,17 +474,18 @@ In order to do so configure the `i18n` [application component](structure-applica ], ``` -Now you can place your adjusted translations to `@app/messages//yii.php`. +これで、あなたの修正した翻訳を `@app/messages//yii.php` に置くことが出来ます。 -### Handling missing translations +### 欠落している翻訳の処理 -If the translation is missing at the source, Yii displays the requested message content. Such behavior is very convenient -in case your raw message is a valid verbose text. However, sometimes it is not enough. -You may need to perform some custom processing of the situation, when requested translation is missing at the source. -This can be achieved using the [[yii\i18n\MessageSource::EVENT_MISSING_TRANSLATION|missingTranslation]]-event of [[yii\i18n\MessageSource]]. +ソースに翻訳が欠落している場合でも、Yii はリクエストされたメッセージの内容を原文で表示します。 +このような振舞いは、原文のメッセージが正当かつ詳細なテキストである場合には、非常に好都合です。 +しかし、場合によっては、それだけでは十分ではありません。 +リクエストされた翻訳がソースに欠落しているときに、何らかの特別な処理を実行する必要がある場合もあります。 +そういう処理は、[[yii\i18n\MessageSource]] の [[yii\i18n\MessageSource::EVENT_MISSING_TRANSLATION|missingTranslation]] イベントを使うことによって達成できます。 -For example to mark all missing translations with something notable, so they can be easily found at the page we -first we need to setup event handler. This can be done in the application configuration: +例えば、全ての欠落している翻訳を簡単に見つけられるように、何か目立つマークを付けることにしましょう。 +最初にイベントハンドラをセットアップする必要がありますが、それはアプリケーションの構成によって行うことが出来ます。 ```php 'components' => [ @@ -503,7 +505,7 @@ first we need to setup event handler. This can be done in the application config ], ``` -Now we need to implement our own event handler: +次に、私たち独自のイベントハンドラを実装する必要があります。 ```php Attention: each message source handles its missing translations separately. If you are using several message sources -> and wish them treat missing translation in the same way, you should assign corresponding event handler to each of them. +> Note|注意: 全てのメッセージソースは、欠落した翻訳をそれぞれ独自に処理します。 +> いくつかのメッセージソースを使っていて、それらが同じ方法で欠落した翻訳を取り扱うようにしたい場合は、対応するイベントハンドラを全てのメッセージソースそれぞれに割り当てなければなりません。 -Views ------ +ビュー +------ -Instead of translating messages as described in the last section, -you can also use `i18n` in your views to provide support for different languages. For example, if you have a view `views/site/index.php` and -you want to create a special version for russian language of it, you create a `ru-RU` folder under the view path of the current controller/widget and -put the file for russian language as follows `views/site/ru-RU/index.php`. Yii will then load the file for the current language if it exists -and fall back to the original view file if none was found. +前の項で説明したようなメッセージの翻訳の代りに、ビューの中で `i18n` を使ってさまざまな言語に対するサポートを提供することも出来ます。 +例えば、`views/site/index.php` というビューがあり、それのロシア語のための特別版を作りたい場合は、現在のコントローラ/ウィジェットのビューパスの下に `ru-RU` フォルダを作って、ロシア語のためのファイルを `views/site/ru-RU/index.php` として置きます。 +そうすると、Yii は、現在の言語のためのファイルが存在する場合はそれをロードし、何も見つからなかった場合はオリジナルのビューファイルにフォールバックします。 -> **Note**: If language is specified as `en-US` and there are no corresponding views, Yii will try views under `en` -> before using original ones. +> **Note**|注意: 言語が `en-US` と指定されている場合、対応するビューが無いと、Yii は `en` の下でビューを探して、そこにも無ければ、オリジナルのビューを使います。 -Formatting Number and Date values ---------------------------------- +数値と日付の値を書式設定する +---------------------------- -See the [data formatter section](output-formatter.md) for details. +詳細は [データフォーマッタ](output-formatter.md) の節を参照してください。 -Setting up your PHP environment -------------------------------- +PHP 環境をセットアップする +-------------------------- -Yii uses the [PHP intl extension](http://php.net/manual/en/book.intl.php) to provide most of its internationalization features -such as the number and date formatting of the [[yii\i18n\Formatter]] class and the message formatting using [[yii\i18n\MessageFormatter]]. -Both classes provides a fallback implementation that provides basic functionality in case intl is not installed. -This fallback implementation however only works well for sites in english language and even there can not provide the -rich set of features that is available with the PHP intl extension, so its installation is highly recommended. +Yii は、[[yii\i18n\Formatter]] クラスの数値や日付の書式設定や、[[yii\i18n\MessageFormatter]] を使うメッセージのフォーマッティングなど、ほとんどの国際化機能を提供するために [PHP intl 拡張](http://php.net/manual/ja/book.intl.php) を使います。 +この二つのクラスは、`intl` がインストールされていない場合に備えて基本的な機能を提供するフォールバックを実装しています。 +だだし、このフォールバックの実装は、英語のサイトでのみ十分に機能するものであり、たとえ英語のサイトであっても、PHP intl 拡張によって利用可能になる一連の豊かな機能を提供できるものではありません。 +従って、PHP intl 拡張のインストールが強く推奨されます。 -The [PHP intl extension](http://php.net/manual/en/book.intl.php) is based on the [ICU library](http://site.icu-project.org/) which -provides the knowledge and formatting rules for all the different locales. According to this fact the formatting of dates and numbers -and also the supported syntax available for message formatting differs between different versions of the ICU library that is compiled with -you PHP binary. +[PHP intl 拡張](http://php.net/manual/ja/book.intl.php) は、さまざまに異なる全てのロケールについて知識と書式の規則を提供する [ICU ライブラリ](http://site.icu-project.org/) に基礎を置いています。 +この事実により、日付や数値の書式設定、また、メッセージのフォーマッティングで利用できる構文は、PHP バイナリとともにコンパイルされる ICU ライブラリのバージョンの違いによって異なってきます。 -To ensure your website works with the same output in all environments it is recommended to install the PHP intl extension -in all environments and verify that the version of the ICU library compiled with PHP is the same. +あなたのウェブサイトが全ての環境で同じ出力をすることを確実にするために、全ての環境において PHP intl 拡張をインストールし、PHP とともにコンパイルされた ICU ライブラリのバージョンが同一であることを確認することが推奨されます。 -To find out which version of ICU is used by PHP you can run the following script, which will give you the PHP and ICU version used. +どのバージョンの ICU が PHP によって使われているかを知るために、次のスクリプトを走らせることが出来ます。 +このスクリプトは、使用されている PHP と ICU のバージョンを出力します。 ```php for a list of available ICU versions. Note that the version numbering has changed after the -4.8 release so that the first digits are now merged: the sequence is ICU 4.8, ICU 49, ICU 50. +このドキュメントで説明されている全ての機能を使うことが出来るように、ICU のバージョンが 49 以上であることを推奨します。 +49 未満のバージョンに欠落している主要な機能の一つが、複数形規則における `#` プレースホルダです。 +入手できる ICU バージョン については、 を参照してください。 +バージョン番号の採番方式が 4.8 リリースの後に変更されて、最初の二つの数字が結合されたことに注意してください。 +すなわち、ICU 4.8、ICU 49、ICU 50 という順序です。 -Additionally the information in the time zone database shipped with the ICU library may be outdated. Please refer -to the [ICU manual](http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data) for details -on updating the time zone database. While for output formatting the ICU timezone database is used, the time zone database -used by PHP may be relevant too. You can update it by installing the latest version of the [pecl package `timezonedb`](http://pecl.php.net/package/timezonedb). +これに加えて、ICU ライブラリとともに出荷されるタイムゾーンデータベースの情報も古くなっている可能性があります。 +タイムゾーンデータベースの更新に関する詳細は [ICU マニュアル](http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data) を参照してください。 +出力の書式設定には ICU タイムゾーンデータベースが使用されますが、PHP によって使われるタイムゾーンデータベースも影響する可能性があります。 +PHP のタイムゾーンデータベースは、[`timezonedb` pecl パッケージ](http://pecl.php.net/package/timezonedb) の最新版をインストールすることによって更新することが出来ます。 From 7b79166f160e79da4f247aa65ac90f50cd746a27 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Thu, 8 Jan 2015 22:45:15 +0900 Subject: [PATCH 5/5] docs/guide-ja updated [ci skip] --- docs/guide-ja/db-active-record.md | 5 +++++ docs/guide-ja/test-fixtures.md | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/guide-ja/db-active-record.md b/docs/guide-ja/db-active-record.md index 122492c87f..77ed23d438 100644 --- a/docs/guide-ja/db-active-record.md +++ b/docs/guide-ja/db-active-record.md @@ -91,6 +91,11 @@ $customer->email = 'jane@example.com'; $customer->save(); ``` +> Note|注意: 自明なことですが、カラム名が直接にアクティブレコードクラスの属性名になりますので、データベースの命名スキーマでアンダースコアを使用している場合はアンダースコアを持つ属性名になります。 +> 例えば、`user_name` というカラムは、アクティブレコードのオブジェクトでは `$user->user_name` としてアクセスされることになります。 +> コードスタイルが気になるのであれば、データベースの命名スキーマも camelCase を使用しなければなりません。 +> しかしながら、camelCase の使用は要求されてはいません。Yii は他のどのような命名スタイルでも十分に動作します。 + データベースに接続する ---------------------- diff --git a/docs/guide-ja/test-fixtures.md b/docs/guide-ja/test-fixtures.md index 893580836a..f3babc4e08 100644 --- a/docs/guide-ja/test-fixtures.md +++ b/docs/guide-ja/test-fixtures.md @@ -1,8 +1,6 @@ フィクスチャ ============ -> Note|注意: この節はまだ執筆中です。 - フィクスチャはテストの重要な部分です。 フィクスチャの主な目的は、テストを期待されている方法で繰り返して実行できるように、環境を固定された既知の状態に設定することです。 Yii は、フィクスチャを正確に定義して容易に使うことを可能にするフィクスチャフレームワークを提供しています。 @@ -42,6 +40,12 @@ class UserFixture extends ActiveFixture > [[yii\test\ActiveFixture::tableName]] プロパティまたは [[yii\test\ActiveFixture::modelClass]] プロパティを設定することによって、テーブルを指定することが出来ます。 > 後者を使う場合は、`modelClass` によって指定される `ActiveRecord` クラスからテーブル名が取得されます。 +> Note|注意: [[yii\test\ActiveFixture]] は SQL データベースにのみ適しています。 +> NoSQL データベースのためには、Yii は以下の `ActiveFixture` クラスを提供しています。 +> +> - Mongo DB: [[yii\mongodb\ActiveFixture]] +> - Elasticsearch: [[yii\elasticsearch\ActiveFixture]] (バージョン 2.0.2 以降) + `ActiveFixture` フィクスチャのフィクスチャデータは通常は `FixturePath/data/TableName.php` として配置されるファイルで提供されます。 ここで `FixturePath` はフィクスチャクラスファイルを含むディレクトリを意味し、`TableName` はフィクスチャと関連付けられているテーブルの名前です。 @@ -92,6 +96,10 @@ class UserProfileFixture extends ActiveFixture } ``` +依存関係は、また、複数のフィクスチャが正しく定義された順序でロードされ、アンロードされることを保証します。 +上記の例では、全ての外部キー参照が存在することを保証するために `UserFixture` は常に `UserProfileFixture` の前にロードされます。 +また、同じ理由によって、`UserFixture` は常に `UserProfileFixture` がアンロードされた後でアンロードされます。 + 上記では、DB テーブルに関してフィクスチャを定義する方法を示しました。 DB と関係しないフィクスチャ (例えば、何らかのファイルやディレクトリに関するフィクスチャ) を定義するためには、より汎用的な基底クラス [[yii\test\Fixture]] から拡張して、[[yii\test\Fixture::load()|load()]] と [[yii\test\Fixture::unload()|unload()]] のメソッドをオーバーライドすることが出来ます。 @@ -232,7 +240,9 @@ data\ Managing Fixtures ================= -// todo: this tutorial may be merged into test-fixture.md +> Note: This section is under development. +> +> todo: this tutorial may be merged with the above part of test-fixtures.md Fixtures are important part of testing. Their main purpose is to populate you with data that needed by testing different cases. With this data using your tests becoming more efficient and useful.