goi18np

package module
v0.0.0-...-51b732e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2017 License: MIT Imports: 7 Imported by: 0

README

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",
}

Documentation

Index

Constants

View Source
const (
	AnalyzerFuncName = "T"
	MaxDepth         = 5
)

Const values

Variables

This section is empty.

Functions

func SaveJSON

func SaveJSON(w io.Writer, i18nrs I18NRecords) error

SaveJSON save I18NRecords as json without indent

func SaveJSONIndent

func SaveJSONIndent(w io.Writer, i18nrs I18NRecords, prefix, indent string) error

SaveJSONIndent save I18NRecords as json with indent

Types

type Analyzer

type Analyzer struct {
	FuncName string // Function name
	Debug    bool
	Records  []I18NRecord
}

Analyzer struct

func (*Analyzer) AnalyzeFromFile

func (da *Analyzer) AnalyzeFromFile(filename string) []I18NRecord

AnalyzeFromFile analyzes a go file

func (*Analyzer) AnalyzeFromFiles

func (da *Analyzer) AnalyzeFromFiles(files []string) []I18NRecord

AnalyzeFromFiles analyzes multiple go source files

func (Analyzer) Name

func (da Analyzer) Name() string

Name returns the function name that is used to analyze go source code

func (Analyzer) SaveJSON

func (da Analyzer) SaveJSON(w io.Writer) error

SaveJSON saves JSON based on go-i18np format

func (Analyzer) SaveJSONIndent

func (da Analyzer) SaveJSONIndent(w io.Writer, prefix, indent string) error

SaveJSONIndent saves JSON based on go-i18np format

type I18NRecord

type I18NRecord struct {
	ID          string `json:"id"`
	Translation string `json:"translation"`
}

I18NRecord has `id` and `translation` field

type I18NRecords

type I18NRecords []I18NRecord

I18NRecords is slice of I18NRecord

func (I18NRecords) SortByID

func (rs I18NRecords) SortByID()

SortByID sorts I18NRecords by ID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL