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

  • Home
  • SEARCH
  • 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 510891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:09:36+00:00 2026-05-13T07:09:36+00:00

To clarify: I’m not using the gettext php module /extension, reason being because I

  • 0

To clarify:

  • I’m not using the gettext php module/extension, reason being because I have to deal with servers that don’t have gettext included, I’m aware of php-gettext but that just complicates things in that I have to use multiple libraries. Further more I don’t want to depend on the user having the necessary locales installed, and some servers I won’t have root access to do this. I also realize there are lots of issues with locales in general.
  • I have to support PHP4. Yes, it’s dead. Yes, I hate it. But I don’t have a choice.

I have a class that parses a “server-level” .mo gettext file based on the current language ( defaults to en ), iterates through every msgid and msgstr and populates an array with keys/values of the msgid and msgstr.

Afterwards I have a method which parses an “application-level” .mo file and merges the two together in the initial array being set, so the application-level translations take precedence over the server-side generic translations.

Since I’m using the merged array for my string translations, and I don’t want to read the .mo files on every single page read I’ll need some way to actually cache this and use the cached version if the page being read is the same language/locale as the cached version.

So If I went to my website and the default language was english it would read the english server/application mo files, merge them, make the array, cache it. If the next page the user clicked on is English, the cached version will be used. Otherwise, if it was say, Spanish, the merging takes place again and the spanish cached version is used.

So basically, how would I go about caching language/locale specific merged arrays? I’ve never actually implemented caching myself, but I would assume all I’d need to do is serialize my array, then write it into an application-level cache directory, and save the filename as something like ‘translation-{$locale}’ where $locale is something like ‘en’, then use logic to determine what the locale is in my app, based on that see if there’s a cached version available – if so, unserialize and just use that?

Is this usually how it’s done? I would very much appreciate code examples. The array I have has around 200-300 key/value pairs and is just a two level multidimensional array:

array(
  'en' => array(
  'Hello' => '',
),
  'es' => array(
  'Hello' => 'Hola',
)
);
  • 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-13T07:09:37+00:00Added an answer on May 13, 2026 at 7:09 am

    I’m not understanding why you are caching multiple language arrays? Do you have to provide support for > 1 language during a single request (its php) of your application?

    Anyways, what your saying is fine – serialize the array, stick it in the cache and retrieve it in the future. If you cache-miss, recompute the array.

    then write it into an
    application-level cache directory, and
    save the filename as something like
    ‘translation-{$locale}’ where $locale
    is something like ‘en’, then use logic
    to determine what the locale is in my
    app, based on that see if there’s a
    cached version available.

    File I/O is not as fast as memory access – if your going through the trouble of caching this, I would recommend looking into memcache.

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

Sidebar

Ask A Question

Stats

  • Questions 360k
  • Answers 360k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer <input type="submit" name="delete[1]" value="delete"> if (isset($_POST['delete'])) $id=key($_POST['delete']); May 14, 2026 at 2:39 pm
  • Editorial Team
    Editorial Team added an answer This transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:strip-space elements="*"/> <xsl:variable… May 14, 2026 at 2:39 pm
  • Editorial Team
    Editorial Team added an answer As others have mentioned, excessive DOM manipulation kills performance. Creating… May 14, 2026 at 2:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.