public
Description: CakePHP plugin for localizing JavaScript
Homepage:
Clone URL: git://github.com/mcurry/js.git
unknown (author)
Thu May 28 21:58:14 -0700 2009
commit  53574e907b1fb3f3a8858a954794ce2358ff0154
tree    5cf8206592aab74e22184af00e903db12e464a0a
parent  da8607364c22b47523ee65990847482c3a7aebd7
js /
README
/*
 * JS localize CakePHP Plugin
 * Copyright (c) 2009 Matt Curry
 * www.PseudoCoder.com
 * http://github.com/mcurry/js
 *
 * @author      Matt Curry <matt@pseudocoder.com>
 * @license     MIT
 *
 */

/* About */
This plugin allows you to create javascript files that include Cake's __() function, which translates strings.  The 
plugin processes the files and caches them as static javascript files.

/* Instructions */
   1. Download the plugin to /app/plugins/js.
   2. There are two ways to use this plugin:
    a. If you want to keep a separate JavaScript file with all language strings:
      - Create the file as /app/webroot/js/source/lang.js.  It will likely look something like this (but doesn't have 
      to):
        var Lang =
          {
            Message1 : "<?php __('Message 1') ?>",
            Message2 : "<?php __('Message 2') ?>",
          };
      - Then include your js file as lang/en.js.  You can substitute "en" with any of the language codes supported.
        $javascript->link('lang/en.js');
    
    b. If you want to include your localized strings right in the javascript code:
      - Put the files in /app/webroot/js/source/.  
        For example if you had a site.js that had a bunch of JavaScript code mized with calles to __() the file would 
        be:
        /app/webroot/js/source/site.js.
      - Then include your js file as lang/en/site.js.  You can substitute "en" with any of the language codes supported.

              $javascript->link('lang/en/site.js');
   3. Cache
    - If debug is enabled no files are cached.
    - If debug is off files will be cached to the request location.
    - Delete the entire /app/webroot/js/lang dir to remove the cache - it's a good idea to do this as part of your 
    build.
    
/* How This Works */
When the first request is made no file actually exists.  This causes Cake to catch the request and the request is 
handled by the plugin.  The plugin looks for the base file in /source (this is configurable).  The source file is 
processed by PHP so that all calls to __() are replaced with the correct strings.  The resulting file is then saved to 
the file system so that the next request reads it directly.