simple i18n support that relies on standard go libraries

i18n

Build Status Go Report Card

Simple i18n support that relies on standard go libraries

How to start?

The i18n package mainly includes a set of methods for managing the data. Start by creating a en.json file.

{
    "some": {
        "awesome": {
            "text": "Hello World!"

        }
    }
}

Create a new Translate instance as follows.

var err error
translate, err = i18n.NewTranslate().BindPath("./example").BindMainLocale("en").Init()
if err != nil {
	...
}

Once you setup the i18n instance, you should be able to lookup for messages.

result, err := translate.Lookup("some.awesome.text")
if err != nil {
    ...
}
fmt.Println(result)

The program should print Hello World!

Lookup for a specific locale

result, err := translate.LookupWithLocale("en", "some.awesome.text")
if err != nil {
    ...
}
fmt.Println(result)

The program should print Hello World!

Lookup with arguments

i18n relies on fmt.Sprintf(...) to apply replacements, so you should be able to use it as follows.

Your .json file should look like this.

{
    "some": {
        "awesome": {
            "textWithArgs": "Hello %s!"
        }
    }
}

Lookup for messages like this.

result, err := translate.Lookup("some.awesome.textWithArgs", "i18n")
if err != nil {
    ...
}
fmt.Println(result)

The program should print Hello i18n!

JSON Format

{
    "some": {
        "awesome": {
            "text": "Hello World!",
            "textWithArgs": "Hello %s!"
        }
    }
}

How to install?

go get github.com/alobaton/i18n

How to test?

$ go test ./...

Example

Here you can find an example

Owner
Alvaro Jose Lobaton Restrepo
Software Engineer, Go, Java, Angular
Alvaro Jose Lobaton Restrepo
Similar Resources

Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Procswap is a simple application that allows you to prioritize processes on a Windows machine.

Mar 8, 2022

Simple unpacking script for Ezuri ELF Crypter

Simple unpacking script for Ezuri ELF Crypter

ezuri_unpack A simple unpacking script for the Ezuri ELF Crypter. Based on the analysis done by Ofer Caspi and Fernando Martinez of AT&T Alien Labs

Dec 15, 2022

Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation

stack Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation Purpose Provide a fast, thread safe, and generic Golang Stack API with minim

May 3, 2022

Simple profiling for Go

profile Simple profiling for Go. Easy management of Go's built-in profiling and tracing Based on the widely-used pkg/profile: mostly-compatible API Su

Sep 23, 2022

A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃

go-hashlru A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃 Uses map[interface{}]interface{} to allow

Dec 5, 2022

Simple expression evaluation engine for Go

🌶️ chili Currently in development, Unstable (API may change in future) Simple expression evaluation engine. Expression is one liner that evalutes int

Nov 8, 2022

A simple tool to auto remove unused imports in rust

rust_strip A simple tool to remove unused imports in RUST. Call Cargo build/test Process the warning logs of unused imports Then replace the involved

Oct 15, 2022

A simple business indicator tool that uses a sliding window to detect whether the indicator exceeds the threshold

melon A simple business indicator tool that uses a sliding window to detect whether the indicator exceeds the threshold Usage //create the metric //th

Jul 11, 2021

Simple HTML Modification in Go

Simple HTML Modification in Go Do you grin at the sight of html.Node ? Me too. Modifying HTML in Go should be simple. 🧘🏻 Human friendly: query langu

Sep 29, 2021
Related tags
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing

chrometracing: chrome://tracing trace_event files The chrometracing directory contains libraries for various programming languages that make it easy t

Oct 6, 2022
Instrumentations of third-party libraries using opentelemetry-go library

OpenTelemetry Go Contributions About This reopsitory hosts instrumentations of the following OpenTelemetry libraries: confluentinc/confluent-kafka-go

Nov 14, 2022
go-sundheit:A library built to provide support for defining service health for golang services
go-sundheit:A library built to provide support for defining service health for golang services

A library built to provide support for defining service health for golang services. It allows you to register async health checks for your dependencies and the service itself, and provides a health endpoint that exposes their status.

Dec 27, 2022
Support converting Vault Secrets to diffrent formats.

Vault Converter Support converting Vault Secrets to different formats. vault-converter is a tool designed to synchronize variables from local to Vault

Sep 13, 2022
Go-generics-simple-doubly-linked-list - A simple doubly linked list implemented using generics (Golang)

Welcome to Go-Generics-Simple-Doubly-Linked-List! Hi, This repository contains a

Jun 30, 2022
Simple in Pure Go in Browser Interactive Interpreter
Simple in Pure Go in Browser Interactive Interpreter

GoBook This project is a PoC Don't take it seriously The main point of this project is the use of the library: github.com/brendonmatos/golive Maybe th

Feb 22, 2022
Simple project to demonstrate the loading of eBPF programs via florianl/go-tc.

tc-skeleton Simple project to demonstrate the loading of eBPF programs via florianl/go-tc.

Dec 23, 2022
EGo lets you build, debug und run Go apps on Intel SGX - as simple as conventional Go programming!

EGo lets you build, debug und run Go apps on Intel SGX - as simple as conventional Go programming!

Dec 28, 2022
A super simple Lodash like utility library with essential functions that empowers the development in Go
A super simple Lodash like utility library with essential functions that empowers the development in Go

A simple Utility library for Go Go does not provide many essential built in functions when it comes to the data structure such as slice and map. This

Jan 4, 2023
egg - the simple error aggregator

egg - the simple error aggregator egg ingests errors and aggregates them egg has 1st class support for sentry SDKs so you dont have to change any code

May 1, 2022