• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang gettext.Gettext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/chai2010/gettext-go/gettext.Gettext函数的典型用法代码示例。如果您正苦于以下问题:Golang Gettext函数的具体用法?Golang Gettext怎么用?Golang Gettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Gettext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ProfileDeviceAdd

func (c *Client) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*Response, error) {
	st, err := c.ProfileConfig(profile)
	if err != nil {
		return nil, err
	}

	newdev := shared.Device{}
	for _, p := range props {
		results := strings.SplitN(p, "=", 2)
		if len(results) != 2 {
			return nil, fmt.Errorf(gettext.Gettext("no value found in %q"), p)
		}
		k := results[0]
		v := results[1]
		newdev[k] = v
	}
	if st.Devices != nil && st.Devices.ContainsName(devname) {
		return nil, fmt.Errorf(gettext.Gettext("device already exists"))
	}
	newdev["type"] = devtype
	if st.Devices == nil {
		st.Devices = shared.Devices{}
	}
	st.Devices[devname] = newdev

	body := shared.Jmap{"config": st.Config, "name": st.Name, "devices": st.Devices}
	return c.put(fmt.Sprintf("profiles/%s", profile), body, Sync)
}
开发者ID:Malizor,项目名称:lxd,代码行数:28,代码来源:client.go


示例2: init

func init() {
	// bind app domain
	gettext.BindTextdomain("hello", "local", nil)
	gettext.Textdomain("hello")

	// $(LC_MESSAGES) or $(LANG) or empty
	fmt.Println(gettext.Gettext("Gettext in init."))
	fmt.Println(gettext.PGettext("main.init", "Gettext in init."))
	hi.SayHi()
	// Output(depends on local environment):
	// ?
	// ?
	// ?
	// ?

	// set simple chinese
	gettext.SetLocale("zh_CN")

	// simple chinese
	fmt.Println(gettext.Gettext("Gettext in init."))
	fmt.Println(gettext.PGettext("main.init", "Gettext in init."))
	hi.SayHi()
	// Output:
	// Init函数中的Gettext.
	// Init函数中的Gettext.
	// 来自"Hi"包的问候: 你好, 世界!
	// 来自"Hi"包的问候: 你好, 世界!
}
开发者ID:chrisolsen,项目名称:gettext-go,代码行数:28,代码来源:hello.go


示例3: execIfAliases

func execIfAliases(config *lxd.Config, origArgs []string) {
	newArgs := []string{}
	expandedAlias := false
	for _, arg := range origArgs {
		changed := false
		for k, v := range config.Aliases {
			if k == arg {
				expandedAlias = true
				changed = true
				newArgs = append(newArgs, strings.Split(v, " ")...)
				break
			}
		}

		if !changed {
			newArgs = append(newArgs, arg)
		}
	}

	if expandedAlias {
		path, err := exec.LookPath(origArgs[0])
		if err != nil {
			fmt.Fprintf(os.Stderr, gettext.Gettext("processing aliases failed %s\n"), err)
			os.Exit(5)
		}
		ret := syscall.Exec(path, newArgs, syscall.Environ())
		fmt.Fprintf(os.Stderr, gettext.Gettext("processing aliases failed %s\n"), ret)
		os.Exit(5)
	}
}
开发者ID:rockstar,项目名称:lxd,代码行数:30,代码来源:main.go


示例4: flags

func (c *launchCmd) flags() {
	massage_args()
	gnuflag.Var(&profArgs, "profile", "Profile to apply to the new container")
	gnuflag.Var(&profArgs, "p", "Profile to apply to the new container")
	gnuflag.BoolVar(&ephem, "ephemeral", false, gettext.Gettext("Ephemeral container"))
	gnuflag.BoolVar(&ephem, "e", false, gettext.Gettext("Ephemeral container"))
}
开发者ID:jumpstarter-io,项目名称:lxd,代码行数:7,代码来源:launch.go


示例5: GroupId

// GroupId is an adaption from https://codereview.appspot.com/4589049.
func GroupId(name string) (int, error) {
	var grp C.struct_group
	var result *C.struct_group

	bufSize := C.size_t(C.sysconf(C._SC_GETGR_R_SIZE_MAX))
	buf := C.malloc(bufSize)
	if buf == nil {
		return -1, fmt.Errorf(gettext.Gettext("allocation failed"))
	}
	defer C.free(buf)

	// mygetgrgid_r is a wrapper around getgrgid_r to
	// to avoid using gid_t because C.gid_t(gid) for
	// unknown reasons doesn't work on linux.
	rv := C.getgrnam_r(C.CString(name),
		&grp,
		(*C.char)(buf),
		bufSize,
		&result)

	if rv != 0 {
		return -1, fmt.Errorf(gettext.Gettext("failed group lookup: %s"), syscall.Errno(rv))
	}

	if result == nil {
		return -1, fmt.Errorf(gettext.Gettext("unknown group %s"), name)
	}

	return int(C.int(result.gr_gid)), nil
}
开发者ID:rrva,项目名称:lxd,代码行数:31,代码来源:util_linux.go


示例6: main

func main() {
	if err := run(); err != nil {
		// The action we take depends on the error we get.
		msg := fmt.Sprintf(gettext.Gettext("error: %v\n"), err)
		switch t := err.(type) {
		case *url.Error:
			switch u := t.Err.(type) {
			case *net.OpError:
				if u.Op == "dial" && u.Net == "unix" {
					switch errno := u.Err.(type) {
					case syscall.Errno:
						switch errno {
						case syscall.ENOENT:
							msg = gettext.Gettext("LXD socket not found; is LXD running?\n")
						case syscall.ECONNREFUSED:
							msg = gettext.Gettext("Connection refused; is LXD running?\n")
						case syscall.EACCES:
							msg = gettext.Gettext("Permisson denied, are you in the lxd group?\n")
						default:
							msg = fmt.Sprintf("%d %s\n", uintptr(errno), errno.Error())
						}
					}
				}
			}
		}

		fmt.Fprintf(os.Stderr, msg)
		os.Exit(1)
	}
}
开发者ID:jumpstarter-io,项目名称:lxd,代码行数:30,代码来源:main.go


示例7: main

func main() {
	if err := run(); err != nil {
		// The action we take depends on the error we get.
		switch t := err.(type) {
		case *url.Error:
			shared.Debugf("url.Error caught in main(). Op: %s, URL: %s, Err: %s\n", t.Op, t.URL, t.Err)
			switch u := t.Err.(type) {
			case *net.OpError:
				shared.Debugf("Inner error type is a net.OpError: Op: %s Net: %s Addr: %s Err: %T", u.Op, u.Net, u.Addr, u.Err)
				if u.Op == "dial" && u.Net == "unix" {
					// The unix socket we are trying to conect to is refusing our connection attempt. Perhaps the server is not running?
					// Let's at least tell the user about it, since it's hard to get information on wether something is actually listening.
					fmt.Fprintf(os.Stderr, fmt.Sprintf(gettext.Gettext("Cannot connect to unix socket at %s Is the server running?\n"), u.Addr))
					os.Exit(1)
				}
			default:
				shared.Debugf("url.Error's inner Err type is %T", u)
			}
		default:
			shared.Debugf("Error caught in main: %T\n", t)
		}

		fmt.Fprintf(os.Stderr, gettext.Gettext("error: %v\n"), err)
		os.Exit(1)
	}
}
开发者ID:kostyll,项目名称:lxd,代码行数:26,代码来源:main.go


示例8: run

func (c *actionCmd) run(config *lxd.Config, args []string) error {
	if len(args) == 0 {
		return errArgs
	}

	for _, nameArg := range args {
		remote, name := config.ParseRemoteAndContainer(nameArg)
		d, err := lxd.NewClient(config, remote)
		if err != nil {
			return err
		}

		resp, err := d.Action(name, c.action, timeout, force)
		if err != nil {
			return err
		}

		if resp.Type != lxd.Async {
			return fmt.Errorf(gettext.Gettext("bad result type from action"))
		}

		if err := d.WaitForSuccess(resp.Operation); err != nil {
			return fmt.Errorf("%s\n"+gettext.Gettext("Try `lxc info --show-log %s` for more info"), err, name)
		}
	}
	return nil
}
开发者ID:rockstar,项目名称:lxd,代码行数:27,代码来源:action.go


示例9: run

func (c *helpCmd) run(_ *lxd.Config, args []string) error {
	if len(args) > 0 {
		for _, name := range args {
			cmd, ok := commands[name]
			if !ok {
				fmt.Fprintf(os.Stderr, gettext.Gettext("error: unknown command: %s\n"), name)
			} else {
				fmt.Fprintf(os.Stderr, cmd.usage())
			}
		}
		return nil
	}

	fmt.Println(gettext.Gettext("Usage: lxc [subcommand] [options]\nAvailable commands:\n"))
	var names []string
	for name := range commands {
		names = append(names, name)
	}
	sort.Strings(names)
	for _, name := range names {
		cmd := commands[name]
		if showAll || cmd.showByDefault() {
			fmt.Printf("\t%-10s - %s\n", name, summaryLine(cmd.usage()))
		}
	}
	fmt.Println()
	if !showAll {
		fmt.Println(gettext.Gettext("Options:"))
		fmt.Println("  --all    " + gettext.Gettext("Print less common commands."))
	}
	return nil
}
开发者ID:rrva,项目名称:lxd,代码行数:32,代码来源:help.go


示例10: run

func (c *publishCmd) run(config *lxd.Config, args []string) error {
	var cRemote string
	var cName string
	iName := ""
	iRemote := ""
	properties := map[string]string{}
	firstprop := 1 // first property is arg[2] if arg[1] is image remote, else arg[1]

	if len(args) < 1 {
		return errArgs
	}

	cRemote, cName = config.ParseRemoteAndContainer(args[0])
	if len(args) >= 2 && !strings.Contains(args[1], "=") {
		firstprop = 2
		iRemote, iName = config.ParseRemoteAndContainer(args[1])
	} else {
		iRemote, iName = config.ParseRemoteAndContainer("")
	}

	if cName == "" {
		return fmt.Errorf(gettext.Gettext("Container name is mandatory"))
	}
	if iName != "" {
		return fmt.Errorf(gettext.Gettext("There is no \"image name\".  Did you want an alias?"))
	}

	if cRemote != iRemote {
		/*
		 * Get the source remote to export the container over a websocket,
		 * pass that ws to the dest remote, and have it import it as an
		 * image
		 */
		return fmt.Errorf(gettext.Gettext("Publish to remote server is not supported yet"))
	}

	d, err := lxd.NewClient(config, iRemote)
	if err != nil {
		return err
	}

	for i := firstprop; i < len(args); i++ {
		entry := strings.SplitN(args[i], "=", 2)
		if len(entry) < 2 {
			return errArgs
		}
		properties[entry[0]] = entry[1]
	}

	fp, err := d.ImageFromContainer(cName, makePublic, pAliases, properties)

	if err == nil {
		fmt.Printf(gettext.Gettext("Container published with fingerprint %s")+"\n", fp)
	}
	return err
}
开发者ID:argami,项目名称:goard,代码行数:56,代码来源:publish.go


示例11: showImages

func showImages(images []shared.ImageInfo) error {
	data := [][]string{}
	for _, image := range images {
		shortest := shortestAlias(image.Aliases)
		if len(image.Aliases) > 1 {
			shortest = fmt.Sprintf(gettext.Gettext("%s (%d more)"), shortest, len(image.Aliases)-1)
		}
		fp := image.Fingerprint[0:12]
		public := gettext.Gettext("no")
		description := findDescription(image.Properties)
		if shared.InterfaceToBool(image.Public) {
			public = gettext.Gettext("yes")
		}
		const layout = "Jan 2, 2006 at 3:04pm (MST)"
		uploaded := time.Unix(image.UploadDate, 0).Format(layout)
		arch, _ := shared.ArchitectureName(image.Architecture)
		data = append(data, []string{shortest, fp, public, description, arch, uploaded})
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetColWidth(50)
	table.SetHeader([]string{
		gettext.Gettext("ALIAS"),
		gettext.Gettext("FINGERPRINT"),
		gettext.Gettext("PUBLIC"),
		gettext.Gettext("DESCRIPTION"),
		gettext.Gettext("ARCH"),
		gettext.Gettext("UPLOAD DATE")})
	sort.Sort(ByName(data))
	table.AppendBulk(data)
	table.Render()

	return nil
}
开发者ID:achanda,项目名称:lxd,代码行数:34,代码来源:image.go


示例12: doProfileApply

func doProfileApply(client *lxd.Client, c string, p string) error {
	resp, err := client.ApplyProfile(c, p)
	if err == nil {
		if p == "" {
			p = gettext.Gettext("(none)")
		}
		fmt.Printf(gettext.Gettext("Profile %s applied to %s")+"\n", p, c)
	} else {
		return err
	}
	return client.WaitForSuccess(resp.Operation)
}
开发者ID:achanda,项目名称:lxd,代码行数:12,代码来源:profile.go


示例13: usage

func (c *configCmd) usage() string {
	return gettext.Gettext(
		"Manage configuration.\n" +
			"\n" +
			"lxc config device add <container> <name> <type> [key=value]...\n" +
			"               Add a device to a container\n" +
			"lxc config device list <container>                     List devices for container\n" +
			"lxc config device show <container>                     Show full device details for container\n" +
			"lxc config device remove <container> <name>            Remove device from container\n" +
			"lxc config edit <container>                            Edit container configuration in external editor\n" +
			"lxc config get <container> key                         Get configuration key\n" +
			"lxc config set <container> key value                   Set container configuration key\n" +
			"lxc config unset <container> key                       Unset container configuration key\n" +
			"lxc config set key value                               Set server configuration key\n" +
			"lxc config unset key                                   Unset server configuration key\n" +
			"lxc config show <container>                            Show container configuration\n" +
			"lxc config trust list [remote]                         List all trusted certs.\n" +
			"lxc config trust add [remote] [certfile.crt]           Add certfile.crt to trusted hosts.\n" +
			"lxc config trust remove [remote] [hostname|fingerprint]\n" +
			"               Remove the cert from trusted hosts.\n" +
			"\n" +
			"Examples:\n" +
			"To mount host's /share/c1 onto /opt in the container:\n" +
			"\tlxc config device add container1 mntdir disk source=/share/c1 path=opt\n" +
			"To set an lxc config value:\n" +
			"\tlxc config set <container> raw.lxc 'lxc.aa_allow_incomplete = 1'\n" +
			"To set the server trust password:\n" +
			"\tlxc config set core.trust_password blah\n")
}
开发者ID:Ramzec,项目名称:lxd,代码行数:29,代码来源:config.go


示例14: usage

func (c *imageCmd) usage() string {
	return gettext.Gettext(
		`Manipulate container images.

lxc image import <tarball> [rootfs tarball] [target] [--public] [--created-at=ISO-8601] [--expires-at=ISO-8601] [--fingerprint=FINGERPRINT] [prop=value]

lxc image copy [remote:]<image> <remote>: [--alias=ALIAS].. [--copy-alias] [--public]
lxc image delete [remote:]<image>
lxc image edit [remote:]<image>
lxc image export [remote:]<image>
lxc image info [remote:]<image>
lxc image list [remote:] [filter]
lxc image show [remote:]<image>

Lists the images at specified remote, or local images.
Filters are not yet supported.

lxc image alias create <alias> <target>
lxc image alias delete <alias>
lxc image alias list [remote:]

Create, delete, list image aliases. Example:
lxc remote add store2 images.linuxcontainers.org
lxc image alias list store2:`)
}
开发者ID:achanda,项目名称:lxd,代码行数:25,代码来源:image.go


示例15: run

func (c *snapshotCmd) run(config *lxd.Config, args []string) error {
	if len(args) < 1 {
		return errArgs
	}

	var snapname string
	if len(args) < 2 {
		snapname = ""
	} else {
		snapname = args[1]
	}

	remote, name := config.ParseRemoteAndContainer(args[0])
	d, err := lxd.NewClient(config, remote)
	if err != nil {
		return err
	}

	// we don't allow '/' in snapshot names
	if shared.IsSnapshot(snapname) {
		return fmt.Errorf(gettext.Gettext("'/' not allowed in snapshot name\n"))
	}

	resp, err := d.Snapshot(name, snapname, c.stateful)
	if err != nil {
		return err
	}

	return d.WaitForSuccess(resp.Operation)
}
开发者ID:rrva,项目名称:lxd,代码行数:30,代码来源:snapshot.go


示例16: doProfileCreate

func doProfileCreate(client *lxd.Client, p string) error {
	err := client.ProfileCreate(p)
	if err == nil {
		fmt.Printf(gettext.Gettext("Profile %s created\n"), p)
	}
	return err
}
开发者ID:dvbportal,项目名称:osx-lxd,代码行数:7,代码来源:profile.go


示例17: baseGet

func (c *Client) baseGet(getUrl string) (*Response, error) {
	req, err := http.NewRequest("GET", getUrl, nil)
	if err != nil {
		return nil, err
	}

	req.Header.Set("User-Agent", shared.UserAgent)

	resp, err := c.http.Do(req)
	if err != nil {
		return nil, err
	}

	if c.scert != nil && resp.TLS != nil {
		if !bytes.Equal(resp.TLS.PeerCertificates[0].Raw, c.scert.Raw) {
			pUrl, _ := url.Parse(getUrl)
			return nil, fmt.Errorf(gettext.Gettext("Server certificate for host %s has changed. Add correct certificate or remove certificate in %s"), pUrl.Host, ConfigPath("servercerts"))
		}
	}

	if c.scertDigestSet == false && resp.TLS != nil {
		c.scertWire = resp.TLS.PeerCertificates[0]
		c.scertIntermediates = x509.NewCertPool()
		for _, cert := range resp.TLS.PeerCertificates {
			c.scertIntermediates.AddCert(cert)
		}
		c.scertDigest = sha256.Sum256(resp.TLS.PeerCertificates[0].Raw)
		c.scertDigestSet = true
	}

	return HoistResponse(resp, Sync)
}
开发者ID:Malizor,项目名称:lxd,代码行数:32,代码来源:client.go


示例18: unixDial

func unixDial(networ, addr string) (net.Conn, error) {
	var raddr *net.UnixAddr
	var err error
	if addr == "unix.socket:80" {
		raddr, err = net.ResolveUnixAddr("unix", shared.VarPath("unix.socket"))
		if err != nil {
			return nil, fmt.Errorf(gettext.Gettext("cannot resolve unix socket address: %v"), err)
		}
	} else { // TODO - I think this is dead code
		raddr, err = net.ResolveUnixAddr("unix", addr)
		if err != nil {
			return nil, fmt.Errorf(gettext.Gettext("cannot resolve unix socket address: %v"), err)
		}
	}
	return net.DialUnix("unix", nil, raddr)
}
开发者ID:Malizor,项目名称:lxd,代码行数:16,代码来源:client.go


示例19: ImageFromContainer

func (c *Client) ImageFromContainer(cname string, public bool, aliases []string, properties map[string]string) (string, error) {
	source := shared.Jmap{"type": "container", "name": cname}
	if shared.IsSnapshot(cname) {
		source["type"] = "snapshot"
	}
	body := shared.Jmap{"public": public, "source": source, "properties": properties}

	resp, err := c.post("images", body, Async)
	if err != nil {
		return "", err
	}

	jmap, err := c.AsyncWaitMeta(resp)
	if err != nil {
		return "", err
	}

	fingerprint, err := jmap.GetString("fingerprint")
	if err != nil {
		return "", err
	}

	/* add new aliases */
	for _, alias := range aliases {
		c.DeleteAlias(alias)
		err = c.PostAlias(alias, alias, fingerprint)
		if err != nil {
			fmt.Printf(gettext.Gettext("Error adding alias %s")+"\n", alias)
		}
	}

	return fingerprint, nil
}
开发者ID:Malizor,项目名称:lxd,代码行数:33,代码来源:client.go


示例20: ContainerDeviceAdd

func (c *Client) ContainerDeviceAdd(container, devname, devtype string, props []string) (*Response, error) {
	st, err := c.ContainerStatus(container, false)
	if err != nil {
		return nil, err
	}

	newdev := shared.Device{}
	for _, p := range props {
		results := strings.SplitN(p, "=", 2)
		if len(results) != 2 {
			return nil, fmt.Errorf(gettext.Gettext("no value found in %q\n"), p)
		}
		k := results[0]
		v := results[1]
		newdev[k] = v
	}
	newdev["type"] = devtype
	if st.Devices == nil {
		st.Devices = shared.Devices{}
	}
	st.Devices[devname] = newdev

	body := shared.Jmap{"config": st.Config, "profiles": st.Profiles, "name": st.Name, "devices": st.Devices}
	return c.put(fmt.Sprintf("containers/%s", container), body, Async)
}
开发者ID:dvbportal,项目名称:osx-lxd,代码行数:25,代码来源:client.go



注:本文中的github.com/chai2010/gettext-go/gettext.Gettext函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang webp.Decode函数代码示例发布时间:2022-05-23
下一篇:
Golang models.VirtualMachine类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap