Here are some common method naming patterns for this use case:
Method Name Ideas
1. GetName(ctx context.Context) string
- Simple and clear
- Language determined from context
2. Name(ctx context.Context) string
- Even more concise
- Common in Go for getter-style methods
3. LocalizedName(ctx context.Context) string
- Explicitly indicates localization
- Self-documenting
4. DisplayName(ctx context.Context) string
- Indicates this is for display purposes
- Common in UI-focused applications
Implementation Example
type Product struct {
NameID string
NameEN string
}
func (p *Product) Name(ctx context.Context) string {
lang := GetLanguageFromContext(ctx) // your context helper
switch lang {
case "id":
return p.NameID
case "en":
return p.NameEN
default:
return p.NameEN // fallback
}
}
// Usage
ctx := context.WithValue(context.Background(), "language", "id")
product := &Product{NameID: "Produk", NameEN: "Product"}
fmt.Println(product.Name(ctx)) // outputs: "Produk"
Real-world Examples
Kubernetes uses similar patterns in their API objects:
Hugo Static Site Generator has extensive i18n support:
Gin Web Framework examples often show similar patterns:
The Name(ctx context.Context) pattern is probably your best bet - it's concise, follows Go conventions, and clearly indicates the method depends on context for language selection.