forked from NEKOGET/FuelPHP_docs_jp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlang.html
576 lines (541 loc) · 20.1 KB
/
lang.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Lang::";
</script>
<script src="./../assets/js/combined.js"></script>
<title>Lang - クラス - FuelPHP ドキュメント</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<a href="http://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="検索" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">目次</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<h2>Lang クラス</h2>
<p>Lang クラスは、アプリケーション内の言語ファイルを使用して言語の変数をセットすることができます。</p>
<p>
デフォルトの言語は、<kbd>app/config/config.php</kbd> の中で <code>en</code> と設定されています。
値を変更するには、<a href="./config.html#method_set">Config の set メソッド</a> を使用してください。
</p>
<pre class="php"><code>Config::set('language', 'cy');</code></pre>
<p>
フォールバック言語を設定の中で言語コードや言語コードの配列として定義することもできます。
言語ファイルを読み込むときに指定した言語ファイルが存在しなければ、
フォールバック言語が使用されます。
</p>
<h3 id="multi_lang">多言語サポート</h3>
<p>
Lang クラスは同時に使うことができる多数の言語をサポートしています。
デフォルトでは、ファイルの読み込みと言語文字列の取得は現在設定されている言語で行われます。
しかし、上記のメソッドを使うか、または必要な言語コードを Lang クラスのメソッドで呼び出すことによって動的に切り替えることができます。
</p>
<h3 id="lang_groups">言語ファイルの種類</h3>
言語ファイルを保存するのに、さまざまなファイルレイアウトを使用できます。レイアウトの種類は、ファイルの拡張子で決められます。
<ul>
<li>
PHP 。デフォルト。PHP ファイルは配列構造を返します。
<pre class="php"><code> return array('key' => 'value');</code></pre>
</li>
<li>
INI 。ini ファイルのレイアウトについては、<a href="http://ja.wikipedia.org/wiki/INI%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB">このページ</a> をごらんください。
<pre class="ini"><code> [group]
key=value</code></pre>
</li>
<li>
YAML 。yaml ファイルのレイアウトについては、<a href="http://ja.wikipedia.org/wiki/YAML">このページ</a> をごらんください。
<pre class="yaml"><code> group:
key: value</code></pre>
</li>
<li>
JSON 。json ファイルのレイアウトについては、<a href="http://ja.wikipedia.org/wiki/JSON">このページ</a> をごらんください。
<pre class="javascript"><code> {
"group" :
{
"key": "value"
}
}</code></pre>
</li>
<li>
DB 。次のようなテーブル構造を用います。
<pre class="php"><code> CREATE TABLE IF NOT EXISTS `lang` (
`identifier` char(100) NOT NULL,
`language` char(10) NOT NULL,
`lang` longtext NOT NULL,
`hash` char(13) NOT NULL,
PRIMARY KEY (`identifier`, `language`)
)</code></pre>
デフォルトでは、'lang' というテーブル名を使用します。
<code>app/config/config.php</code> の中にあるキー <strong>lang.table_name</strong> に使いたいテーブル名を定義することで変更ができます。
</li>
</ul>
<p>ファイルの種類を指定しない場合、Lang::load() はデフォルトの 'php' を使用します。</p>
<article>
<h4 class="method" id="method_load">load($file, $group = null, $language = null, $overwrite = false, $reload = false)</h4>
<p><strong>load</strong> メソッドは、言語ファイルを読み込むことができます。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td><i>必須</i></td>
<td>求めるファイルへのパス。読み込まれたパッケージやモジュールから読み込むために、名前空間のプレフィックスを付けることができます。</td>
</tr>
<tr>
<th><kbd>$group</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>使用する言語グループをセットします。</td>
</tr>
<tr>
<th><kbd>$language</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>読み込みたい指定の言語をセットします。</td>
</tr>
<tr>
<th><kbd>$overwrite</kbd></th>
<td><kbd>false</kbd></td>
<td>(オプション) <kbd>true</kbd> にセットしたならば、読み込んだ言語アイテムは既にある読み込まれたアイテムと非再帰的な方法でマージされます。多次元配列である場合は、マージするのではなく配列の値が上書きされます。</td>
</tr>
<tr>
<th><kbd>$reload</kbd></th>
<td><kbd>false</kbd></td>
<td>(オプション) <kbd>true</kbd> にセットしたならば、要求された言語ファイルは再読み込みが強制され、読み込まれている言語ファイルに関連した言語アイテムのキャッシュが削除されます。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>void</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 言語ファイルの例:
return array(
'hello' => 'Hello :name',
'something'=> 'something :name!',
'test'=> array('hello' => 'Hello', 'something' => 'Plop') // グループ
);
// example.php を読み込む。
// 注意: 設定に言語がセットされていないならば、英語が代わりに使われます。
Lang::load('example');
// 'test' グループの中の指定したファイルが読み込まれます。
Lang::load('example', 'test');
// プロパティの出力
$this->output = Lang::get('test.test.something');
// 'bar' グループの中の 'foo' モジュールから example 言語ファイルが読み込まれます。
Lang::load('foo::example', 'bar');
// イタリア語の言語ファイル example が読み込まれます。
// 存在しなかったならば、設定されている言語が読み込まれます
Lang::load('foo::example', 'bar', 'it');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_get">get($line, $params = array(), $default = null, $language = null)</h4>
<p><strong>get</strong> メソッドは、言語ファイルから指定した行を取得します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$line</kbd></th>
<td><i>必須</i></td>
<td>求める行の識別子。</td>
</tr>
<tr>
<th><kbd>$parameters</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>行へ渡されるパラメータの配列をセットします。</td>
</tr>
<tr>
<th><kbd>$default</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>$line が見つからなければ返す値。</td>
</tr>
<tr>
<th><kbd>$language</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>この行で取得したい言語コード。与えられないならば、現在アクティブな言語が使用されます。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed 。見つかれば String 、見つからなければ false</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// この言語ファイルを与える
return array('hello' => 'Hello :name');
// Hello world を出力
$this->output = Lang::get('hello', array('name' => 'world'));
// プロパティの出力
$this->output = Lang::get('test.something');
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set">set($line, $value, $group = null, $language = null)</h4>
<p><strong>set</strong> メソッドは、指定した行を言語ファイルにセットすることができます。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$line</kbd></th>
<td><i>必須</i></td>
<td>求める行の識別子。</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>行の値をセットする。</td>
</tr>
<tr>
<th><kbd>$group</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>使用する言語グループをセットする。</td>
</tr>
<tr>
<th><kbd>$language</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>この行でセットしたい言語コード。与えられないならば、現在アクティブな言語が使用されます。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>void</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// true を返す
Lang::set('hello', 'Ahoy!');
// グループを使って
Lang:set('hello', 'Ahoy!', 'test');
// 上と同じ様な動作
Lang::load('test', 'test');
Lang::set('hello', 'Ahoy!');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_save">save($file, $lang, $language = null)</h4>
<p>
<strong>save</strong> メソッドは、システムの中に言語ファイルを保存します。要求されたファイルの言語ディレクトリを検索します。
もしファイルが見つからないならば、APPPATH の lang ディレクトリに言語ファイルを作成します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$file</kbd></th>
<td><i>必須</i></td>
<td>設定ファイルのパスは、config ディレクトリに対する相対パスです。ファイル拡張子を含まないでください (拡張子として ".php" であることが決め打ちされています) 。読み込まれたパッケージやモジュールの設定ファイルを読み込むために、名前空間のプレフィックスを付けることが出来ます。</td>
</tr>
<tr>
<th><kbd>$lang</kbd></th>
<td><i>必須</i></td>
<td>文字列ならばグループ名を指定して保存します。配列ならば、言語文字列が含まれているとして保存します。</td>
</tr>
<tr>
<th><kbd>$language</kbd></th>
<td><code>null</code></td>
<td>ファイルに保存される言語コード。指定されないならば、現在セットされている言語コードで保存されます。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>言語ファイルが保存されたら <kbd>true</kbd> 、エラーが発生したら <kbd>false</kbd></td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// これは、"foo" という名前のグループにある言語ファイル "custom" を読み込む。
Lang::load('custom', 'foo');
// 言語のアイテムを更新する
Lang::set('foo.key', $value);
// 更新された言語グループ 'foo' を保存 (注意: グループの中の全てのものが保存されます!)
Lang::save('custom', 'foo');
// 更新された言語グループ 'foo' を モジュール 'foo' の中の 言語ファイル 'custom' に保存
Lang::save('foo::custom', 'bar');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_delete">delete($item, $group = null, $language = null)</h4>
<p><strong>delete</strong> メソッドは、<em>読み込まれた</em> 言語ファイルから指定された行を削除します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$item</kbd></th>
<td><i>必須</i></td>
<td>求める行の識別子。</td>
</tr>
<tr>
<th><kbd>$group</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>使いたい言語グループをセットします。</td>
</tr>
<tr>
<th><kbd>$language</kbd></th>
<td><pre class="php"><code>null</code></pre></td>
<td>削除する行の言語コード。与えられないならば、現在アクティブな言語が使用されます。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>void</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 言語キー 'hello' を削除
Lang::delete('hello');
</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">
language クラスに格納された言語アイテムを削除するのであって、ディスクにある言語ファイルから削除<em>しない</em>ことに注意してください。
</p>
</article>
<article>
<h4 class="method" id="method_get_lang">get_lang()</h4>
<p><strong>get_lang</strong> メソッドは、現在アクティブな言語を取得します。一般的に、<a href="../classes/config.html#method_get">Config::get('language')</a> と同じ結果になります。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td><i>なし</i></td>
</tr>
<tr>
<th>返り値</th>
<td><kbd>String</kbd> 現在アクティブな言語。</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 現在アクティブな言語を返す。大抵は 'en' になるだろう
Lang::get_lang();
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_set_lang">set_lang($language, $reload = false)</h4>
<p>
<strong>set_lang</strong> メソッドは、新しいアクティブな言語を設定することができ、必要に応じて、
既に読み込まれたすべての言語ファイルをその言語のために再読み込みしようとします。
グローバルに新しい言語を設定するには <a href="../classes/config.html#method_set">Config::set('language')</a>
を呼び出します。 一般的にはユーザー構成可能な言語に切り替えるため、または設定するために利用されます。
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>はい</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$language</kbd></th>
<td><i>必須</i></td>
<td>言語コードを設定。</td>
</tr>
<tr>
<th><kbd>$reload</kbd></th>
<td><kbd>false</kbd></td>
<td>(オプション) <kbd>true</kbd> に設定すると、既に読み込まれたすべての言語ファイルは新しい言語セットのために再読み込みされます。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>戻り値</th>
<td>成功または失敗を示す <kbd>Bool</kbd>。</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// フランス語に切り替え、読み込まれているすべての言語ファイルを再読み込み
Lang::set_lang('fr', true);
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<h3 id="procedural_helpers">手続き型ヘルパー</h3>
<article>
<h4 id="function___">__($string, $params = array())</h4>
<p>The <strong>__</strong> 関数は、<a href="#method_get">Lang::get</a> の別名です。</p>
<table class="method">
<tbody>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$string</kbd></th>
<td><i>必須</i></td>
<td>求める行の識別子。</td>
</tr>
<tr>
<th><kbd>$parameters</kbd></th>
<td><pre class="php"><code>array()</code></pre></td>
<td>行に渡されるパラメータの配列。</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>string 。<a href="#method_get">Lang::get</a> からの結果</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// Hello world を出力
$this->output = __('hello', array('name' => 'world');
// プロパティを出力
$this->output = __('test.something');</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2016 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
[ <a href="https://github.com/fuel/docs/commits/1.8/develop/classes/lang.html">原文コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/commits/1.8/develop_japanese/classes/lang.html">翻訳コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/blob/1.8/develop_japanese/classes/lang.html">GitHubで修正</a> ]
</p>
</footer>
</div>
</body>
</html>