Socket
Socket
Sign inDemoInstall

github.com/gboncoffee/intergo

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/gboncoffee/intergo


Readme

Source

InterGo

Small library for simple internationalization in Go.

Usage

var ctx InterContext
ctx.Init()
ctx.AddLocale("pt_BR", map[string]string{"hello": "olá"})

Optionally set the prefered locale to properly use ctx.Get():

ctx.SetPreferedLocale("pt_BR")

Get localized strings:

This returns "olá", as we have a "pt_BR" locale set.

txt, err := ctx.GetFromLocale("hello", "pt_BR")

This returns "olá", as we haven't set any Portuguese Portuguese locale, so it falls back to other locales in the same language:

txt, err = ctx.GetFromLocale("hello", "pt_PT")

This returns "hello", as we haven't set any English language locale, so it'll just return the string we have passed.

txt, err = ctx.GetFromLocale("hello", "en_US")

Prefered locale.

It's possible to set a prefered locale. This way, we simply use ctx.Get() to retrive strings instead of passing the locale every time:

err := ctx.SetPreferedLocale(locale)
if err != nil {
    return fmt.Errorf("error parsing locale string: %v", locale)
}
txt := ctx.Get("hello")

Note how ctx.Get() does not need to return any error as it does not parses a locale string.

It's also possible to automatically set the prefered locale from the environment variables LC_ALL and LANG:

err := ctx.AutoSetPreferedLocale()
if err != nil {
    return fmt.Errorf("error parsing environment variables: %v", err)
}

FAQs


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