linggo

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 4 Imported by: 0

README

Linggo v1.1.1

Ini adalah package bahasa pemrograman go sederhana untuk mengkonfigurasikan tampilan pesan ke dalam multi bahasa.

func Tr()
func Tr(file string, key string) (message interface{}, err error)
func Set()
func Set(file string) (jsonFile JFile, err error)
func Ts()
func (f JFile) Ts(key string) (message interface{})
Instalasi

go get github.com/michaelwp/linggo atau go get github.com/michaelwp/linggo@v1.0.1

Contoh penggunaan

A. Buat Json file untuk menampung bahasa yang digunakan

  • id.json (bahasa Indonesia)
{
  "hello world": "halo dunia",
  "welcome": "selamat datang",
  "please": "silahkan"
}
  • en.json (bahasa Inggris)
{
  "hello world": "hello world"
}
  • fr.json (bahasa Prancis)
{
  "hello world": "Bonjour le monde"
}
  • en.json (bahasa China)
{
  "hello world": "你好,世界"
}

B. memanggil file json setiap kali proses translate

package main

import (
    "github.com/michaelwp/linggo"  // import linggo package
    "log"
)

func main(){
    // contoh translate ke dalam bahasa China
    msg, err := linggo.Tr("ch", "hello world")
    // handle error (disarankan untuk menghandle error dengan cara yang lebih baik)
    if err != nil {
        log.Fatal(err)
    }
    // menampilkan hasil ke layar
    log.Println(msg)
}
Hasil
你好,世界

C. memanggil file json hanya sekali diawal.

package main

import (
    "github.com/michaelwp/linggo"  // import linggo package
    "log"
)

// load json file (bahasa indonesia/ id.json)
var f, _ = linggo.Set("id")

func main() {
    welcome := f.Ts("welcome")
    please := f.Ts("please")

    log.Println(welcome)
    log.Println(please)
}
Hasil
selamat datang
silahkan

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tr

func Tr(file string, key string) (message interface{}, err error)

Types

type JFile added in v1.1.0

type JFile string

func Set added in v1.1.0

func Set(file string) (jsonFile JFile, err error)

func (JFile) Ts added in v1.1.0

func (f JFile) Ts(key string) (message interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL