【问题标题】:What does golang.org/x/text/message.Print accomplish?golang.org/x/text/message.Print 完成了什么?
【发布时间】:2018-07-22 02:57:46
【问题描述】:

Printer.Print 的文档说:

Print 类似于 fmt.Print,但使用特定于语言的格式。

但与 Printer.Printf 相比,我很难看到任何特定语言的内容。

考虑:

package main

import (
    "fmt"

    "golang.org/x/text/language"
    "golang.org/x/text/message"
)

func main() {
    message.SetString(language.English, "foo", "bar")

    p := message.NewPrinter(language.English)
    p.Print("foo")
    fmt.Println()
    p.Printf("foo")
    fmt.Println()
}

结果:

foo
bar

Printer.Print 究竟做了什么(即特定于语言)?

【问题讨论】:

    标签: go internationalization translation


    【解决方案1】:

    包消息为本地化字符串实现格式化 I/O,其功能类似于 fmt 的打印功能。它是 fmt 的直接替代品。

    特定于语言的行为不区分 Printer.PrintPrinter.Printf —— 而是区分它们的 analogous functions in the fmt package。它就在您引用的文档中。

    【讨论】:

    • 我还是不明白。为什么Print 不进行语言查找?因为Print 应该逐字打印它的参数,没有任何解释?
    猜你喜欢
    • 1970-01-01
    • 2016-09-16
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多