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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:30:22+00:00 2026-05-27T15:30:22+00:00

I have a PHP back-end to which several types of devices communicate via a

  • 0

I have a PHP back-end to which several types of devices communicate via a public API. Requests normally contain a required language for the response (e.g. ‘en’ or ‘fr’ or ‘ru’, etc.) – but not the full locale. This has worked fine for everything I needed over the last couple of years. However now I need to include date information in the response – and need a locale to format dates.

How can I get a locale from the language? I do understand that a language is not enough to uniquely identify a locale, but I need at least something. If I can get at least one locale, e.g. en_GB for ‘en’ or ‘ru_RU’ for ‘ru’, etc. – that would be sufficient.

  • 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-27T15:30:23+00:00Added an answer on May 27, 2026 at 3:30 pm

    Having thought more about the problem and the particular setup I have, I came up with this solution, which seems to work. Note that I don’t have control over what languages I need to support: there are translation files dropped into a predefined place and system locales installed by someone else. During runtime, I need to support a particular language if corresponding translation file exists and and system locale is installed. This got me to this solution:

    function getLocale($lang)
    {
        $locs = array();
        exec('locale -a', $locs);
    
        $locale = 'en_GB';
        foreach($locs as $l)
        {
            $regex = "/$lang\_[A-Z]{2}$/";
            if(preg_match($regex, $l) && file_exists(TRANSROOT . "/$lang.php"))
            {
                $locale = $l;
                break;
            }
        }
    
        return $locale;
    }
    

    I’m defaulting to en_GB if I cannot resolve a locale, because I know for certain that en_GB is installed (we’re located in the UK as are our servers).

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

Sidebar

Related Questions

I have a PHP search suggestion script which uses MySQL as its back-end. I
I have this query which I want to run in my PHP application back
I am doing some processing in a back end page (thread.php) which basically returns
I recently inherited a website and they have a simple back-end area which was
I have a real basic form (code below) with a bunch of back-panel PhP.
I have inherited some legacy PHP code what was written back when it was
I have php file with form which the user need to enter three parameters
I have PHP function which checks to see if variables are set and then
I have a large(ish) COM object that works as the back end of my
I want to build a back end of a general web form which contains

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.