SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Molde, Norway
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Translation using Zend_Form and Zend_Config_Ini

    I am experimenting with Zend_Form and populating the form with data stored in an ini file:

    Code:
    [temp]
    method = "post"
    
    ; username element
    elements.username.type = "text"
    elements.username.options.validators.strlen.validator = "StringLength"
    elements.username.options.validators.strlen.options.min = "1"
    elements.username.options.validators.strlen.options.max = "10"
    elements.username.options.validators.strlen.options.messages.StringLengthTooShort = "A valid username must be entered"
    elements.username.options.validators.strlen.options.messages.StringLengthTooLong = "A valid username must be entered"
    elements.username.options.validators.notempty.validator = "NotEmpty"
    elements.username.options.validators.notempty.options.messages.isEmpty = "A valid username must be entered"
    elements.username.options.required = true
    elements.username.options.label = "Username"
    
    ; password element
    elements.password.type = "password"
    elements.password.options.required = true
    elements.password.options.validators.ne.validator = "NotEmpty"
    elements.password.options.validators.ne.options.messages.isEmpty = "A password must be entered"
    elements.password.options.label = "Password"
    
    ; submit element
    elements.submit.type = "submit"
    The form is shown by this code:
    $config = new Zend_Config_Ini('form.ini', 'temp');
    $form = new Zend_Form($config);

    What is the best practice to have the form labels and error messages from the ini file translated into other languages without having different ini files for every language?

  2. #2
    SitePoint Guru
    Join Date
    May 2005
    Location
    Finland
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, just register a translator (either manually or with Zend_Registry) and all labels and error messages will be translated for you.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Molde, Norway
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found out, I just add a translator object to the form:
    Code:
    $translator = new Zend_Translate('csv', 'norsk.scv', 'nb_NO');
    $form->setTranslator($translator);
    I can have the language data in a lot of different formats, for other interested people, look here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •