Localization, Coding a Web Application




CS174

Chris Pollett

Nov. 13, 2013

Outline

Introduction

Text Direction

Text-direction: HTML and CSS

gettext

How do we create .mo files? .po files

From .po files to .mo files, more on msgid's.

Dynamic String Translation

Coding Practices

General Coding Comments

PHP Guidelines

  1. Avoid require or include commands within methods or randomly in your PHP documents. Put them at the top of the given file, try to use require_once, and try to avoid using variables to say what to require.
  2. Do not write much code out of a function or method. If you are using the MVC approach we've been discussing for the HW's then only index.php and config.php should have code that is not inside a function/method/class.
  3. In particular, use PHP's copy mode only within a function:
    class Layout
    {
        var $view;
    
        function __contruct($view)
        {
          $this->view = $view;
          //contructor code
        }
        function render($data)
        {
          ?>
          <html>
          <head><title><?php echo $data['title']; ?></title></head>
          <body>
          <?php $this->view->render($data); ?>
          </body>
          </html>     
          <?php
        }
    }
    
    This avoids headaches such as sending HTTP headers from a sessions after some HTML has been output.
  4. Make sure to de-reference associative arrays correctly:
    echo $my_assoc['my_field'];
    //not
    echo $my_assoc[my_field];
    
  5. Always use Unix paths not Windows paths -- on a Windows machine PHP auto-converts from the former to the latter. On a *nix machine though, PHP won't convert Windows paths to *nix.

Testing