Socket
Socket
Sign inDemoInstall

github.com/sgatev/g11n

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/sgatev/g11n

Package g11n is an internationalization library that offers: I. Initialization Create a new instance of g11n. Each instance handles messages and locales separately. Define a struct with messages. Initialize an instance of the struct through the g11n object. Invoke messages on that instance. II. Choosing locale Load a locale in the g11n instance. Different locale loaders could be registered by implementing the locale.Loader interface. Specify the locale for every message struct initialized by this g11n instance. III. Format parameters The parameters of a message call could be formatted by declaring a special type that implements The format method G11nParam is invoked before substituting a parameter in the message. IV. Format result The result of a message call could be further formatted by declaring a special result type that implements The format method G11nResult is invoked after all parameters have been substituted in the message.


Version published

Readme

Source

g11n

Join the chat at https://gitter.im/sgatev/g11n Build Status Coverage Status Go Report Card GoDoc MIT License

g11n /gopherization/ is an internationalization library inspired by GWT that offers:

  • Statically-typed message keys.
  • Parameterized messages.
  • Extendable message formatting.
  • Custom localization file format.
package main

import (
	"fmt"
	"net/http"

	"github.com/sgatev/g11n"
	locale "github.com/sgatev/g11n/http"
)

type Messages struct {
	Hello func(string) string `default:"Hi %v!"`
}

func main() {
	http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
		// Create messages factory.
		factory := g11n.New()

		// Initialize messages value.
		var m Messages
		factory.Init(&m)

		// Set messages locale.
		locale.SetLocale(factory, r)

		fmt.Fprintf(w, m.Hello("World"))
	})

	log.Fatal(http.ListenAndServe(":8080", nil))
}

FAQs

Last updated on 11 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc