Complete C++ i18n gettext() “hello world” example

后端 未结 3 1879
一生所求
一生所求 2020-11-29 05:19

I am looking for a complete i18n gettext() hello world example. I have started a script based upon A tutorial on Native Language Support using GNU gettext by G.

3条回答
  •  渐次进展
    2020-11-29 06:10

    cat >hellogt.cxx <
    #include 
    #include 
    int main (){
        setlocale(LC_ALL, "");
        bindtextdomain("hellogt", ".");
        textdomain( "hellogt");
        std::cout << gettext("hello, world!") << std::endl;
    }
    EOF
    g++ -o hellogt hellogt.cxx
    xgettext --package-name hellogt --package-version 1.2 --default-domain hellogt --output hellogt.pot hellogt.cxx
    msginit --no-translator --locale es_MX --output-file hellogt_spanish.po --input hellogt.pot
    sed --in-place hellogt_spanish.po --expression='/"hello, world!"/,/#: / s/""/"hola mundo"/'
    mkdir --parents ./es_MX.utf8/LC_MESSAGES
    msgfmt --check --verbose --output-file ./es_MX.utf8/LC_MESSAGES/hellogt.mo hellogt_spanish.po
    LANGUAGE=es_MX.utf8 ./hellogt
    

    Here is a description of the files created by the above:

    hellogt.cxx         C++ source file
    hellogt             Executable image
    hellogt.pot         Extracted text from C++ source file (portable object template)
    hellogt_spanish.po  Modified text for Spanish with translations added (using sed)
    es_MX.utf8/
     LC_MESSAGES/
       hellogt.mo       Binary translated text for Spanish used at run-time
    

提交回复
热议问题