diff --git a/en/appendices/3-0-migration-guide.rst b/en/appendices/3-0-migration-guide.rst index b682fb353d..837b1e7d61 100644 --- a/en/appendices/3-0-migration-guide.rst +++ b/en/appendices/3-0-migration-guide.rst @@ -1101,7 +1101,7 @@ the ``I18n`` class:: Configure::write('Config.language', 'fr_FR'); // Now - I18n::locale('en_US'); + I18n::setLocale('en_US'); - The methods below have been moved: diff --git a/en/appendices/3-5-migration-guide.rst b/en/appendices/3-5-migration-guide.rst index 6fe34367e7..80f5cd0a34 100644 --- a/en/appendices/3-5-migration-guide.rst +++ b/en/appendices/3-5-migration-guide.rst @@ -57,6 +57,9 @@ The following is a list of methods that are deprecated and replaced with * ``outputAs()`` (now ``getOutputFormat()`` / ``setOutputFormat()``) ``Cake\Http\ServerRequest`` * ``env()`` (now ``getEnv()`` / ``withEnv()``) +``Cake\I18n\I18n`` + * ``locale()`` + * ``translator()`` ``Cake\ORM\LocatorAwareTrait`` * ``tableLocator()`` ``Cake\ORM\Table`` @@ -152,3 +155,5 @@ New Features * ``Cake\Datasource\SchemaInterface`` was added. * ``Cake\Validation\ValidatorAwareInterface`` was added to define the methods implemented by ``Cake\Validation\ValidatorAwareTrait``. +* ``Cake\Http\Client::addCookie()`` was added to make it easy to add cookies to + a client instance. diff --git a/en/appendices/3-x-migration-guide.rst b/en/appendices/3-x-migration-guide.rst index 7a4626152e..7338a487a5 100644 --- a/en/appendices/3-x-migration-guide.rst +++ b/en/appendices/3-x-migration-guide.rst @@ -9,7 +9,7 @@ each version and the migration path between 2.x and 3.x. If you are currently using 1.x you should first upgrade to 2.x. See the 2.x documentation for the relevant upgrade guides. -3.4 Migration Guide +3.5 Migration Guide =================== .. toctree:: diff --git a/en/core-libraries/httpclient.rst b/en/core-libraries/httpclient.rst index 639056a5ad..fd97c19d4e 100644 --- a/en/core-libraries/httpclient.rst +++ b/en/core-libraries/httpclient.rst @@ -339,6 +339,20 @@ request's ``$options`` parameters:: 'cookies' => ['sessionid' => '123abc'] ]); + +You can add cookie objects to the client after creating it using the ``addCookie()`` +method:: + + use Cake\Http\Cookie\Cookie; + + $http = new Client([ + 'host' => 'cakephp.org' + ]); + $http->addCookie(new Cookie('session', 'abc123')); + +.. versionadded:: 3.5.0 + ``addCookie()`` was added in 3.5.0 + .. _httpclient-response-objects: Response Objects diff --git a/en/core-libraries/internationalization-and-localization.rst b/en/core-libraries/internationalization-and-localization.rst index 7fb185a2c1..33d4ac2eae 100644 --- a/en/core-libraries/internationalization-and-localization.rst +++ b/en/core-libraries/internationalization-and-localization.rst @@ -121,7 +121,8 @@ To change the language for translated strings you can call this method:: use Cake\I18n\I18n; - I18n::locale('de_DE'); + // Prior to 3.5 use I18n::locale() + I18n::setLocale('de_DE'); This will also change how numbers and dates are formatted when using one of the localization tools. @@ -384,7 +385,7 @@ for a single domain and locale:: use Aura\Intl\Package; - I18n::translator('animals', 'fr_FR', function () { + I18n::setTranslator('animals', function () { $package = new Package( 'default', // The formatting strategy (ICU) 'default' // The fallback domain @@ -397,7 +398,7 @@ for a single domain and locale:: ]); return $package; - }); + }, 'fr_FR'); The above code can be added to your **config/bootstrap.php** so that translations can be found before any translation function is used. The absolute @@ -405,7 +406,8 @@ minimum that is required for creating a translator is that the loader function should return a ``Aura\Intl\Package`` object. Once the code is in place you can use the translation functions as usual:: - I18n::locale('fr_FR'); + // Prior to 3.5 use I18n::locale() + I18n::setLocale('fr_FR'); __d('animals', 'Dog'); // Returns "Chien" As you see, ``Package`` objects take translation messages as an array. You can @@ -417,11 +419,11 @@ For example, you can still use **.po** files, but loaded from another location:: use Cake\I18n\MessagesFileLoader as Loader; // Load messages from src/Locale/folder/sub_folder/filename.po - - I18n::translator( + // Prior to 3.5 use translator() + I18n::setTranslator( 'animals', - 'fr_FR', - new Loader('filename', 'folder/sub_folder', 'po') + new Loader('filename', 'folder/sub_folder', 'po'), + 'fr_FR' ); Creating Message Parsers @@ -457,10 +459,11 @@ And finally, configure the translation loader for the domain and locale:: use Cake\I18n\MessagesFileLoader as Loader; - I18n::translator( + // Prior to 3.5 use translator() + I18n::setTranslator( 'animals', - 'fr_FR', - new Loader('animals', 'fr_FR', 'yaml') + new Loader('animals', 'fr_FR', 'yaml'), + 'fr_FR' ); .. _creating-generic-translators: @@ -468,7 +471,7 @@ And finally, configure the translation loader for the domain and locale:: Creating Generic Translators ---------------------------- -Configuring translators by calling ``I18n::translator()`` for each domain and +Configuring translators by calling ``I18n::setTranslator()`` for each domain and locale you need to support can be tedious, specially if you need to support more than a few different locales. To avoid this problem, CakePHP lets you define generic translator loaders for each domain. @@ -551,7 +554,7 @@ interpolating the variables:: It is possible to set the default formatter for all translators created by CakePHP before they are used for the first time. This does not include manually -created translators using the ``translator()`` and ``config()`` methods:: +created translators using the ``setTranslator()`` and ``config()`` methods:: I18n::defaultFormatter('sprintf'); @@ -569,7 +572,8 @@ the current locale setting and use the right classes:: use Cake\I18n\Time; use Cake\I18n\Number; - I18n::locale('fr-FR'); + // Prior to 3.5 use I18n::locale() + I18n::setLocale('fr-FR'); $date = new Time('2015-04-05 23:00:00'); diff --git a/en/orm/behaviors/translate.rst b/en/orm/behaviors/translate.rst index 68037ff20f..630a9ac35c 100644 --- a/en/orm/behaviors/translate.rst +++ b/en/orm/behaviors/translate.rst @@ -33,7 +33,7 @@ Now, select a language to be used for retrieving entities by changing the application language, which will affect all translations:: // In a controller. Change the locale, e.g. to Spanish - I18n::locale('es'); + I18n::setLocale('es'); $this->loadModel('Articles'); Then, get an existing entity:: @@ -172,7 +172,7 @@ translation for entities that are loaded:: use Cake\I18n\I18n; // Then you can change the language in your action: - I18n::locale('es'); + I18n::setLocale('es'); $this->loadModel('Articles'); // All entities in results will contain spanish translation @@ -181,7 +181,7 @@ translation for entities that are loaded:: This method works with any finder in your tables. For example, you can use TranslateBehavior with ``find('list')``:: - I18n::locale('es'); + I18n::setLocale('es'); $data = $this->Articles->find('list')->toArray(); // Data will contain @@ -289,12 +289,12 @@ simply uses the query builder function for the ``contain`` clause to use the Retrieving one language without using I18n::locale -------------------------------------------------- -calling ``I18n::locale('es');`` changes the default locale for all translated +calling ``I18n::setLocale('es');`` changes the default locale for all translated finds, there may be times you wish to retrieve translated content without modifying the application's state. For these scenarios use the behavior -``locale()`` method:: +``setLocale()`` method:: - I18n::locale('en'); // reset for illustration + I18n::setLocale('en'); // reset for illustration $this->loadModel('Articles'); $this->Articles->locale('es'); // specific locale @@ -306,7 +306,7 @@ Note that this only changes the locale of the Articles table, it would not affect the langauge of associated data. To affect associated data it's necessary to call locale on each table for example:: - I18n::locale('en'); // reset for illustration + I18n::setLocale('en'); // reset for illustration $this->loadModel('Articles'); $this->Articles->locale('es'); @@ -389,7 +389,7 @@ can be retrieved as usual:: The second way to use for saving entities in another language is to set the default language directly to the table:: - I18n::locale('es'); + I18n::setLocale('es'); $article->title = 'Mi Primer Artículo'; $this->Articles->save($article); diff --git a/fr/appendices/3-0-migration-guide.rst b/fr/appendices/3-0-migration-guide.rst index dfdb50b64f..34668b9530 100644 --- a/fr/appendices/3-0-migration-guide.rst +++ b/fr/appendices/3-0-migration-guide.rst @@ -1216,7 +1216,7 @@ pouvez utiliser la classe ``I18n``:: Configure::write('Config.language', 'fr_FR'); // Maintenant - I18n::locale('en_US'); + I18n::setLocale('en_US'); - Les méthodes ci-dessous ont été déplacées: diff --git a/fr/core-libraries/internationalization-and-localization.rst b/fr/core-libraries/internationalization-and-localization.rst index 11f8442351..df0ffcabe4 100644 --- a/fr/core-libraries/internationalization-and-localization.rst +++ b/fr/core-libraries/internationalization-and-localization.rst @@ -128,7 +128,7 @@ cette méthode:: use Cake\I18n\I18n; - I18n::locale('de_DE'); + I18n::setLocale('de_DE'); Cela changera également le formatage des nombres et des dates lorsque vous utilisez les outils de localisation. @@ -403,7 +403,7 @@ un seul domaine et une seule locale:: use Aura\Intl\Package; - I18n::translator('animals', 'fr_FR', function () { + I18n::setTranslator('animals', function () { $package = new Package( 'default', // The formatting strategy (ICU) 'default' // The fallback domain @@ -416,7 +416,7 @@ un seul domaine et une seule locale:: ]); return $package; - }); + }, 'fr_FR'); Le code ci-dessus peut être ajouté à votre **config/bootstrap.php** pour que les traductions soient ajoutées avant qu'une fonction de traduction ne soit @@ -425,7 +425,7 @@ fonction loader doit retourner un objet ``Aura\Intl\Package``. Une fois que le code est en place vous pouvez utiliser les fonctions de traduction comme d'habitude:: - I18n::locale('fr_FR'); + I18n::setLocale('fr_FR'); __d('animals', 'Dog'); // Retourne "Chien" Comme vous pouvez le voir, les objets ``Package`` prennent les messages de @@ -441,10 +441,10 @@ depuis un autre endroit:: // Charge les messages depuis src/Locale/folder/sub_folder/filename.po - I18n::translator( + I18n::setTranslator( 'animals', - 'fr_FR', - new Loader('filename', 'folder/sub_folder', 'po') + new Loader('filename', 'folder/sub_folder', 'po'), + 'fr_FR' ); Créer des Parsers de Messages @@ -480,10 +480,10 @@ Enfin, configurez le loader de traduction pour le domaine et la locale:: use Cake\I18n\MessagesFileLoader as Loader; - I18n::translator( + I18n::setTranslator( 'animals', - 'fr_FR', - new Loader('animals', 'fr_FR', 'yaml') + new Loader('animals', 'fr_FR', 'yaml'), + 'fr_FR' ); .. _creating-generic-translators: @@ -491,7 +491,7 @@ Enfin, configurez le loader de traduction pour le domaine et la locale:: Créer des Traducteurs Génériques -------------------------------- -Configurer des traducteurs en appelant ``I18n::translator()`` pour chaque +Configurer des traducteurs en appelant ``I18n::setTranslator()`` pour chaque domaine et locale que vous devez supporter peut être fastidieux, spécialement si vous devez supporter plus que quelques locales. Pour éviter ce problème, CakePHP vous permet de définir des loaders de traduction génériques pour chaque @@ -578,7 +578,7 @@ interpoler les variables:: Il est possible de définir le formateur par défaut pour tous les traducteurs créés par CakePHP avant qu'ils soient utilisés pour la première fois. Cela n'inclut pas les traducteurs créés manuellement en utilisant les méthodes -``translator()`` et ``config()``:: +``setTranslator()`` et ``config()``:: I18n::defaultFormatter('sprintf'); @@ -596,7 +596,7 @@ la locale et utiliser les bonnes classes:: use Cake\I18n\Time; use Cake\I18n\Number; - I18n::locale('fr-FR'); + I18n::setLocale('fr-FR'); $date = new Time('2015-04-05 23:00:00'); diff --git a/fr/orm/behaviors/translate.rst b/fr/orm/behaviors/translate.rst index 2f6e717f2e..5a38c1c851 100644 --- a/fr/orm/behaviors/translate.rst +++ b/fr/orm/behaviors/translate.rst @@ -32,7 +32,7 @@ behavior à l'objet Table que vous souhaitez rendre traduisible:: Maintenant, sélectionnez une langue à utiliser pour récupérer les entities:: // Dans un controller. Change la locale - I18n::locale('es'); + I18n::setLocale('es'); $this->loadModel('Articles'); Ensuite, récupérez une entity existante:: @@ -176,7 +176,7 @@ la traduction active pour les entities qui sont chargées:: use Cake\I18n\I18n; // Change la langue dans votre action - I18n::locale('es'); + I18n::setLocale('es'); $this->loadModel('Articles'); // Toutes les entities dans les résultats vont contenir la traduction espagnol @@ -186,7 +186,7 @@ Cette méthode fonctionne avec n'importe quel finder se trouvant dans vos tables. Par exemple, vous pouvez utiliser TranslateBehavior avec ``find('list')``:: - I18n::locale('es'); + I18n::setLocale('es'); $data = $this->Articles->find('list')->toArray(); // Data va contenir @@ -298,12 +298,12 @@ l'association. Récupérer une Langue sans Utiliser I18n::locale ----------------------------------------------- -Appeler ``I18n::locale('es');`` change la locale par défaut pour tous les finds +Appeler ``I18n::setLocale('es');`` change la locale par défaut pour tous les finds traduits, il peut y avoir des fois où vous souhaitez récupérer du contenu traduit sans modification de l'état de l'application. Pour ces scenarios, utilisez la méthode ``locale`` du behavior:: - I18n::locale('en'); // réinitialisation pour l'exemple + I18n::setLocale('en'); // réinitialisation pour l'exemple $this->loadModel('Articles'); $articles->locale('es'); // locale spécifique @@ -316,7 +316,7 @@ changera pas la langue des données associées. Pour utiliser cette technique pour changer les données associées, il est nécessaire d'appeler la locale pour chaque table par exemple:: - I18n::locale('en'); // reset for illustration + I18n::setLocale('en'); // reset for illustration $this->loadModel('Articles'); $this->Articles->locale('es'); @@ -401,7 +401,7 @@ sauvegardée et récupérée comme d'habitude:: La deuxième manière de l'utiliser pour sauvegarder les entities dans une autre langue est de définir par défaut la langue directement à la table:: - I18n::locale('es'); + I18n::setLocale('es'); $article->title = 'Mi Primer Artículo'; $this->Articles->save($article); diff --git a/ja/appendices/3-0-migration-guide.rst b/ja/appendices/3-0-migration-guide.rst index 7fac597f75..b2967b189a 100644 --- a/ja/appendices/3-0-migration-guide.rst +++ b/ja/appendices/3-0-migration-guide.rst @@ -1129,7 +1129,7 @@ I18n Configure::write('Config.language', 'fr_FR'); // Now - I18n::locale('en_US'); + I18n::setLocale('en_US'); - 以下のメソッドが移動されました: diff --git a/ja/core-libraries/internationalization-and-localization.rst b/ja/core-libraries/internationalization-and-localization.rst index ef0010107d..3afcdc8694 100644 --- a/ja/core-libraries/internationalization-and-localization.rst +++ b/ja/core-libraries/internationalization-and-localization.rst @@ -113,7 +113,7 @@ i18n シェルを利用できます。より知りたい場合は、 :doc:`次 use Cake\I18n\I18n; - I18n::locale('de_DE'); + I18n::setLocale('de_DE'); 地域化のツールを使うと、これは数字や日付がどのようにフォーマットされているかについても変更します。 @@ -355,7 +355,7 @@ Gettext の複数形選択を使用する use Aura\Intl\Package; - I18n::translator('animals', 'fr_FR', function () { + I18n::translator('animals', function () { $package = new Package( 'default', // フォーマット戦略 (ICU) 'default' // フォールバックドメイン @@ -368,13 +368,13 @@ Gettext の複数形選択を使用する ]); return $package; - }); + }, 'fr_FR'); 上記のコードは **config/bootstrap.php** に追加してください。そうすれば翻訳の機能が使われる前に 見つかります。翻訳機構を作成するのに最低限必要なのは、ローダー機能が ``Aura\Intl\Package`` オブジェクトを返すことです。一旦コードを置けば、翻訳機能は以下のように利用できるでしょう。 :: - I18n::locale('fr_FR'); + I18n::setLocale('fr_FR'); __d('animals', 'Dog'); // "Chien" を返す 見てお分かりの通り、 ``Package`` オブジェクトは配列として翻訳メッセージを受け取ります。 @@ -387,10 +387,10 @@ Gettext の複数形選択を使用する // src/Locale/folder/sub_folder/filename.po からメッセージをロード - I18n::translator( + I18n::setTranslator( 'animals', + new Loader('filename', 'folder/sub_folder', 'po'), 'fr_FR', - new Loader('filename', 'folder/sub_folder', 'po') ); のようになります。 @@ -426,10 +426,10 @@ CakePHP が利用しているものと同じやり方を使い続けることも use Cake\I18n\MessagesFileLoader as Loader; - I18n::translator( + I18n::setTranslator( 'animals', - 'fr_FR', - new Loader('animals', 'fr_FR', 'yaml') + new Loader('animals', 'fr_FR', 'yaml'), + 'fr_FR' ); .. _creating-generic-translators: @@ -532,7 +532,7 @@ CakePHP が利用しているものと同じやり方を使い続けることも use Cake\I18n\Time; use Cake\I18n\Number; - I18n::locale('fr-FR'); + I18n::setLocale('fr-FR'); $date = new Time('2015-04-05 23:00:00'); diff --git a/ja/orm/behaviors/translate.rst b/ja/orm/behaviors/translate.rst index bbf7d09192..d53ca4fd83 100644 --- a/ja/orm/behaviors/translate.rst +++ b/ja/orm/behaviors/translate.rst @@ -31,7 +31,7 @@ Table オブジェクトにビヘイビアを追加してください。 :: これはすべての翻訳に影響します。 :: // コントロールの中。例えば、スペイン語にロケールを変更。 - I18n::locale('es'); + I18n::setLocale('es'); $this->loadModel('Articles'); 次に、既存のエンティティを取得します。 :: @@ -163,7 +163,7 @@ Table への Translate ビヘイビアの追加 use Cake\I18n\I18n; // 次に、アクションの中で言語を変更することができます。 - I18n::locale('es'); + I18n::setLocale('es'); $this->loadModel('Articles'); // 結果のすべてのエンティティは、スペイン語の翻訳が含まれています。 @@ -172,7 +172,7 @@ Table への Translate ビヘイビアの追加 このメソッドは、Table 内の任意のファインダで動作します。 たとえば、 ``find('list')`` で TranslateBehavior を使用することができます。 :: - I18n::locale('es'); + I18n::setLocale('es'); $data = $this->Articles->find('list')->toArray(); // データが含まれます。 @@ -278,11 +278,11 @@ translate ビヘイビアは元のフィールド値を上書きします。 I18n::locale を使用せずに一つの言語の取得 ----------------------------------------- -``I18n::locale('es');`` を呼び出すと、翻訳されたすべての検索のデフォルトロケールが変更されますが、 +``I18n::setLocale('es');`` を呼び出すと、翻訳されたすべての検索のデフォルトロケールが変更されますが、 アプリケーションの状態を変更せずに翻訳されたコンテンツを取得したいことがあります。 これらの状況には、ビヘイビアの ``locale()`` メソッドを使用してください。 :: - I18n::locale('en'); // 説明のためにリセット + I18n::setLocale('en'); // 説明のためにリセット $this->loadModel('Articles'); $this->Articles->locale('es'); // 特定のロケール @@ -294,7 +294,7 @@ I18n::locale を使用せずに一つの言語の取得 関連するデータの言語に影響を与えないことに注意してください。 関連するデータに影響を与えるためには、各テーブルで locale を呼び出すことが必要です。例えば、 :: - I18n::locale('en'); // 説明のためにリセット + I18n::setLocale('en'); // 説明のためにリセット $this->loadModel('Articles'); $this->Articles->locale('es'); @@ -373,7 +373,7 @@ TranslateBehavior の背後にある哲学は、デフォルトの言語を表 別の言語でエンティティを保存するために使用する2つ目の方法は、 直接テーブルにデフォルトの言語を設定することです。 :: - I18n::locale('es'); + I18n::setLocale('es'); $article->title = 'Mi Primer Artículo'; $this->Articles->save($article);