From 39320dc84749aa8ed39c79413af7d5af5e2117b6 Mon Sep 17 00:00:00 2001 From: j20 Date: Sat, 3 Nov 2012 14:54:38 -0500 Subject: [PATCH 1/5] Update laravel/documentation/localization.md Updated to use the two-letter, ISO standard language code for Spanish--'es' instead of 'sp'. --- laravel/documentation/localization.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/laravel/documentation/localization.md b/laravel/documentation/localization.md index cbf4a463..6876f4cb 100644 --- a/laravel/documentation/localization.md +++ b/laravel/documentation/localization.md @@ -11,7 +11,7 @@ ## The Basics Localization is the process of translating your application into different languages. The **Lang** class provides a simple mechanism to help you organize and retrieve the text of your multilingual application. -All of the language files for your application live under the **application/language** directory. Within the **application/language** directory, you should create a directory for each language your application speaks. So, for example, if your application speaks English and Spanish, you might create **en** and **sp** directories under the **language** directory. +All of the language files for your application live under the **application/language** directory. Within the **application/language** directory, you should create a directory for each language your application speaks. So, for example, if your application speaks English and Spanish, you might create **en** and **es** directories under the **language** directory. Each language directory may contain many different language files. Each language file is simply an array of string values in that language. In fact, language files are structured identically to configuration files. For example, within the **application/language/en** directory, you could create a **marketing.php** file that looks like this: @@ -23,7 +23,7 @@ #### Creating a language file: ); -Next, you should create a corresponding **marketing.php** file within the **application/language/sp** directory. The file would look something like this: +Next, you should create a corresponding **marketing.php** file within the **application/language/es** directory. The file would look something like this: return array( @@ -50,7 +50,7 @@ #### Retrieving a language line using the "__" helper: #### Getting a language line in a given language: - echo Lang::line('marketing.welcome')->get('sp'); + echo Lang::line('marketing.welcome')->get('es'); ## Place Holders & Replacements From 1beea5d594b89986b5f92ec2fd33bbeb722a21f9 Mon Sep 17 00:00:00 2001 From: Jesse O'Brien Date: Thu, 6 Dec 2012 11:16:06 -0500 Subject: [PATCH 2/5] Add JSONP as a default response. --- laravel/response.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/laravel/response.php b/laravel/response.php index ccd53e1f..51ee33d6 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -98,6 +98,26 @@ public static function json($data, $status = 200, $headers = array()) return new static(json_encode($data), $status, $headers); } + /** + * Create a new JSONP response. + * + * + * // Create a response instance with JSONP + * return Response::jsonp($data, 200, array('header' => 'value')); + * + * + * @param mixed $data + * @param int $status + * @param array $headers + * @return Response + */ + public static function jsonp($data, $status = 200, $headers = array()) + { + $headers['Content-Type'] = 'application/javascript; charset=utf-8'; + + return new static(json_encode($data), $status, $headers); + } + /** * Create a new response of JSON'd Eloquent models. * @@ -344,4 +364,4 @@ public function __toString() return $this->render(); } -} \ No newline at end of file +} From cf6e2a768b7bb93e884873429f5f50489a507002 Mon Sep 17 00:00:00 2001 From: Jesse O'Brien Date: Thu, 6 Dec 2012 11:22:48 -0500 Subject: [PATCH 3/5] Add documentation for JSONP Response --- laravel/documentation/views/home.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/laravel/documentation/views/home.md b/laravel/documentation/views/home.md index 27383562..53a0c4f3 100644 --- a/laravel/documentation/views/home.md +++ b/laravel/documentation/views/home.md @@ -62,6 +62,10 @@ #### Returning a JSON response: return Response::json(array('name' => 'Batman')); +#### Returning a JSONP response: + + return Response::jsonp(array('name' => 'Batman')); + #### Returning Eloquent models as JSON: return Response::eloquent(User::find(1)); From 404b59730a229c246e036a53cd35fdbee20a3a20 Mon Sep 17 00:00:00 2001 From: Jesse O'Brien Date: Thu, 6 Dec 2012 11:57:26 -0500 Subject: [PATCH 4/5] Added callback wrapper for JSONP auto wrapping. --- laravel/documentation/views/home.md | 2 +- laravel/response.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/laravel/documentation/views/home.md b/laravel/documentation/views/home.md index 53a0c4f3..3daf57a9 100644 --- a/laravel/documentation/views/home.md +++ b/laravel/documentation/views/home.md @@ -64,7 +64,7 @@ #### Returning a JSON response: #### Returning a JSONP response: - return Response::jsonp(array('name' => 'Batman')); + return Response::jsonp('myCallback', array('name' => 'Batman')); #### Returning Eloquent models as JSON: diff --git a/laravel/response.php b/laravel/response.php index 51ee33d6..5e69308f 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -103,7 +103,7 @@ public static function json($data, $status = 200, $headers = array()) * * * // Create a response instance with JSONP - * return Response::jsonp($data, 200, array('header' => 'value')); + * return Response::jsonp('myFunctionCall', $data, 200, array('header' => 'value')); * * * @param mixed $data @@ -111,11 +111,11 @@ public static function json($data, $status = 200, $headers = array()) * @param array $headers * @return Response */ - public static function jsonp($data, $status = 200, $headers = array()) + public static function jsonp($callback, $data, $status = 200, $headers = array()) { $headers['Content-Type'] = 'application/javascript; charset=utf-8'; - return new static(json_encode($data), $status, $headers); + return new static($callback.'('.json_encode($data).')', $status, $headers); } /** From 4f5cc0cd97676e5064b176cee7b0432df31ba975 Mon Sep 17 00:00:00 2001 From: Jesse O'Brien Date: Thu, 6 Dec 2012 12:04:06 -0500 Subject: [PATCH 5/5] Add semi-colon onto padding to be safe. --- laravel/response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laravel/response.php b/laravel/response.php index 5e69308f..7979ef46 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -115,7 +115,7 @@ public static function jsonp($callback, $data, $status = 200, $headers = array() { $headers['Content-Type'] = 'application/javascript; charset=utf-8'; - return new static($callback.'('.json_encode($data).')', $status, $headers); + return new static($callback.'('.json_encode($data).');', $status, $headers); } /**