Skip to content

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

Open

Description

@itas109

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

Activity

  1. itas109 commented on Nov 28, 2020

    @itas109
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions