LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [C++] marking keywords for use with xgettext (https://www.linuxquestions.org/questions/programming-9/%5Bc-%5D-marking-keywords-for-use-with-xgettext-4175620430/)

Andy Alt 12-28-2017 05:39 AM

[C++] marking keywords for use with xgettext
 
So.. in C, marking strings with keywords for use with xgettext is pretty straightforward, putting the marks around the quotes, and I've done it with a C program.

printf (_("Not concerned with %s any %d vars and only using %s one mark\n"), var1, var2, var3);

I had trouble finding examples of how to mark keywords around cout statements.

For example:

cout "some" << vars1 << "between" << "vars2" << "and more" << vars3 << endl;


I haven't tried to see what would happen yet if I just put a mark at the beginning and the end of that line, but I have a feeling that wouldn't get me the desired result. I wanted to hear some opinions on it.

Does anyone recommend using a library other than gettext for adding support for translations to C++ programs?

Is there any good reason I shouldn't consider using something like tinyformat for the C++ program I'm working in?

If anyone knows of a C++ program that already uses gettext, please tell me about it and I can just look to see how it's done. Thanks...

NevemTeve 12-28-2017 06:11 AM

Luckily, you can use printf in your C++ program, too.

Andy Alt 12-30-2017 02:06 AM

That works in most cases, but I get this warning when using a String type

Code:

hldig.cc:418:74: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘String*’ [-Wformat=]
      printf (_("Could not open argument '%s' of flag -m\n"), minimalFile);


NevemTeve 12-30-2017 03:13 AM

Code:

minimalFile.c_str()
Or something like this.

Mara 12-30-2017 03:54 AM

If you want to have a program that is easy to translate to different languages, I very much recommend you to have one single string per sentence. The printf() format is very good for it. The reason is that in another language the order of the parameters may be different and the translators will have much harder work if they can't arrange them as they need.

Andy Alt 01-04-2018 02:50 PM

I tried `minimalFile.c_str()` but got the error

Quote:

‘class String’ has no member named ‘c_str’
But using &minimalFile[0] seems to work ok.

I did a search on that error and found mostly Arduino-related posts about it. I'm not experienced with C++, my background is mostly in C. The C++ code base I'm working on is pretty old, updated hardly at all since 2004; it's a fork of ht://Dig.


Quote:

Originally Posted by Mara
If you want to have a program that is easy to translate to different languages, I very much recommend you to have one single string per sentence. The printf() format is very good for it. The reason is that in another language the order of the parameters may be different and the translators will have much harder work if they can't arrange them as they need.

That's my goal. I was basically looking for opinions on the best way to achieve that using C++. Seems like printf() is the agreed-upon choice. Thanks everyone.

NevemTeve 01-05-2018 03:06 AM

(You should find out where this 'String' comes from (ie: which header file), and what methods does it have.)

camp0 01-08-2018 10:44 AM

I like to use boost::format on c++ formating strings http://www.boost.org/doc/libs/1_66_0...oc/format.html


All times are GMT -5. The time now is 06:38 AM.