Documentation


SEARCH

TABLE OF CONTENT

    1. Getting started 2. Basic concepts 3. Request dispatching 4. Context container 5. Dual MVC 6. Component model: 7. Security 8. Configuration 9. Session handling 10. I18n 11. Cache 12. Logging 13. Error handling 14. Advanced Topics 15. API reference

      Tutorials: Frequently Asqued Questions

      See also:


      Exceptions and I18n

      Internationalizating Exceptions

      Table of Contents

      The error table and I18n

      One of the most valuable benefits of using an error table (app/config/errors.xml) is how easy is to maintain I18n strings bound to each exception.
      i.e.

      1. <?xml version "1.0" standalone="yes"?>
      2.  
      3. <configuration>
      4.  
      5.   <errors>
      6.   
      7.     <!-- Common errors -->
      8.     <error-group id="ERR_MODEL_ERRORS" exception-class="MyModelExceptionClass">
      9.       <error code="75001" id="ERR_INVOICE_CANNOT_BE_EMPTY" />
      10.       <error code="75002" id="ERR_INVOICE_WRONG_DATE" />
      11.       <error code="75003" id="ERR_INVOICE_NOT_FOUND" />
      12.       <error code="75004" id="ERR_CUSTOMER_NOT_FOUND" />
      13.       ...
      14.     </error-group>
      15.  
      16.     <error-group id="ERR_SECURITY_ERRORS" exception-class="MySecurityExceptionClass">
      17.       <error code="76002" id="ERR_WRONG_USERNAME_OR_PASSWORD" />
      18.       <error code="76008" id="ERR_ACCESS_LOGIN_REQUIRED" />
      19.       ...

      Now we can declare a I18n file for each language, setting an entry with the same name as the id assigned to each error within the error table.

      If we have an error with id ERR_WRONG_USERNAME_OR_PASSWORD, this is the entry that we must set in our I18n files.

      i.e.

      1. ;------------------------------------------------
      2. ;Error strings/////////////////////////////////
      3. ;------------------------------------------------
      4.  
      5. ERR_INVOICE_CANNOT_BE_EMPTY "Invoice can not be empty"
      6. ERR_INVOICE_WRONG_DATE      "Wrong date assigned to invoice"
      7. ERR_INVOICE_NOT_FOUND       "Invoice not found: {0}"
      8. ERR_CUSTOMER_NOT_FOUND      "Customer not found: {0}"
      9.  
      10. ...
      11.  
      12. ERR_WRONG_USERNAME_OR_PASSWORD "Either the email does not correspond to 
      13.                                   any registered user or the password is wrong"
      14. ERR_ACCESS_LOGIN_REQUIRED "You must be logged-in to access to this page"
      15.  
      16. ...

      It's important to note that we must configure I18n strings as per session in case the exceptions may happens in whatever page, otherwise as per request.

      However, recommend to configure them as per session since eases refactorizations

      i.e.

      1. <?xml version "1.0" standalone="yes"?>
      2. <configuration>
      3.   
      4.   <resource-providers>
      5.  
      6.     ...
      7.     
      8.     <resource-provider class="__IniFileResourceProvider" description="Error strings" persistence-level="session">
      9.       <resources_type class="__ErrorMessageResource"/>                
      10.       <properties>
      11.         <property name="languageDir" value="libs/language"/>
      12.         <property name="filename" value="errors.ini"/>
      13.       </properties>
      14.     </resource-provider>    
      15.  
      16.     ...
      17.     
      18.   </resource-providers>  
      19.   
      20. </configuration>