Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:22:31+00:00 2026-06-03T05:22:31+00:00

I’m trying to add Zend_Translate in a PHP project, using Zend components as standalone

  • 0

I’m trying to add Zend_Translate in a PHP project, using Zend components as standalone libraries.

I’m already using cache for several items using the following method:

$cache = Zend_Cache::factory( ...
if (!($obj = $cache->load('OBJ')))
{
  $obj = ...
  $cache->save($obj);
}

Now, following the documentation of Zend_Translate, I set the same $cache object to my Zend_Translate with a setCache before to actually create the object:

Zend_Translate::setCache($cache);
$translate = new Zend_Translate(
  array(
    'adapter' => 'gettext',
    'content' => 'languages',
     null,
     array('scan' => Zend_Translate::LOCALE_FILENAME)
  )
);

So, here I’m steering away from my usual method which instead would have been to put the whole Zend_Translate in the cache. The overall result, as of now is the following:

// 1.php

ob_start();
session_start();

$cache = Zend_Cache::factory( ...
if (!($obj = $cache->load('OBJ')))
{
  $obj = ...
  $cache->save($obj);
}

Zend_Translate::setCache($cache);
$translate = new Zend_Translate(
  array(
    'adapter' => 'gettext',
    'content' => 'languages',
    null,
    array('scan' => Zend_Translate::LOCALE_FILENAME)
  )
);

echo $translate->_("Hello, I'm the first script");

// end 1.php

and

// 2.php

ob_start();
session_start();

$cache = Zend_Cache::factory( ...
if (!($obj = $cache->load('OBJ')))
{
  $obj = ...
  $cache->save($obj);
}

Zend_Translate::setCache($cache);
$translate = new Zend_Translate(
  array(
    'adapter' => 'gettext',
    'content' => 'languages',
    null,
    array('scan' => Zend_Translate::LOCALE_FILENAME)
  )
);

echo $translate->_("Hello, I'm the second script");

// end 2.php

This approach doesn’t work as I see that the cache files are created every time that I load the page.

I am wondering:

  1. Am I correct to assume that I need to call Zend_Cache::factory in every page?
  2. How can I get my translate to work with cache in this standalone situation?
  3. Question about Zend_Translate: does addTranslation add anything to the picture or can I just load all my translations like I do?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:22:32+00:00Added an answer on June 3, 2026 at 5:22 am

    Question #1 Yes. You need to call Zend_Cache::factory on every page load. But if you already use Zend_Cache you can re-use it for your needs instead of creating a new instance for Zend_Translate.

    Question #2. There is no difference in usage of Zend Translate + Zend Cache as standalone components. Here is how I use them as standalone components in such small scripts:

    // Init application
    define('APP_PATH',      realpath(dirname(__FILE__)));
    define('APP_DATA',  APP_PATH . '/lang');
    define('APP_CACHE',     APP_PATH . '/tmp');
    
    require_once 'Zend/Translate.php';
    require_once 'Zend/Cache.php';
    
    // initialize cache
    $cache = Zend_Cache::factory(
          'Core'
            , 'File'
            , array(
                  'caching'     => true
                , 'lifetime'    => 900
                , 'automatic_serialization' => true
                , 'automatic_cleaning_factor'   => 20
                , 'cache_id_prefix'             => 'Translate'
                )
            , array(
                  'hashed_directory_level' => 0
                , 'cache_dir'   => APP_CACHE
            )
        );
    
    // Setup translation object
    Zend_Translate::setCache($cache);
    $translate = new Zend_Translate('tmx', APP_DATA . '/general.tmx');
    
    echo $translate->_("Hello, I'm the second script");
    

    OK, you are ready to use Zend_Cache. All caching will be covered by Zend_Translate instance itself internally.

    Question #3. addTranslation() just adds new translation sources, you can pass them to constructor instead (your case).

    Try to set “cache_id_prefix” for cache before passing it to Zend_Translate, that will help you to determine if problem occurs somewhere in your code “…” or new cache that is created on each page load is created by Zend Translate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.