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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:57:41+00:00 2026-06-11T08:57:41+00:00

Part 1: Let’s say I do something which throws an exception like: function do_something($somepar)

  • 0

Part 1:
Let’s say I do something which throws an exception like:

function do_something($somepar)
{
    if (inexistent())
        return TRUE;
    else
        return FALSE;
}
if (do_something("SMART"))
    echo "Everything went right";
else
    echo "Something failed";

I got

Fatal error: Call to undefined function inexistent() in xyz.php on line 123

Is it possible to localize this message? I hoped

setlocale(LC_ALL,'it_IT');

could do that but it didn’t.

Part 2:
which is your recommendation to handle localized errors. Let’s say I want to create a general function to public it on the web and can be used by people who want it to use their own language.

function do_something($somepar)
{
    if (whatever())
    {
        return TRUE;
    }
    else
    {
        $error_message = localizeThis("How to translate this?");
        trigger_error($error_message, E_USER_ERROR);
        return FALSE;
    }
}
if (do_something("SMART"))
    echo "Everything went right";
else
    echo "Something failed";

Also how to set the correct output language?

  • 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-11T08:57:43+00:00Added an answer on June 11, 2026 at 8:57 am

    You need to differentiate between error handling, debugging/error messages and user-visible output. The standard error messages triggered by PHP are not localized by PHP. They are exclusively for the developer to see to help the developer debug the application, and the developer is expected to speak English. The rest of the PHP language is in English anyway.

    Messages triggered by trigger_error or by thrown exceptions are not meant for end-user consumption, as most end users won’t understand them anyway. You need to catch those errors internally and, if necessary, notify the user with any sort of localization system that something bad happened. The technical error messages can also contain sensitive information that should not be disclosed to the general public. So:

    set_error_handler(function ($errno, $errstr) {
        logErrorToFile($errstr);
    
        switch ($errno) {
            case E_ERROR :
                die(_('Sorry, something bad happened. Please read this comforting localized error instead'));
            case E_NOTICE :
                // decide what you want to do here
            ...
        }
    });
    

    and:

    try {
        somethingThatThrowsExceptions();
    } catch (Exception $e) {
        logErrorToFile($e->getMessage());
        die(_('Sorry, something bad happened. Please read this comforting localized error instead'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this function, which is part of some gui toolkit: typedef
Probably a conceptual mistake from my part but let's say I have a function
Let's say the original text is something like this: 12345 {unit} Then what's the
Let's say I have something like this: var location = '/users/45/messages/current/20/'; and I need
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let's say i have a griffon object that needs to be part of the
Let's presume that I have string like '=&?/;#+%' to be a part of my
Let's say we have two tables: 'Car' and 'Part', with a joining table in
Let's say we have this form, and the possible part for a user to
I have a web part which I'd like to add a custom icon to.

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.