Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tkyshm/goi18n-parser
Creating go-i18n JSON file by parsing your go source code
https://github.com/tkyshm/goi18n-parser
ast go golang i18n json
Last synced: 18 days ago
JSON representation
Creating go-i18n JSON file by parsing your go source code
- Host: GitHub
- URL: https://github.com/tkyshm/goi18n-parser
- Owner: tkyshm
- License: mit
- Created: 2017-02-21T07:47:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T08:07:37.000Z (over 7 years ago)
- Last Synced: 2024-07-30T19:09:26.481Z (4 months ago)
- Topics: ast, go, golang, i18n, json
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/tkyshm/goi18n-parser.svg?branch=master)](https://travis-ci.org/tkyshm/goi18n-parser)
# goi18n-parser
Note: Please check [go-i18n](https://github.com/nicksnyder/go-i18n) before to use this package.
## Usage
very simple!
```go
package mainimport (
"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:
```go
fmt.Println(T("message_uniq_key"))
fmt.Println(SomeStruct.T("message_uniq_key"))
```If you want to parse other function names, please fill `FuncName`:
```go
a := Analyzer{
FuncName: "Translation",
}
```