Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multi-language 支持多种语言 #5

Open
itas109 opened this issue Nov 28, 2020 · 1 comment
Open

support multi-language 支持多种语言 #5

itas109 opened this issue Nov 28, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@itas109
Copy link
Owner

itas109 commented Nov 28, 2020

Describe the solution you'd like
support multi-language 支持多种语言

@itas109 itas109 added the enhancement New feature or request label Nov 28, 2020
@itas109
Copy link
Owner Author

itas109 commented Nov 28, 2020

gettext

  • code
// hello.cpp
#include <stdio.h>

#include <locale.h>
#include <libintl.h>
#define _(string) gettext (string)
#define LOCALEDIR "./locale/" 
#define PACKAGE "hello"

int main(int argc, char* argv[])

{

setlocale (LC_ALL, "");

bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);

printf(_("hello"));

return 0;
}
  • export po file
xgettext -a hello.cpp -o hello.po

"Content-Type: text/plain; charset=CHARSET/n" change CHARSET to UTF-8

  • make mo file
msgfmt hello.po -o hello.mo
  • mkdir
mkdir -p locale/zh_CN/LC_MESSAGES/
  • copy to locale/zh_CN/LC_MESSAGES/
cp hello.mo locale/zh_CN/LC_MESSAGES/
  • compile and run
g++ hello.cpp
./a.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant