Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add feature change package name and message type name #295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mr-tron
Copy link

@mr-tron mr-tron commented Mar 8, 2023

It can be useful for creating simple wrappers like #292 asks. For example my wrapper:

package i18n

import (
	"embed"
	"github.com/BurntSushi/toml"
	"github.com/nicksnyder/go-i18n/v2/i18n"
	"golang.org/x/text/language"
)

//go:embed locale.*.toml
var localeFS embed.FS
var bundle *i18n.Bundle

func init() {
	bundle = i18n.NewBundle(language.English)
	bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
	bundle.LoadMessageFileFS(localeFS, "active.en.toml")
}

type C = i18n.LocalizeConfig
type M = i18n.Message

func T(lang string, c C) string {
	s, _ := i18n.NewLocalizer(bundle, lang).Localize(&c)
	return s
}

and i can use it like

import "my/wrapper/path/i18n"

...

i18n.T(i18n.C{DefaultMessage:&i18n.M{blah blah blah}})

@mr-tron
Copy link
Author

mr-tron commented Mar 14, 2023

hello?

@nicksnyder
Copy link
Owner

This change is just to enable you to write something like i18n.M instead of i18n.Message?

I am currently hesitant to merge a change like this, it seems unnecessary, and I am wondering if there is a better way to accomplish what you want (i.e. having i18n expose a type alias), but any case a change like this would needs tests before I could consider merging it.

@mr-tron
Copy link
Author

mr-tron commented Oct 25, 2023

It allows to make proxy-package inside my project. Aliases is only one example of usage.
Ok. I will try to write tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants