GithubHelp home page GithubHelp logo

g5t's Introduction

Internationalization and localization support.

This module is a <<< subset >>> and rewrite of the Python gettext module 
in the Go language.
The main difference between this module and the Python gettext module is that
this one only uses unicode. This approach reduces the code size 
significantly.


This module contains only ---- SIX ---- exported functions:

    Parse()                  // This is the ".mo" file parser and is overridable
    LoadLang()               // This function loads a translation into Catalog struct
    Catalog.String()         // This function returns a translated string
    Catalog.StringN()        // This function returns a translated string in plural form
    Catalog.StringPartial()  // This returns a plain string->string function for calling String
    Catalog.StringNPartial() // This returns a plain string->string function for calling StringN
    

Usage (short):

    1) To use this package in your application, write this line (it's 
       go-installable): 
    
        import "github.com/GerardNL/g5t"
        
        
    2) Run for each ".go" file:
    
        xgettext -o messages.po -C -kG -kGN:1,2 yourprogramfile.go
   
       
    3) If you want to place the translation files to a sub directory of 
       your application, make a directory called "translations" (for example)
       To locate your translations place this function in your app:
       
        lang := gt.LoadLang("your_app", "directory_to_transl_files", "language", Parser)


    4) In your application define functions (for singualar and plural):
       
        G := lang.StringPartial()
        GN := lang.StringNPartial()
       

    5) Code the rest of your program. When you want a string that needs to be 
       translated, write G("string to translate") etc.
    

    6) Translate "messages.po" with a text editor to a specific language and
       save the file to "yourdomain.po". Then run
       
       msgfmt yourdomain.po
       

       Msgfmt creates "yourdomain.mo". Copy this file to the language
       translation directory (in Debian this is "/usr/share/locale/")
 
    7) That's it.


TODO:
- Bugfixing. 
- Make it work on different operating systems.
- Listen to input from others. 


g5t's People

Contributors

jkozera avatar

Watchers

 avatar  avatar

Forkers

jkozera

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.