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 6743837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:00:37+00:00 2026-05-26T12:00:37+00:00

For multi-language usage of CMS, they translate terms by a function similar to function

  • 0

For multi-language usage of CMS, they translate terms by a function similar to

function __($word) {
include 'fr.php';
if(!empty($lang[$word])) {$translated=$lang[$word];
} else {
$translated = $word;
} 
return $translated;
}
  1. Since we need to use this function several times in a php page, as all words and phrases will be echoed by __(‘ ‘); does the function need to include the language time every time, or it will be cached for the function after first load?

  2. Since the language file contains a complete list of words and phrased used throughout the website (thousands of key/value), pho needs to load this long array into memory every time a page is visited. Is it really the best approach to add multi-language feature to a CMS?

  • 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-05-26T12:00:38+00:00Added an answer on May 26, 2026 at 12:00 pm

    If you can’t use gettext() for some reason, you’d be better off, with something like this, to put it into an object with the included language strings as a static array, something like:

    class Message {
    
      private static $_messages = array();
    
      public static function setMessageLibrary($sMessageLibrary) {
        require_once $sMessageLibrary;
        self::$_messages = $aMsgs;
      }
    
      public static function getMessage($sMessageId) {
        return isset(self::$_messages[$sMessageId]) ? self::$_messages[$sMessageId] : "";
      }
    }
    

    Your message library file (included with the setMessageLibrary() static function), of which you’ll have one per language, will need a variable in it called $aMsgs which might look something like:

    // Messages for fr-FR
    $aMsgs = array(
      'hello_everybody' => "Bonjour tout le monde"
    
      ...
    
      and so on
    );
    

    Since it’s all static but within the object you can effectively cache that included language file by setting it at the start of your script.

    <?php
    Message::setMessageLibrary('/lang/fr-FR/messages.inc.php');
    echo Message::getMessage('hello_world');
    echo Message::getMessage('another_message');
    echo Message::getMessage('yet_another_message');
    ?>
    

    All three messages will then reference the single language array stored in Message::$_messages

    There’s no sanitisation, nor sanity checks in there, but that’s the basic principle anyway … if you can’t use gettext() 😉

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

Sidebar

Related Questions

In a multi-language web site, can I rely on the javascript confirm to translate
I'm building multi-language support for PHP page. Let's say I have a page url:
I have multi-language website in Drupal, but not all content is translated. I want
I'm working on multi-language website. For example, DB table pages for 1 lang looks
I have a PHP application and now I need to implement multi language support.
I have added multi-language using the short article below. When you add for example
I am building a multi-language API to query key value stores and I am
We're building a multi-language Drupal stack and one of the concerns we have is
I'm trying to add multi-language support to an OpenSocial application. I see that I
I want to make a multi-language site, such that all or almost all pages

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.