LinuxQuestions.org
Help answer threads with 0 replies.
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, 06:39 AM   #1
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 390

Rep: Reputation: 44
[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 06:43 AM. Reason: being more specific
 
Old 12-28-2017, 07:11 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,345

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
Luckily, you can use printf in your C++ program, too.
 
1 members found this post helpful.
Old 12-30-2017, 03:06 AM   #3
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 390

Original Poster
Rep: Reputation: 44
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, 04:13 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,345

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

Rep: Reputation: 203Reputation: 203Reputation: 203
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, 03:50 PM   #6
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 390

Original Poster
Rep: Reputation: 44
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, 04:06 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,345

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
(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, 11:44 AM   #8
camp0
Member
 
Registered: Dec 2016
Location: Dublin
Distribution: Fedora
Posts: 62

Rep: Reputation: 3
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:27 AM
Alsa-utils failing make stage: "cannot stat `t-ja.gmo'", I think I need xgettext timkarwoski Linux - General 2 10-06-2008 03:07 PM
Help with keywords please ! DarkLeon Linux - Newbie 7 11-06-2006 04:37 PM
xgettext: How to parse entire directory structure (dirs/subdirs) Muffe Linux - Software 1 04-28-2006 10:52 AM
xgettext error php language uknown psychomachine Linux - Software 0 12-09-2004 10:28 AM

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

All times are GMT -5. The time now is 11:28 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration