Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8ac87a60c | |||
| 67d7b9ca60 | |||
| bb9b8c2585 | |||
| b4ab6497b5 | |||
| 2441e55972 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
|||||||
run: go build -v .
|
run: go build -v .
|
||||||
|
|
||||||
- name: Install xgotext CLI
|
- name: Install xgotext CLI
|
||||||
run: go install -v github.com/leonelquinteros/gotext/cli/xgotext
|
run: go install -v git.deineagentur.com/DeineAgenturUG/gotext/cli/xgotext
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test -v -race ./...
|
run: go test -v -race ./...
|
||||||
|
|||||||
32
README.md
32
README.md
@@ -1,9 +1,9 @@
|
|||||||
[](https://github.com/leonelquinteros/gotext)
|
[](https://git.deineagentur.com/DeineAgenturUG/gotext)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://godoc.org/github.com/leonelquinteros/gotext)
|
[](https://godoc.org/git.deineagentur.com/DeineAgenturUG/gotext)
|
||||||

|

|
||||||
[](https://travis-ci.org/leonelquinteros/gotext)
|
[](https://travis-ci.org/leonelquinteros/gotext)
|
||||||
[](https://goreportcard.com/report/github.com/leonelquinteros/gotext)
|
[](https://goreportcard.com/report/git.deineagentur.com/DeineAgenturUG/gotext)
|
||||||
|
|
||||||
# Gotext
|
# Gotext
|
||||||
|
|
||||||
@@ -35,13 +35,13 @@
|
|||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
Refer to the Godoc package documentation at (https://godoc.org/github.com/leonelquinteros/gotext)
|
Refer to the Godoc package documentation at (https://godoc.org/git.deineagentur.com/DeineAgenturUG/gotext)
|
||||||
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
```
|
```
|
||||||
go get github.com/leonelquinteros/gotext
|
go get git.deineagentur.com/DeineAgenturUG/gotext
|
||||||
```
|
```
|
||||||
|
|
||||||
- There are no requirements or dependencies to use this package.
|
- There are no requirements or dependencies to use this package.
|
||||||
@@ -58,28 +58,28 @@ You can rely on this to use your preferred vendoring tool or to manually retriev
|
|||||||
|
|
||||||
### Vendoring with [Go Modules](https://github.com/golang/go/wiki/Modules) (Recommended)
|
### Vendoring with [Go Modules](https://github.com/golang/go/wiki/Modules) (Recommended)
|
||||||
|
|
||||||
Add `github.com/leonelquinteros/gotext` inside the `require` section in your `go.mod` file.
|
Add `git.deineagentur.com/DeineAgenturUG/gotext` inside the `require` section in your `go.mod` file.
|
||||||
|
|
||||||
i.e.
|
i.e.
|
||||||
```
|
```
|
||||||
require (
|
require (
|
||||||
github.com/leonelquinteros/gotext v1.4.0
|
git.deineagentur.com/DeineAgenturUG/gotext v1.5.0
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Vendoring with [dep](https://golang.github.io/dep/)
|
### Vendoring with [dep](https://golang.github.io/dep/)
|
||||||
|
|
||||||
To use last stable version (v1.4.0 at the moment of writing)
|
To use last stable version (v1.5.0 at the moment of writing)
|
||||||
|
|
||||||
```
|
```
|
||||||
dep ensure -add github.com/leonelquinteros/gotext@v1.4.0
|
dep ensure -add git.deineagentur.com/DeineAgenturUG/gotext@v1.5.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Import as
|
Import as
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "github.com/leonelquinteros/gotext"
|
import "git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ For quick/simple translations you can use the package level functions directly.
|
|||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -179,7 +179,7 @@ Use the fmt.Printf syntax (from Go's "fmt" package) to specify how to print the
|
|||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -204,7 +204,7 @@ so you can handle each settings on their own.
|
|||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -241,7 +241,7 @@ you can directly use the Po object to parse it and access the translations in th
|
|||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -277,7 +277,7 @@ Plural formulas are parsed and evaluated using [Kinako](https://github.com/mattn
|
|||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ CLI tool to extract translation strings from Go packages into .POT files.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```
|
```
|
||||||
go install github.com/leonelquinteros/gotext/cli/xgotext
|
go install git.deineagentur.com/DeineAgenturUG/gotext/cli/xgotext
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
alias "github.com/leonelquinteros/gotext"
|
alias "git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
"github.com/leonelquinteros/gotext/cli/xgotext/fixtures/pkg"
|
"git.deineagentur.com/DeineAgenturUG/gotext/cli/xgotext/fixtures/pkg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Fake object with methods similar to gotext
|
// Fake object with methods similar to gotext
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import "github.com/leonelquinteros/gotext"
|
import "git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
|
|
||||||
type SubTranslate struct {
|
type SubTranslate struct {
|
||||||
L gotext.Locale
|
L gotext.Locale
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext/cli/xgotext/parser"
|
"git.deineagentur.com/DeineAgenturUG/gotext/cli/xgotext/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ func (g *GoFile) checkType(rawType types.Type) bool {
|
|||||||
return g.checkType(t.Elem())
|
return g.checkType(t.Elem())
|
||||||
|
|
||||||
case *types.Named:
|
case *types.Named:
|
||||||
if t.Obj().Pkg() == nil || t.Obj().Pkg().Path() != "github.com/leonelquinteros/gotext" {
|
if t.Obj().Pkg() == nil || t.Obj().Pkg().Path() != "git.deineagentur.com/DeineAgenturUG/gotext" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -187,7 +187,7 @@ func (g *GoFile) inspectCallExpr(n *ast.CallExpr) {
|
|||||||
// object is a package if the Obj is not set
|
// object is a package if the Obj is not set
|
||||||
if e.Obj == nil {
|
if e.Obj == nil {
|
||||||
pkg, ok := g.importedPackages[e.Name]
|
pkg, ok := g.importedPackages[e.Name]
|
||||||
if !ok || pkg.PkgPath != "github.com/leonelquinteros/gotext" {
|
if !ok || pkg.PkgPath != "git.deineagentur.com/DeineAgenturUG/gotext" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/leonelquinteros/gotext
|
module git.deineagentur.com/DeineAgenturUG/gotext
|
||||||
|
|
||||||
// go: no requirements found in Gopkg.lock
|
// go: no requirements found in Gopkg.lock
|
||||||
|
|
||||||
|
|||||||
28
gotext.go
28
gotext.go
@@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Package gotext implements GNU gettext utilities.
|
Package gotext implements GNU gettext utilities.
|
||||||
|
|
||||||
For quick/simple translations you can use the package level functions directly.
|
For quick/simple translations you can use the package level functions directly.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Configure package
|
// Configure package
|
||||||
gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name")
|
gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name")
|
||||||
|
|
||||||
// Translate text from default domain
|
// Translate text from default domain
|
||||||
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
|
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
|
||||||
|
|
||||||
// Translate text from a different domain without reconfigure
|
// Translate text from a different domain without reconfigure
|
||||||
fmt.Println(gotext.GetD("domain2", "Another text on a different domain"))
|
fmt.Println(gotext.GetD("domain2", "Another text on a different domain"))
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package gotext
|
package gotext
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package gotext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -99,14 +98,14 @@ msgstr "Another text on another domain"
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory on default location
|
// Create Locales directory on default location
|
||||||
dirname := path.Join("/tmp", "en_US")
|
dirname := filepath.Join("/tmp", "en_US")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PO content to default domain file
|
// Write PO content to default domain file
|
||||||
filename := path.Join(dirname, "default.po")
|
filename := filepath.Join(dirname, "default.po")
|
||||||
|
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,7 +117,7 @@ msgstr "Another text on another domain"
|
|||||||
t.Fatalf("Can't write to test file: %s", err.Error())
|
t.Fatalf("Can't write to test file: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
anotherFilename := path.Join(dirname, "another.po")
|
anotherFilename := filepath.Join(dirname, "another.po")
|
||||||
|
|
||||||
af, err := os.Create(anotherFilename)
|
af, err := os.Create(anotherFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -198,14 +197,14 @@ msgstr[1] ""
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory on default location
|
// Create Locales directory on default location
|
||||||
dirname := path.Join("/tmp", "en_US")
|
dirname := filepath.Join("/tmp", "en_US")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PO content to default domain file
|
// Write PO content to default domain file
|
||||||
filename := path.Join(dirname, "default.po")
|
filename := filepath.Join(dirname, "default.po")
|
||||||
|
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -318,19 +317,19 @@ msgstr[1] "Custom ctx translations"
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory and files on temp location
|
// Create Locales directory and files on temp location
|
||||||
dirname := path.Join("/tmp", "en_US")
|
dirname := filepath.Join("/tmp", "en_US")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fDefault, err := os.Create(path.Join(dirname, "default.po"))
|
fDefault, err := os.Create(filepath.Join(dirname, "default.po"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test file: %s", err.Error())
|
t.Fatalf("Can't create test file: %s", err.Error())
|
||||||
}
|
}
|
||||||
defer fDefault.Close()
|
defer fDefault.Close()
|
||||||
|
|
||||||
fCustom, err := os.Create(path.Join(dirname, "custom.po"))
|
fCustom, err := os.Create(filepath.Join(dirname, "custom.po"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test file: %s", err.Error())
|
t.Fatalf("Can't create test file: %s", err.Error())
|
||||||
}
|
}
|
||||||
@@ -408,14 +407,14 @@ msgstr "Some random Translation in a context"
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory on default location
|
// Create Locales directory on default location
|
||||||
dirname := path.Join("/tmp", "en_US")
|
dirname := filepath.Join("/tmp", "en_US")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PO content to default domain file
|
// Write PO content to default domain file
|
||||||
filename := path.Join("/tmp", GetDomain()+".po")
|
filename := filepath.Join("/tmp", GetDomain()+".po")
|
||||||
|
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -437,7 +436,7 @@ msgstr "Some random Translation in a context"
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
GetLibrary()
|
GetLibrary()
|
||||||
SetLibrary(path.Join("/tmp", "gotextlib"))
|
SetLibrary(filepath.Join("/tmp", "gotextlib"))
|
||||||
GetDomain()
|
GetDomain()
|
||||||
SetDomain("default")
|
SetDomain("default")
|
||||||
GetLanguage()
|
GetLanguage()
|
||||||
|
|||||||
44
locale.go
44
locale.go
@@ -9,7 +9,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,10 +21,10 @@ multiple languages at the same time by working with this object.
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -41,9 +41,8 @@ Example:
|
|||||||
l.AddDomain("extras")
|
l.AddDomain("extras")
|
||||||
|
|
||||||
// Translate text from domain
|
// Translate text from domain
|
||||||
fmt.Println(l.GetD("extras", "Translate this"))
|
fmt.Println(l.GetD("extras", "Translate this"))
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
type Locale struct {
|
type Locale struct {
|
||||||
// Path to locale files.
|
// Path to locale files.
|
||||||
@@ -72,26 +71,41 @@ func NewLocale(p, l string) *Locale {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SetLang ...
|
||||||
|
func (l *Locale) SetLang(lang string) {
|
||||||
|
l.lang = lang
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetLang ...
|
||||||
|
func (l *Locale) GetLang() string {
|
||||||
|
return l.lang
|
||||||
|
}
|
||||||
|
|
||||||
|
//SetPath ...
|
||||||
|
func (l *Locale) SetPath(path string) {
|
||||||
|
l.path = path
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Locale) findExt(dom, ext string) string {
|
func (l *Locale) findExt(dom, ext string) string {
|
||||||
filename := path.Join(l.path, l.lang, "LC_MESSAGES", dom+"."+ext)
|
filename := filepath.Join(l.path, l.lang, "LC_MESSAGES", dom+"."+ext)
|
||||||
if _, err := os.Stat(filename); err == nil {
|
if _, err := os.Stat(filename); err == nil {
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(l.lang) > 2 {
|
if len(l.lang) > 2 {
|
||||||
filename = path.Join(l.path, l.lang[:2], "LC_MESSAGES", dom+"."+ext)
|
filename = filepath.Join(l.path, l.lang[:2], "LC_MESSAGES", dom+"."+ext)
|
||||||
if _, err := os.Stat(filename); err == nil {
|
if _, err := os.Stat(filename); err == nil {
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = path.Join(l.path, l.lang, dom+"."+ext)
|
filename = filepath.Join(l.path, l.lang, dom+"."+ext)
|
||||||
if _, err := os.Stat(filename); err == nil {
|
if _, err := os.Stat(filename); err == nil {
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(l.lang) > 2 {
|
if len(l.lang) > 2 {
|
||||||
filename = path.Join(l.path, l.lang[:2], dom+"."+ext)
|
filename = filepath.Join(l.path, l.lang[:2], dom+"."+ext)
|
||||||
if _, err := os.Stat(filename); err == nil {
|
if _, err := os.Stat(filename); err == nil {
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
@@ -271,7 +285,7 @@ func (l *Locale) GetNDC(dom, str, plural string, n int, ctx string, vars ...inte
|
|||||||
return Printf(plural, vars...)
|
return Printf(plural, vars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Euses a domain "default" to return the corresponding Translation of a given string.
|
// GetE uses a domain "default" to return the corresponding Translation of a given string.
|
||||||
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
||||||
// The second return value is true iff the string was found.
|
// The second return value is true iff the string was found.
|
||||||
func (l *Locale) GetE(str string, vars ...interface{}) (string, bool) {
|
func (l *Locale) GetE(str string, vars ...interface{}) (string, bool) {
|
||||||
@@ -324,14 +338,14 @@ func (l *Locale) GetNDE(dom, str, plural string, n int, vars ...interface{}) (st
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetC uses a domain "default" to return the corresponding Translation of the given string in the given context.
|
// GetCE uses a domain "default" to return the corresponding Translation of the given string in the given context.
|
||||||
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
||||||
// The second return value is true iff the string was found.
|
// The second return value is true iff the string was found.
|
||||||
func (l *Locale) GetCE(str, ctx string, vars ...interface{}) (string, bool) {
|
func (l *Locale) GetCE(str, ctx string, vars ...interface{}) (string, bool) {
|
||||||
return l.GetDCE(l.GetDomain(), str, ctx, vars...)
|
return l.GetDCE(l.GetDomain(), str, ctx, vars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNC retrieves the (N)th plural form of Translation for the given string in the given context in the "default" domain.
|
// GetNCE retrieves the (N)th plural form of Translation for the given string in the given context in the "default" domain.
|
||||||
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
||||||
// The second return value is true iff the string was found.
|
// The second return value is true iff the string was found.
|
||||||
func (l *Locale) GetNCE(str, plural string, n int, ctx string, vars ...interface{}) (string, bool) {
|
func (l *Locale) GetNCE(str, plural string, n int, ctx string, vars ...interface{}) (string, bool) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package gotext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,14 +62,14 @@ msgstr "More Translation"
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory with simplified language code
|
// Create Locales directory with simplified language code
|
||||||
dirname := path.Join("/tmp", "en", "LC_MESSAGES")
|
dirname := filepath.Join("/tmp", "en", "LC_MESSAGES")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PO content to file
|
// Write PO content to file
|
||||||
filename := path.Join(dirname, "my_domain.po")
|
filename := filepath.Join(dirname, "my_domain.po")
|
||||||
|
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -192,14 +192,14 @@ msgstr "More Translation"
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory with simplified language code
|
// Create Locales directory with simplified language code
|
||||||
dirname := path.Join("/tmp", "en", "LC_MESSAGES")
|
dirname := filepath.Join("/tmp", "en", "LC_MESSAGES")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PO content to file
|
// Write PO content to file
|
||||||
filename := path.Join(dirname, "my_domain.po")
|
filename := filepath.Join(dirname, "my_domain.po")
|
||||||
|
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -425,14 +425,14 @@ msgstr[2] "And this is the second plural form: %s"
|
|||||||
`
|
`
|
||||||
|
|
||||||
// Create Locales directory with simplified language code
|
// Create Locales directory with simplified language code
|
||||||
dirname := path.Join("/tmp", "es")
|
dirname := filepath.Join("/tmp", "es")
|
||||||
err := os.MkdirAll(dirname, os.ModePerm)
|
err := os.MkdirAll(dirname, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't create test directory: %s", err.Error())
|
t.Fatalf("Can't create test directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PO content to file
|
// Write PO content to file
|
||||||
filename := path.Join(dirname, "race.po")
|
filename := filepath.Join(dirname, "race.po")
|
||||||
|
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
6
mo.go
6
mo.go
@@ -17,7 +17,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext/plurals"
|
"git.deineagentur.com/DeineAgenturUG/gotext/plurals"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -41,7 +41,7 @@ Example:
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -502,7 +502,7 @@ func (mo *Mo) GetNCE(str, plural string, n int, ctx string, vars ...interface{})
|
|||||||
if _, ok := mo.contexts[ctx][str]; ok {
|
if _, ok := mo.contexts[ctx][str]; ok {
|
||||||
if fmt, ok := mo.contexts[ctx][str].GetNE(mo.pluralForm(n)); ok {
|
if fmt, ok := mo.contexts[ctx][str].GetNE(mo.pluralForm(n)); ok {
|
||||||
return Printf(fmt, vars...), true
|
return Printf(fmt, vars...), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
po.go
8
po.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext/plurals"
|
"git.deineagentur.com/DeineAgenturUG/gotext/plurals"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -28,7 +28,7 @@ Example:
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leonelquinteros/gotext"
|
"git.deineagentur.com/DeineAgenturUG/gotext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -456,7 +456,7 @@ func (po *Po) GetNC(str, plural string, n int, ctx string, vars ...interface{})
|
|||||||
return Printf(plural, vars...)
|
return Printf(plural, vars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Eretrieves the corresponding Translation for the given string.
|
// GetE retrieves the corresponding Translation for the given string.
|
||||||
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
||||||
// The second return value is true iff the string was found.
|
// The second return value is true iff the string was found.
|
||||||
func (po *Po) GetE(str string, vars ...interface{}) (string, bool) {
|
func (po *Po) GetE(str string, vars ...interface{}) (string, bool) {
|
||||||
@@ -475,7 +475,7 @@ func (po *Po) GetE(str string, vars ...interface{}) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetN Eretrieves the (N)th plural form of Translation for the given string.
|
// GetNE retrieves the (N)th plural form of Translation for the given string.
|
||||||
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
|
||||||
// The second return value is true iff the string was found.
|
// The second return value is true iff the string was found.
|
||||||
func (po *Po) GetNE(str, plural string, n int, vars ...interface{}) (string, bool) {
|
func (po *Po) GetNE(str, plural string, n int, vars ...interface{}) (string, bool) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (t *Translation) GetN(n int) string {
|
|||||||
return t.PluralID
|
return t.PluralID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the string of the translation. The second return value is true
|
// GetE returns the string of the translation. The second return value is true
|
||||||
// iff the string was found.
|
// iff the string was found.
|
||||||
func (t *Translation) GetE() (string, bool) {
|
func (t *Translation) GetE() (string, bool) {
|
||||||
// Look for Translation index 0
|
// Look for Translation index 0
|
||||||
@@ -64,7 +64,7 @@ func (t *Translation) GetE() (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetN returns the string of the plural translation. The second return value
|
// GetNE returns the string of the plural translation. The second return value
|
||||||
// is true iff the string was found.
|
// is true iff the string was found.
|
||||||
func (t *Translation) GetNE(n int) (string, bool) {
|
func (t *Translation) GetNE(n int) (string, bool) {
|
||||||
// Look for Translation index
|
// Look for Translation index
|
||||||
|
|||||||
Reference in New Issue
Block a user