First implementation of CLI tool

This commit is contained in:
Leonel Quinteros
2019-02-15 15:20:42 -03:00
parent ff3209d159
commit 0e382cfe26
8 changed files with 531 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:23
#. gotext.Get
msgid "My text on 'domain-name' domain"
msgstr ""
#: fixtures/main.go:38
#. l.GetN
msgid "Singular"
msgid_plural "Plural"
msgstr[0] ""
msgstr[1] ""
#: fixtures/main.go:40
#. l.GetN
msgid "SingularVar"
msgid_plural "PluralVar"
msgstr[0] ""
msgstr[1] ""

View File

@@ -0,0 +1,15 @@
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:42
#. l.GetDC
msgctxt "ctx"
msgid "string"
msgstr ""

View File

@@ -0,0 +1,14 @@
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:26
#. gotext.GetD
msgid "Another text on a different domain"
msgstr ""

View File

@@ -0,0 +1,22 @@
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:35
#. l.GetD
msgid "Translate this"
msgstr ""
#: fixtures/main.go:43
#. l.GetNDC
msgctxt "NDC-CTX"
msgid "ndc"
msgid_plural "ndcs"
msgstr[0] ""
msgstr[1] ""

View File

@@ -0,0 +1,47 @@
package main
import (
"fmt"
"github.com/leonelquinteros/gotext"
)
// Fake object with methods similar to gotext
type Fake struct {
}
// Get by id
func (f Fake) Get(id int) int {
return 42
}
func main() {
// Configure package
gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name")
// Translate text from default domain
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
// Translate text from a different domain without reconfigure
fmt.Println(gotext.GetD("domain2", "Another text on a different domain"))
// Create Locale with library path and language code
l := gotext.NewLocale("/path/to/locales/root/dir", "es_UY")
// Load domain '/path/to/locales/root/dir/es_UY/default.po'
l.AddDomain("default")
// Translate text from domain
fmt.Println(l.GetD("translations", "Translate this"))
// Get plural translations
l.GetN("Singular", "Plural", 4)
num := 17
l.GetN("SingularVar", "PluralVar", num)
l.GetDC("domain", "string", "ctx")
l.GetNDC("translations", "ndc", "ndcs", 7, "NDC-CTX")
f := Fake{}
f.Get(3)
}