Skip to content

Creating go-i18n JSON file by parsing your go source code

License

Notifications You must be signed in to change notification settings

tkyshm/goi18n-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

goi18n-parser

Note: Please check go-i18n before to use this package.

Usage

very simple!

package main

import (
    "fmt"
    "goi18np"
    "encoding/json"
)

func main() {
    a := goi18np.Analyzer{
        Debug: true,
    }
    result := a.AnalyzeFromFile("path/to/code.go")

    out, err := json.Marshal(result)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(out))

    a.SaveJSON("path/to/translate.json")
}

Analyzer

Analyzer has fields:

name type description
FuncName string Analyze target function name
Debug bool If true, exec ast.Print for go source codes
Records []I18NRecord Analysis result with FuncName

you can analyze such as the following code:

fmt.Println(T("message_uniq_key"))
fmt.Println(SomeStruct.T("message_uniq_key"))

If you want to parse other function names, please fill FuncName:

a := Analyzer{
    FuncName: "Translation",
}

About

Creating go-i18n JSON file by parsing your go source code

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages