package i18n

// TranslatableString is the interface implemented
// by strings that can be translated.
type TranslatableString interface {
	TranslatedString(lang Languager) string
}

// String is an alias for string, but variables
// or constants declared with the type String will
// be extracted for translation.
type String string

// String returns the String as a plain string.
func (s String) String() string {
	return string(s)
}

// TranslatedString returns the string translated into
// the language returned by lang.
func (s String) TranslatedString(lang Languager) string {
	return T(string(s), lang)
}

package i18n

import (
	"gnd.la/util/textutil"
)

// TranslatableString is the interface implemented
// by strings that can be translated.
type TranslatableString interface {
	TranslatedString(lang Languager) string
}

// String is an alias for string, but variables
// or constants declared with the type String will
// be extracted for translation.
type String string

// String returns the String as a plain string.
func (s String) String() string {
	return string(s)
}

// TranslatedString returns the string translated into
// the language returned by lang.
func (s String) TranslatedString(lang Languager) string {
	if string(s) == "" {
		return ""
	}
	fields, _ := textutil.SplitFields(string(s), "|")
	if len(fields) > 1 {
		return Tc(fields[0], fields[1], lang)
	}
	if len(fields) > 0 {
		return T(fields[0], lang)
	}
	return T(string(s), lang)
}

Add support for i18n.String with multiple fields
Add support for i18n.String with multiple fields

1 field => singular
2 fields => context|singular
3 fields => context|singular|plural
