https://github.com/moemoe89/go-localization
🇮🇩 🇯🇵 🇺🇸 go-localization is a Go package that provides tool for showing message based on language code.
https://github.com/moemoe89/go-localization
go golang language localization
Last synced: 6 months ago
JSON representation
🇮🇩 🇯🇵 🇺🇸 go-localization is a Go package that provides tool for showing message based on language code.
- Host: GitHub
- URL: https://github.com/moemoe89/go-localization
- Owner: moemoe89
- License: mit
- Created: 2019-11-13T08:43:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-15T23:29:25.000Z (almost 5 years ago)
- Last Synced: 2024-06-21T05:03:12.827Z (11 months ago)
- Topics: go, golang, language, localization
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/moemoe89/go-localization)
[](https://coveralls.io/github/moemoe89/go-localization?branch=master)
[](https://godoc.org/github.com/moemoe89/go-localization)
[](https://goreportcard.com/report/github.com/moemoe89/go-localization)# go-localization
## Description
go-localization is a Go package that provides tool for showing message based on language code.
It has the following rules:* configuration message written in JSON with specific format.
* if the message is found but the language code is not, will return by the default language code that was set up previously.
* if the message is not found, will return the message.## Requirements
Go programming language
## JSON Format
```
{
"en": {
"Good morning": "Good morning"
},
"id": {
"Good morning": "Selamat pagi"
},
"jp": {
"Good morning": "おはようございます"
}
}```
## Getting Started
The go-localization package mainly includes a set of methods for managing the data. You use
method `language.New()` to init the data, and you can call some method to bind config```
cfg := language.New()
// path to look for the language file in
cfg.BindPath("./language.json")
// call multiple times to add many search paths
cfg.BindPath("/home/appname/language.json")
cfg.BindMainLocale("en")
```
If you want to user the message convert function, start with the init function````
lang, err := cfg.Init()
if err != nil {
panic(err)
}// print some message in different languages
fmt.Println(lang.Lookup("en", "Good morning"))
fmt.Println(lang.Lookup("id", "Good morning"))
fmt.Println(lang.Lookup("jp", "Good morning"))
// if language not found, will return default language
fmt.Println(lang.Lookup("fr", "Good morning"))
// print unlisted message
fmt.Println(lang.Lookup("en", "Good night"))
````### Installation
Run the following command to install the package:
```
go get github.com/moemoe89/go-localization
```### Example
You can find a example for the implementation at [example](https://github.com/moemoe89/go-localization/blob/master/example/main.go) repository.