LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2017, 05:39 AM   #1
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
[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...

Last edited by Andy Alt; 12-28-2017 at 05:43 AM. Reason: being more specific
 
Old 12-28-2017, 06:11 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Luckily, you can use printf in your C++ program, too.
 
1 members found this post helpful.
Old 12-30-2017, 02:06 AM   #3
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
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);
 
Old 12-30-2017, 03:13 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Code:
minimalFile.c_str()
Or something like this.
 
Old 12-30-2017, 03:54 AM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
1 members found this post helpful.
Old 01-04-2018, 02:50 PM   #6
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
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.
 
Old 01-05-2018, 03:06 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
(You should find out where this 'String' comes from (ie: which header file), and what methods does it have.)
 
1 members found this post helpful.
Old 01-08-2018, 10:44 AM   #8
camp0
Member
 
Registered: Dec 2016
Location: Dublin
Distribution: Fedora
Posts: 70

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


Reply

Tags
c++ programming, gettext, i18n, translations



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ? about "marking for removal" or "marking for complete removal" in synaptic pkg mgr Gregg Bell Linux - Newbie 5 03-06-2014 07:27 AM
Alsa-utils failing make stage: "cannot stat `t-ja.gmo'", I think I need xgettext timkarwoski Linux - General 2 10-06-2008 02:07 PM
Help with keywords please ! DarkLeon Linux - Newbie 7 11-06-2006 03:37 PM
xgettext: How to parse entire directory structure (dirs/subdirs) Muffe Linux - Software 1 04-28-2006 09:52 AM
xgettext error php language uknown psychomachine Linux - Software 0 12-09-2004 09:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration