All Projects β†’ chai2010 β†’ Gettext Go

chai2010 / Gettext Go

Licence: bsd-3-clause
πŸ†Ž GNU gettext for Go (Imported By Kubernetes)

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects
language
365 projects

Projects that are alternatives of or similar to Gettext Go

Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+165.15%)
Mutual labels:  translation, i18n, gettext
Gettext
PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
Stars: ✭ 578 (+775.76%)
Mutual labels:  translation, i18n, gettext
Django Rosetta
Rosetta is a Django application that eases the translation process of your Django projects
Stars: ✭ 806 (+1121.21%)
Mutual labels:  translation, i18n, gettext
Glotpress Wp
🌍 🌎 🌏 GlotPress is a WordPress plugin to let you set up your own collaborative, web-based software translation tool.
Stars: ✭ 205 (+210.61%)
Mutual labels:  translation, i18n, gettext
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+4019.7%)
Mutual labels:  translation, i18n, gettext
gettext-extractor
A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
Stars: ✭ 82 (+24.24%)
Mutual labels:  i18n, translation, gettext
Tempura
Pure Clojure/Script i18n translations library
Stars: ✭ 211 (+219.7%)
Mutual labels:  translation, i18n, gettext
Gotext
Go (Golang) GNU gettext utilities package
Stars: ✭ 292 (+342.42%)
Mutual labels:  translation, i18n, gettext
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+842.42%)
Mutual labels:  translation, i18n
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+875.76%)
Mutual labels:  translation, i18n
Translation
The Translation component provides tools to internationalize your application.
Stars: ✭ 6,196 (+9287.88%)
Mutual labels:  translation, i18n
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+1075.76%)
Mutual labels:  translation, i18n
Angular Translate
Translating your AngularJS 1.x apps
Stars: ✭ 4,414 (+6587.88%)
Mutual labels:  translation, i18n
I18next
i18next: learn once - translate everywhere
Stars: ✭ 5,971 (+8946.97%)
Mutual labels:  translation, i18n
Laravel Translation Loader
Store your translations in the database or other sources
Stars: ✭ 446 (+575.76%)
Mutual labels:  translation, i18n
Ember Intl
Localization library for any Ember Application or Addon
Stars: ✭ 412 (+524.24%)
Mutual labels:  translation, i18n
React I18next
Internationalization for react done right. Using the i18next i18n ecosystem.
Stars: ✭ 6,942 (+10418.18%)
Mutual labels:  translation, i18n
Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-74.24%)
Mutual labels:  translation, i18n
Webfactoryicutranslationbundle
Enables ICU message formatting for translations in Symfony applications.
Stars: ✭ 27 (-59.09%)
Mutual labels:  translation, i18n
Aeiou
i18n scripts
Stars: ✭ 24 (-63.64%)
Mutual labels:  i18n, gettext
  • Go语言QQηΎ€: 102319854, 1055927514
  • 凹语言(ε‡Ήθ―»ιŸ³β€œWa”)(The Wa Programming Language): https://github.com/wa-lang/wa

gettext-go: GNU gettext for Go (Imported By Kubernetes)

Install

  1. go get github.com/chai2010/gettext-go
  2. go run hello.go

The godoc.org or go.dev has more information.

Examples

package main

import (
	"fmt"

	"github.com/chai2010/gettext-go"
)

func main() {
	gettext := gettext.New("hello", "./examples/locale").SetLanguage("zh_CN")
	fmt.Println(gettext.Gettext("Hello, world!"))

	// Output: δ½ ε₯½, δΈ–η•Œ!
}
package main

import (
	"fmt"

	"github.com/chai2010/gettext-go"
)

func main() {
	gettext.SetLanguage("zh_CN")
	gettext.BindLocale(gettext.New("hello", "locale"))

	// gettext.BindLocale("hello", "locale")              // from locale dir
	// gettext.BindLocale("hello", "locale.zip")          // from locale zip file
	// gettext.BindLocale("hello", "locale.zip", zipData) // from embedded zip data

	// translate source text
	fmt.Println(gettext.Gettext("Hello, world!"))
	// Output: δ½ ε₯½, δΈ–η•Œ!

	// if no msgctxt in PO file (only msgid and msgstr),
	// specify context as "" by
	fmt.Println(gettext.PGettext("", "Hello, world!"))
	// Output: δ½ ε₯½, δΈ–η•Œ!

	// translate resource
	fmt.Println(string(gettext.Getdata("poems.txt"))))
	// Output: ...
}

Go file: hello.go; PO file: hello.po;


API Changes (v0.1.0 vs v1.0.0)

Renamed package path

v0.1.0 (old) v1.0.0 (new)
github.com/chai2010/gettext-go/gettext github.com/chai2010/gettext-go
github.com/chai2010/gettext-go/gettext/po github.com/chai2010/gettext-go/po
github.com/chai2010/gettext-go/gettext/mo github.com/chai2010/gettext-go/mo
github.com/chai2010/gettext-go/gettext/plural github.com/chai2010/gettext-go/plural

Renamed functions

v0.1.0 (old) v1.0.0 (new)
gettext-go/gettext.* gettext-go.*
gettext-go/gettext.DefaultLocal gettext-go.DefaultLanguage
gettext-go/gettext.BindTextdomain gettext-go.BindLocale
gettext-go/gettext.Textdomain gettext-go.SetDomain
gettext-go/gettext.SetLocale gettext-go.SetLanguage
gettext-go/gettext/po.Load gettext-go/po.LoadFile
gettext-go/gettext/po.LoadData gettext-go/po.Load
gettext-go/gettext/mo.Load gettext-go/mo.LoadFile
gettext-go/gettext/mo.LoadData gettext-go/mo.Load

Use empty string as the default context for gettext.Gettext

package main

// v0.1.0
// if the **context** missing, use `callerName(2)` as the context:

// v1.0.0
// if the **context** missing, use empty string as the context:

func main() {
	gettext.Gettext("hello")          
	// v0.1.0 => gettext.PGettext("main.main", "hello")
	// v1.0.0 => gettext.PGettext("", "hello")

	gettext.DGettext("domain", "hello")
	// v0.1.0 => gettext.DPGettext("domain", "main.main", "hello")
	// v1.0.0 => gettext.DPGettext("domain", "", "hello")

	gettext.NGettext("domain", "hello", "hello2", n)
	// v0.1.0 => gettext.PNGettext("domain", "main.main", "hello", "hello2", n)
	// v1.0.0 => gettext.PNGettext("domain", "", "hello", "hello2", n)

	gettext.DNGettext("domain", "hello", "hello2", n)
	// v0.1.0 => gettext.DPNGettext("domain", "main.main", "hello", "hello2", n)
	// v1.0.0 => gettext.DPNGettext("domain", "", "hello", "hello2", n)
}

BindLocale support FileSystem interface

// Use FileSystem:
//	BindLocale(New("poedit", "name", OS("path/to/dir"))) // bind "poedit" domain
//	BindLocale(New("poedit", "name", OS("path/to.zip"))) // bind "poedit" domain

New API in v1.0.0

Gettexter interface:

type Gettexter interface {
	FileSystem() FileSystem

	GetDomain() string
	SetDomain(domain string) Gettexter

	GetLanguage() string
	SetLanguage(lang string) Gettexter

	Gettext(msgid string) string
	PGettext(msgctxt, msgid string) string

	NGettext(msgid, msgidPlural string, n int) string
	PNGettext(msgctxt, msgid, msgidPlural string, n int) string

	DGettext(domain, msgid string) string
	DPGettext(domain, msgctxt, msgid string) string
	DNGettext(domain, msgid, msgidPlural string, n int) string
	DPNGettext(domain, msgctxt, msgid, msgidPlural string, n int) string

	Getdata(name string) []byte
	DGetdata(domain, name string) []byte
}

func New(domain, path string, data ...interface{}) Gettexter

FileSystem interface:

type FileSystem interface {
	LocaleList() []string
	LoadMessagesFile(domain, lang, ext string) ([]byte, error)
	LoadResourceFile(domain, lang, name string) ([]byte, error)
	String() string
}

func NewFS(name string, x interface{}) FileSystem
func OS(root string) FileSystem
func ZipFS(r *zip.Reader, name string) FileSystem
func NilFS(name string) FileSystem

BUGS

Please report bugs to [email protected].

Thanks!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].