Results 1 to 4 of 4

Thread: Problems with cookies and translations

  1. #1
    zaphod is offline Junior Member
    Join Date
    Feb 2009
    Posts
    6

    Default Problems with cookies and translations

    Greetings.

    I'm very new with ZF so please excuse any ignorance on my part.

    I'm developing a website that must have multiple languages for the user
    to choose (namely: en_US and pt_BR). The idea is having icons present
    in all pages that the user can click, resulting in:

    1) Change the default locale for him.
    2) Rendering the page where he's in again, so he sees that page in the
    desired language "automatically".
    3) Setting a cookie so the next time he visits the site the correct
    locale is already set

    Although this might sound pretty straightforward I must confess I'm
    completely confused.

    The translation works fine in the page's initial load (it loads in
    English because my browser's locale is en_US), but it doesn't work after
    the redirect. After the user clicks the icon (in this example, the icon
    for pt_BR) the page loads without rendering the view and instead of the
    translated strings I get only the indexes for the language array
    ('title', 'phone', 'explain', etc...).

    I've also noticed that the cookie is not saved.

    Here's how I'm trying to achieve this (this will be simple to show,
    since the site has just a front page for now):

    app/controllers/IndexController.php - Paste2: Next Generation Pastebin - Viewing Paste 146862
    app/views/scripts/index/index.phtml - Paste2: Next Generation Pastebin - Viewing Paste 146866

    (BTW, the registry is being set in my bootstrap).

    Any ideas on what I'm doing wrong?

    TIA,

    Galvao

  2. #2
    Tekerson is offline Senior Member
    Join Date
    Jul 2008
    Posts
    288

    Default

    Nothing jumps out as wrong with your code. At least with regard to the cookies, I'm not really up on the translation stuff. But if the cookie isn't being set, then nothing else will work.

    Are you perchance running on localhost? I believe some (all?) browsers won't accept cookies from localhost, there is a comment to that effect on the setcookie() manual page.
    Brenton Alker
    PHP Developer - Brisbane, Australia

    blog.tekerson.com | twitter.com/tekerson | brenton.mp

  3. #3
    zaphod is offline Junior Member
    Join Date
    Feb 2009
    Posts
    6

    Default

    Hi. Thanks for your reply.

    I didn't knew about the localhost restriction (yes, I'm testing at localhost). Anyway, I've itried uploading the site to it's production envrionment. The translation still doesn't work, although the problem about rendering the view doesn't happen anymore...

    BTW, the cokkie still doesn't get saved.

    It's halfway to the solution, but something is still missing.

    Any ideas?

  4. #4
    zaphod is offline Junior Member
    Join Date
    Feb 2009
    Posts
    6

    Default Problem solved

    I've managed to solve the problem. Apparently the confusion about concepts was the main responsible for everything going wrong (as I've already suspected, actually).

    This is the final result:

    I've moved the code that initially checks for the cookie and set the locale to my bootstrap file, left the indexAction on my IndexController empty and the changelocaleAction was left unmodified.

    Worked like a charm. Oh, there's no such thing as the localhost cookie restriction, it works both locally and in the production environment.

    Anyway, thank you very much for your reply.

    Cheers,

    Galvao

Similar Threads

  1. Fake missing translations get logged for Zend_Validators
    By midix in forum Internationalization (i18n) & Localization (l10n)
    Replies: 2
    Last Post: 07-29-2010, 08:51 AM
  2. Use translations in view
    By Bjorn121 in forum Internationalization (i18n) & Localization (l10n)
    Replies: 6
    Last Post: 07-13-2009, 08:10 AM
  3. Zend Translate - log missing translations
    By Nastareger in forum Internationalization (i18n) & Localization (l10n)
    Replies: 7
    Last Post: 03-06-2009, 09:37 PM
  4. Cookies Usage
    By anees_muhd in forum Web & Web Services
    Replies: 3
    Last Post: 01-13-2009, 07:03 AM
  5. access control & translations used in a modular directory structure
    By ignace in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 01-30-2008, 05:29 PM

Posting Permissions

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