fy

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: MIT Imports: 9 Imported by: 4

README

            ____
           / __/_  __
          / /_/ / / /
         / __/ /_/ /
        /_/  \__, /
            /____/

中文 | English

Release Build Status Go Report Card GoDoc DUB

fy是一个命令行下的翻译工具。

安装

Homebrew

brew tap xwjdsh/tap
brew install xwjdsh/tap/fy

Go

go get -u github.com/xwjdsh/fy/cmd/fy

Docker

alias fy='docker run -t --rm wendellsun/fy'

Manual

releases 下载可执行文件并将其放到 PATH 环境变量对应的路径中。

使用

Usage of fy:
  -d    调试模式,如果翻译过程出现错误,会将错误信息作为翻译结果展示
  -e string
        选择除了指定以外的翻译者, 逗号分隔, 例如 'bd,gg', 也可以通过 'FY_EXCEPT' 环境变量来配置
  -f string
        翻译文件的路径
  -o string
        选择指定的翻译者, 逗号分隔, 例如 'bd,gg', 也可以通过 'FY_ONLY' 环境变量来配置
  -s    显示支持的翻译者的信息
  -t string   
        指定翻译的目标语言

语言映射

简写 对应语言
zh-CN 中文
en 英语
ru 俄语
ja 日语
de 德语
fr 法语
ko 韩语
es 西班牙语

示例

# 显示支持的翻译者的信息
fy -s

# 不输入参数,则会访问剪贴板内容
fy

# 普通方式
fy test

# 调试模式
fy -d test

# 指定目标语言
fy -t ja 测试翻译为日语

# 指定中文的翻译语言,默认为英语
FY_CN_TO=ko fy 翻译为韩语

# 指定非中文的翻译语言,默认为简体中文
FY_NOT_CN_TO=en fy 중국어로 번역

# 翻译文件
cat `test.txt` | fy
fy < test.txt
fy -f test.txt

# 选择除了指定以外的翻译者
FY_EXCEPT='bd,sg' fy test
fy -e 'bd,sg' test

# 选择指定的翻译者
FY_ONLY='gg,qq' fy test
fy -o 'gg,qq' test

协议

MIT License

Documentation

Index

Constants

View Source
const (
	Chinese  = "zh-CN"
	English  = "en"
	Russian  = "ru"
	Japanese = "ja"
	German   = "de"
	French   = "fr"
	Korean   = "ko"
	Spanish  = "es"
)
View Source
const (
	// IconGood icon goog
	IconGood = "✔"
	// IconBad icon bad
	IconBad = "✗"
	Logo = `
	    ____     
	   / __/_  __
	  / /_/ / / /
	 / __/ /_/ / 
	/_/  \__, /  
	    /____/   

`
	// Desc version and homepage
	Desc = `
 version: %s
homepage: https://github.com/xwjdsh/fy
`
	// CoffeeEmoji coffee emoji
	CoffeeEmoji = "\u2615\ufe0f"
)

Variables

This section is empty.

Functions

func AddCookies

func AddCookies(req *http.Request, cookies []*http.Cookie) *http.Request

AddCookies add cookies to http request

func IsChinese

func IsChinese(str string) bool

IsChinese whether param is Chinese

func NotReadResp

func NotReadResp(resp *http.Response, err error) (*http.Response, error)

NotReadResp dont read response, just closed it

func PrintSource

func PrintSource(name, fullname, source string)

PrintSource print source info

func ReadResp

func ReadResp(resp *http.Response, err error) (*http.Response, []byte, error)

ReadResp read response and closed it

func Register

func Register(t Translator)

Register register a translator

func SendRequest

func SendRequest(method, urlStr string, body io.Reader, f func(*http.Request) error) (*http.Response, []byte, error)

SendRequest send request

Types

type Request

type Request struct {
	// The target language of translation
	TargetLang string
	// Text translate text
	Text string
}

Request translate request

type Response

type Response struct {
	// FullName translator fullname
	FullName string
	// Result translate result
	Result string
	// Err translate error
	Err error
}

Response translate response

func NewResp

func NewResp(t Translator) *Response

NewResp new Response, set fullname

type Translator

type Translator interface {
	// Desc get translator info
	Desc() (name string, fullname string, source string)
	// Translate do translation task
	Translate(Request) *Response
}

Translator translator interface

func Filter

func Filter(only, except string) ([]Translator, error)

Filter filter translators

Directories

Path Synopsis
cmd
fy command

Jump to

Keyboard shortcuts

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