Cakephp-internationalization
CakePHP-国際化
他の多くのフレームワークと同様に、CakePHPも国際化をサポートしています。 単一の言語から複数の言語に移行するには、次の手順に従う必要があります。
ステップ1 *-別のロケールディレクトリ *src \ Locale を作成します。
- ステップ2 *-ディレクトリsrc \ Localeの下に各言語のサブディレクトリを作成します。 サブディレクトリの名前は、言語の2文字のISOコードまたはen_US、fr_FRなどの完全なロケール名にすることができます。
ステップ3 *-各言語サブディレクトリの下に個別の *default.po ファイルを作成します。 このファイルには、次のプログラムに示すように、 msgid および msgstr の形式のエントリが含まれています。
ここで、 msgid はViewテンプレートファイルで使用されるキーであり、 msgstr は翻訳を保存する値です。
ステップ4 *-Viewテンプレートファイルでは、ロケールの設定値に基づいて翻訳される上記の *msgid を以下に示すように使用できます。
デフォルトのロケールは、次の行で config/bootstrap.php ファイルで設定できます。
実行時にローカルを変更するには、次の行を使用できます。
例
次のプログラムに示すように、config/routes.phpファイルに変更を加えます。
次のURLにアクセスして、上記の例を実行します。
出力
実行すると、次の出力が表示されます。
Eメール
CakePHPは、Eメール関連の機能を管理するEmailクラスを提供します。 コントローラーで電子メール機能を使用するには、まず次の行を記述してEmailクラスをロードする必要があります。
Emailクラスは、以下で説明するさまざまな便利なメソッドを提供します。
Syntax | From (string |
array | null $email null, string |
null $name null ) | Parameters |
|
Returns |
array | $this |
Description | It specifies from which email address; the email will be sent |
Syntax | To (string |
array | null $email null, string |
null $name null) | Parameters |
|
Returns |
array | $this |
Description | It specifies to whom the email will be sent |
Syntax | Send (string |
array | null $content null) |
Parameters |
|
Returns | array |
Description | Send an email using the specified content, template and layout |
Syntax | Subject (string |
null $subject null) | Parameters |
|
Returns |
array | $this |
Description | Get/Set Subject. |
Syntax | Attachments (string |
array | null $attachments null) |
Parameters |
|
Returns | array |
$this | Description |
Syntax | Bcc (string |
array | null $email null, string |
null $name null) | Parameters |
|
Returns |
array | $this |
Description | Bcc |
Syntax | cc( string |
array | null $email null, string |
null $name null ) | Parameters |
|
Returns |
array | $this |
Description | Cc |
例
次のプログラムに示すように、config/routes.phpファイルに変更を加えます。
メールを送信する前に、設定する必要があります。 下のスクリーンショットでは、デフォルトとGmailの2つのトランスポートがあることがわかります。 Gmailトランスポートを使用しました。 「GMAIL USERNAME」をGmailユーザー名に、「APP PASSWORD」をアプリケーションパスワードに置き換える必要があります。 メールを送信するには、Gmailで2段階認証プロセスを有効にし、新しいAPPパスワードを作成する必要があります。
次のURLにアクセスして、上記の例を実行します。 http://localhost:85/CakePHP/email
出力
実行すると、次の出力が表示されます。