Skip to content

this is a multilingual translator written in go

Notifications You must be signed in to change notification settings

Brougud/translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Translator

This is a small library that can be used to translate JSON values, into strings, with multi language capability.

Example

Directory

┏ main.go
┖ translations
  ┖ en_US.json

en_US.json

{
    "value": "this is a value",
    "nested": {
        "value": "this is a nested value"
    },
    "formated": "this is a %v string"
}

main.go

package main

import (
    "github.com/Brougud/translator"
    "github.com/Brougud/translator/language"
)

func main() {
    translator.Initalize("translations")
    lang, err := translator.Register("en_US", language.New("English", "icon/image"))
    if err != nil {
        panic(err)
    }
    fmt.Println(lang.Translate("value"))
    fmt.Println(lang.Translate("nested.value"))
    fmt.Println(lang.Translatef("formated", "cool"))
}

running this will output

this is a string
this is a nested value
this is a cool string

About

this is a multilingual translator written in go

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages