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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:16:16+00:00 2026-05-12T12:16:16+00:00

I want to localize a program I already written.. It’s fairly big (almost 50k

  • 0

I want to localize a program I already written.. It’s fairly big (almost 50k lines) and ideally I want a system that allows me (the programmer) to do the least amount of work possible, and without major changes to the program – if possible none at all.

I looked at gettext() and liked it a lot, but it’s unclear to me how it would translate strings such as these:

const char *Colors[] = {
 { "Red" },
 { "Blue" },
 { "Yellow" },
 ....
};

which are VERY common in my program.. Here replacing “Red” with gettext(“Red”) would obviously not work.

So I thought I would do something like, OutputFunction(gettext(Colors[Id])), but then how can I get a list of strings to localize? I doubt any program is smart enough to be able to get “Red”, “Blue”, “Yellow” from that in a to-localize list statically.

Since it’s basically a server there is no need for the ability to change the language without recompiling (I can compile it for every supported language without any major problem or annoyance), I thought about C++0x’s constexpr, which would be perfect! It would work in arrays/etc and I would easily get a list of strings to localize at compile time.. Too bad that no compiler implemented it yet.

Changing all the strings to an ID is not an option since it would require a massive amount of work on my part and especially creating a new id for every new string would be annoying as hell. The same applies to converting all the arrays like the one above to something else.

So, any ideas? :/

  • 1 1 Answer
  • 2 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-12T12:16:17+00:00Added an answer on May 12, 2026 at 12:16 pm

    After a lot of playing around with gettext() and xgettext I think I found a way myself (sorry onebyone but I didn’t like your approach.. There must be hundreds of arrays like that and I would have to import all of them in main(), that’s a lot of extern and a lot of extra work :/).

    Anyways, this is how I think it can theoretically be done (I haven’t tried yet to actually translate but I don’t see why it wouldn’t work)

    Two #define’s:

    #define _ gettext
    #define __(x) x
    

    Then you use _ to actually translate and __ to simply mark strings as “to be translated”:

    const char *Colors[] = {
     { __("Red") },
     { __("Blue") },
     { __("Yellow") },
     ....
    };
    
    void PrintColor(int id) {
        cout << _("The color is: ") << _(Colors[id]);
    }
    

    Then you run:

    xgettext -k_ -k__ *.cpp
    

    And you get the following .po file:

    #: test.cpp:2
    msgid "Red"
    msgstr ""
    
    #: test.cpp:3
    msgid "Blue"
    msgstr ""
    
    #: test.cpp:4
    msgid "Yellow"
    msgstr ""
    
    #: test.cpp:9
    msgid "The color is: "
    msgstr ""
    

    So, you use __ (or any other name, doesn’t really matter) as a “dummy function” to just let xgettext know that the string needs to be translated, and _ to actually call gettext().

    If you call _ with a string then the string will be marked to-be-translated as well, if you call it with a variable, array, whatever then it appears to be simply ignored by xgettext.

    Great! Now all I have to do is go through 5 trillion files and add underscores around, as if I was a monkey :/

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

Sidebar

Related Questions

I have a program in C# that I want to get a news feed
I want to localize a form in my app so that all the labels
I'm developping a little application in WPF and I want to localize my resources.
I'm using the Spark view engine, and want to localize the website. The methods
I want to create a Producer that makes it possible to inject a java.util.ResourceBundle
I want to localize a presentation and I'm having a brain freeze on this
I've got some form for user registration and want to localize it via locales
Trying to localize text in ASP.NET labels... want to add a ':' after the
I want to localize my GWT project to more laguages so I added to
I want to localize Web Service in ASP.NET application. I can write the following

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.