build(deps): bump github.com/leonelquinteros/gotext from 1.7.1 to 1.7.2

Bumps [github.com/leonelquinteros/gotext](https://github.com/leonelquinteros/gotext) from 1.7.1 to 1.7.2.
- [Release notes](https://github.com/leonelquinteros/gotext/releases)
- [Commits](https://github.com/leonelquinteros/gotext/compare/v1.7.1...v1.7.2)

---
updated-dependencies:
- dependency-name: github.com/leonelquinteros/gotext
  dependency-version: 1.7.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2025-06-02 16:16:12 +00:00
committed by GitHub
parent 89feb86062
commit d703d5030a
15 changed files with 209 additions and 130 deletions

2
go.mod
View File

@@ -49,7 +49,7 @@ require (
github.com/jinzhu/now v1.1.5
github.com/justinas/alice v1.2.0
github.com/kovidgoyal/imaging v1.6.4
github.com/leonelquinteros/gotext v1.7.1
github.com/leonelquinteros/gotext v1.7.2
github.com/libregraph/idm v0.5.0
github.com/libregraph/lico v0.66.0
github.com/mitchellh/mapstructure v1.5.0

4
go.sum
View File

@@ -716,8 +716,8 @@ github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvf
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/leonelquinteros/gotext v1.7.1 h1:/JNPeE3lY5JeVYv2+KBpz39994W3W9fmZCGq3eO9Ri8=
github.com/leonelquinteros/gotext v1.7.1/go.mod h1:I0WoFDn9u2D3VbPnnDPT8mzZu0iSXG8iih+AH2fHHqg=
github.com/leonelquinteros/gotext v1.7.2 h1:bDPndU8nt+/kRo1m4l/1OXiiy2v7Z7dfPQ9+YP7G1Mc=
github.com/leonelquinteros/gotext v1.7.2/go.mod h1:9/haCkm5P7Jay1sxKDGJ5WIg4zkz8oZKw4ekNpALob8=
github.com/libregraph/idm v0.5.0 h1:tDMwKbAOZzdeDYMxVlY5PbSqRKO7dbAW9KT42A51WSk=
github.com/libregraph/idm v0.5.0/go.mod h1:BGMwIQ/6orJSPVzJ1x6kgG2JyG9GY05YFmbsnaD80k0=
github.com/libregraph/lico v0.66.0 h1:7T6fD1YF0Ep9n0g4KN6dvWHTlDC3awrQpgsP5GdYCF4=

View File

@@ -1,9 +1,7 @@
# Eclipse shit
# Local IDE
.project
.settings
.buildpath
# golang jetbrains shit
.idea
# Compiled Object files, Static and Dynamic libs (Shared Objects)
@@ -14,6 +12,7 @@
# Folders
_obj
_test
cli/xgotext/fixtures/out
# Architecture specific extensions/prefixes
*.[568vq]
@@ -30,3 +29,4 @@ _testmain.go
*.exe
*.test
*.prof
*.DS_Store

View File

@@ -1,6 +1,6 @@
[![GitHub release](https://img.shields.io/github/release/leonelquinteros/gotext.svg)](https://github.com/leonelquinteros/gotext)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
![Gotext build](https://github.com/leonelquinteros/gotext/workflows/Gotext%20build/badge.svg?branch=master)
![Gotext build](https://github.com/leonelquinteros/gotext/workflows/Gotext%20build/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/leonelquinteros/gotext)](https://goreportcard.com/report/github.com/leonelquinteros/gotext)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/leonelquinteros/gotext)](https://pkg.go.dev/github.com/leonelquinteros/gotext)
@@ -35,7 +35,7 @@
# Documentation
Refer to the Godoc package documentation at (https://godoc.org/github.com/leonelquinteros/gotext)
Refer to package documentation at (https://pkg.go.dev/github.com/leonelquinteros/gotext)
# Installation
@@ -49,90 +49,6 @@ go get github.com/leonelquinteros/gotext
- No need for environment variables. Some naming conventions are applied but not needed.
## Version vendoring
Stable releases use [semantic versioning](http://semver.org/spec/v2.0.0.html) tagging on this repository.
You can rely on this to use your preferred vendoring tool or to manually retrieve the corresponding release tag from the GitHub repository.
**NOTE:** v1.5.0 contains a breaking change on how `Po` objects are initialised, see (https://github.com/leonelquinteros/gotext/issues/56)
### 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.
i.e.
```
require (
github.com/leonelquinteros/gotext v1.4.0
)
```
### Vendoring with [gopkg.in](http://labix.org/gopkg.in)
[http://gopkg.in/leonelquinteros/gotext.v1](http://gopkg.in/leonelquinteros/gotext.v1)
To get the latest v1 package stable release, execute:
```
go get gopkg.in/leonelquinteros/gotext.v1
```
Import as
```go
import "gopkg.in/leonelquinteros/gotext.v1"
```
Refer to it as gotext.
# Locales directories structure
The package will assume a directories structure starting with a base path that will be provided to the package configuration
or to object constructors depending on the use, but either will use the same convention to lookup inside the base path.
Inside the base directory where will be the language directories named using the language and country 2-letter codes (en_US, es_AR, ...).
All package functions can lookup after the simplified version for each language in case the full code isn't present but the more general language code exists.
So if the language set is `en_UK`, but there is no directory named after that code and there is a directory named `en`,
all package functions will be able to resolve this generalization and provide translations for the more general library.
The language codes are assumed to be [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes (2-letter codes).
That said, most functions will work with any coding standard as long the directory name matches the language code set on the configuration.
Then, there can be a `LC_MESSAGES` containing all PO files or the PO files themselves.
A library directory structure can look like:
```
/path/to/locales
/path/to/locales/en_US
/path/to/locales/en_US/LC_MESSAGES
/path/to/locales/en_US/LC_MESSAGES/default.po
/path/to/locales/en_US/LC_MESSAGES/extras.po
/path/to/locales/en_UK
/path/to/locales/en_UK/LC_MESSAGES
/path/to/locales/en_UK/LC_MESSAGES/default.po
/path/to/locales/en_UK/LC_MESSAGES/extras.po
/path/to/locales/en_AU
/path/to/locales/en_AU/LC_MESSAGES
/path/to/locales/en_AU/LC_MESSAGES/default.po
/path/to/locales/en_AU/LC_MESSAGES/extras.po
/path/to/locales/es
/path/to/locales/es/default.po
/path/to/locales/es/extras.po
/path/to/locales/es_ES
/path/to/locales/es_ES/default.po
/path/to/locales/es_ES/extras.po
/path/to/locales/fr
/path/to/locales/fr/default.po
/path/to/locales/fr/extras.po
```
And so on...
# Usage examples
## Using package for single language/domain settings
@@ -296,6 +212,50 @@ msgstr[1] "This one is the plural: %s"
```
# Locales directories structure
The package will assume a directories structure starting with a base path that will be provided to the package configuration
or to object constructors depending on the use, but either will use the same convention to lookup inside the base path.
Inside the base directory where will be the language directories named using the language and country 2-letter codes (en_US, es_AR, ...).
All package functions can lookup after the simplified version for each language in case the full code isn't present but the more general language code exists.
So if the language set is `en_UK`, but there is no directory named after that code and there is a directory named `en`,
all package functions will be able to resolve this generalization and provide translations for the more general library.
The language codes are assumed to be [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes (2-letter codes).
That said, most functions will work with any coding standard as long the directory name matches the language code set on the configuration.
Then, there can be a `LC_MESSAGES` containing all PO files or the PO files themselves.
A library directory structure can look like:
```
/path/to/locales
/path/to/locales/en_US
/path/to/locales/en_US/LC_MESSAGES
/path/to/locales/en_US/LC_MESSAGES/default.po
/path/to/locales/en_US/LC_MESSAGES/extras.po
/path/to/locales/en_UK
/path/to/locales/en_UK/LC_MESSAGES
/path/to/locales/en_UK/LC_MESSAGES/default.po
/path/to/locales/en_UK/LC_MESSAGES/extras.po
/path/to/locales/en_AU
/path/to/locales/en_AU/LC_MESSAGES
/path/to/locales/en_AU/LC_MESSAGES/default.po
/path/to/locales/en_AU/LC_MESSAGES/extras.po
/path/to/locales/es
/path/to/locales/es/default.po
/path/to/locales/es/extras.po
/path/to/locales/es_ES
/path/to/locales/es_ES/default.po
/path/to/locales/es_ES/extras.po
/path/to/locales/fr
/path/to/locales/fr/default.po
/path/to/locales/fr/extras.po
```
And so on...
# Contribute
- Please, contribute.

View File

@@ -49,15 +49,20 @@ type Domain struct {
customPluralResolver func(int) int
}
// Preserve MIMEHeader behaviour, without the canonicalisation
// HeaderMap preserves MIMEHeader behaviour, without the canonicalisation
type HeaderMap map[string][]string
// Add key/value pair to HeaderMap
func (m HeaderMap) Add(key, value string) {
m[key] = append(m[key], value)
}
// Del key from HeaderMap
func (m HeaderMap) Del(key string) {
delete(m, key)
}
// Get value for key from HeaderMap
func (m HeaderMap) Get(key string) string {
if m == nil {
return ""
@@ -68,9 +73,13 @@ func (m HeaderMap) Get(key string) string {
}
return v[0]
}
// Set key/value pair in HeaderMap
func (m HeaderMap) Set(key, value string) {
m[key] = []string{value}
}
// Values returns all values for a given key from HeaderMap
func (m HeaderMap) Values(key string) []string {
if m == nil {
return nil
@@ -78,6 +87,7 @@ func (m HeaderMap) Values(key string) []string {
return m[key]
}
// NewDomain creates a new Domain instance
func NewDomain() *Domain {
domain := new(Domain)
@@ -90,6 +100,7 @@ func NewDomain() *Domain {
return domain
}
// SetPluralResolver sets a custom plural resolver function
func (do *Domain) SetPluralResolver(f func(int) int) {
do.customPluralResolver = f
}
@@ -182,8 +193,8 @@ func (do *Domain) parseHeaders() {
}
}
// Drops any translations stored that have not been Set*() since 'po'
// was initialised
// DropStaleTranslations drops any translations stored that have not been Set*()
// since 'po' was initialised
func (do *Domain) DropStaleTranslations() {
do.trMutex.Lock()
do.pluralMutex.Lock()
@@ -208,7 +219,7 @@ func (do *Domain) DropStaleTranslations() {
}
}
// Set source references for a given translation
// SetRefs set source references for a given translation
func (do *Domain) SetRefs(str string, refs []string) {
do.trMutex.Lock()
do.pluralMutex.Lock()
@@ -225,7 +236,7 @@ func (do *Domain) SetRefs(str string, refs []string) {
}
}
// Get source references for a given translation
// GetRefs get source references for a given translation
func (do *Domain) GetRefs(str string) []string {
// Sync read
do.trMutex.RLock()
@@ -256,6 +267,7 @@ func (do *Domain) Set(id, str string) {
}
}
// Get retrieves the Translation for the given string.
func (do *Domain) Get(str string, vars ...interface{}) string {
// Sync read
do.trMutex.RLock()
@@ -263,14 +275,16 @@ func (do *Domain) Get(str string, vars ...interface{}) string {
if do.translations != nil {
if _, ok := do.translations[str]; ok {
return Printf(do.translations[str].Get(), vars...)
return FormatString(do.translations[str].Get(), vars...)
}
}
// Return the same we received by default
return Printf(str, vars...)
return FormatString(str, vars...)
}
// Append retrieves the Translation for the given string.
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
func (do *Domain) Append(b []byte, str string, vars ...interface{}) []byte {
// Sync read
do.trMutex.RLock()
@@ -286,7 +300,7 @@ func (do *Domain) Append(b []byte, str string, vars ...interface{}) []byte {
return Appendf(b, str, vars...)
}
// Set the (N)th plural form for the given string
// SetN sets the (N)th plural form for the given string
func (do *Domain) SetN(id, plural string, n int, str string) {
// Get plural form _before_ lock down
pluralForm := do.pluralForm(n)
@@ -316,18 +330,18 @@ func (do *Domain) GetN(str, plural string, n int, vars ...interface{}) string {
if do.translations != nil {
if _, ok := do.translations[str]; ok {
return Printf(do.translations[str].GetN(do.pluralForm(n)), vars...)
return FormatString(do.translations[str].GetN(do.pluralForm(n)), vars...)
}
}
// Parse plural forms to distinguish between plural and singular
if do.pluralForm(n) == 0 {
return Printf(str, vars...)
return FormatString(str, vars...)
}
return Printf(plural, vars...)
return FormatString(plural, vars...)
}
// GetN retrieves the (N)th plural form of Translation for the given string.
// AppendN adds 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.
func (do *Domain) AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte {
// Sync read
@@ -347,7 +361,7 @@ func (do *Domain) AppendN(b []byte, str, plural string, n int, vars ...interface
return Appendf(b, plural, vars...)
}
// Set the translation for the given string in the given context
// SetC sets the translation for the given string in the given context
func (do *Domain) SetC(id, ctx, str string) {
do.trMutex.Lock()
do.pluralMutex.Lock()
@@ -383,14 +397,14 @@ func (do *Domain) GetC(str, ctx string, vars ...interface{}) string {
if _, ok := do.contextTranslations[ctx]; ok {
if do.contextTranslations[ctx] != nil {
if _, ok := do.contextTranslations[ctx][str]; ok {
return Printf(do.contextTranslations[ctx][str].Get(), vars...)
return FormatString(do.contextTranslations[ctx][str].Get(), vars...)
}
}
}
}
// Return the string we received by default
return Printf(str, vars...)
return FormatString(str, vars...)
}
// AppendC retrieves the corresponding Translation for a given string in the given context.
@@ -413,7 +427,7 @@ func (do *Domain) AppendC(b []byte, str, ctx string, vars ...interface{}) []byte
return Appendf(b, str, vars...)
}
// Set the (N)th plural form for the given string in the given context
// SetNC sets the (N)th plural form for the given string in the given context
func (do *Domain) SetNC(id, plural, ctx string, n int, str string) {
// Get plural form _before_ lock down
pluralForm := do.pluralForm(n)
@@ -452,16 +466,16 @@ func (do *Domain) GetNC(str, plural string, n int, ctx string, vars ...interface
if _, ok := do.contextTranslations[ctx]; ok {
if do.contextTranslations[ctx] != nil {
if _, ok := do.contextTranslations[ctx][str]; ok {
return Printf(do.contextTranslations[ctx][str].GetN(do.pluralForm(n)), vars...)
return FormatString(do.contextTranslations[ctx][str].GetN(do.pluralForm(n)), vars...)
}
}
}
}
if n == 1 {
return Printf(str, vars...)
return FormatString(str, vars...)
}
return Printf(plural, vars...)
return FormatString(plural, vars...)
}
// AppendNC retrieves the (N)th plural form of Translation for the given string in the given context.
@@ -555,6 +569,40 @@ func (do *Domain) GetTranslations() map[string]*Translation {
return all
}
// GetCtxTranslations returns a copy of every translation in the domain with context
func (do *Domain) GetCtxTranslations() map[string]map[string]*Translation {
all := make(map[string]map[string]*Translation, len(do.contextTranslations))
do.trMutex.RLock()
defer do.trMutex.RUnlock()
for ctx, translations := range do.contextTranslations {
for msgID, trans := range translations {
newTrans := NewTranslation()
newTrans.ID = trans.ID
newTrans.PluralID = trans.PluralID
newTrans.dirty = trans.dirty
if len(trans.Refs) > 0 {
newTrans.Refs = make([]string, len(trans.Refs))
copy(newTrans.Refs, trans.Refs)
}
for k, v := range trans.Trs {
newTrans.Trs[k] = v
}
if all[ctx] == nil {
all[ctx] = make(map[string]*Translation)
}
all[ctx][msgID] = newTrans
}
}
return all
}
// SourceReference is a struct to hold source reference information
type SourceReference struct {
path string
line int
@@ -603,7 +651,7 @@ func (do *Domain) MarshalText() ([]byte, error) {
headerKeys := make([]string, 0, len(do.Headers))
for k, _ := range do.Headers {
for k := range do.Headers {
headerKeys = append(headerKeys, k)
}
@@ -736,6 +784,7 @@ func (do *Domain) MarshalText() ([]byte, error) {
return buf.Bytes(), nil
}
// EscapeSpecialCharacters escapes special characters in a string
func EscapeSpecialCharacters(s string) string {
s = regexp.MustCompile(`([^\\])(")`).ReplaceAllString(s, "$1\\\"") // Escape non-escaped double quotation marks

View File

@@ -46,6 +46,7 @@ type config struct {
var globalConfig *config
// FallbackLocale is the default language to be used when no language is set.
var FallbackLocale = "en_US"
func init() {
@@ -167,6 +168,7 @@ func SetLibrary(lib string) {
loadLocales(true)
}
// GetLocales returns the locales that have been set for the package configuration.
func GetLocales() []*Locale {
globalConfig.RLock()
defer globalConfig.RUnlock()

View File

@@ -28,8 +28,8 @@ func SimplifiedLocale(lang string) string {
return strings.TrimSpace(lang)
}
// Printf applies text formatting only when needed to parse variables.
func Printf(str string, vars ...interface{}) string {
// FormatString applies text formatting only when needed to parse variables.
func FormatString(str string, vars ...interface{}) string {
if len(vars) > 0 {
return fmt.Sprintf(str, vars...)
}

View File

@@ -263,7 +263,7 @@ func (l *Locale) GetD(dom, str string, vars ...interface{}) string {
}
}
return Printf(str, vars...)
return FormatString(str, vars...)
}
// GetND retrieves the (N)th plural form of Translation in the given domain for the given string.
@@ -283,9 +283,9 @@ func (l *Locale) GetND(dom, str, plural string, n int, vars ...interface{}) stri
// Use western default rule (plural > 1) to handle missing domain default result.
if n == 1 {
return Printf(str, vars...)
return FormatString(str, vars...)
}
return Printf(plural, vars...)
return FormatString(plural, vars...)
}
// GetC uses a domain "default" to return the corresponding Translation of the given string in the given context.
@@ -315,7 +315,7 @@ func (l *Locale) GetDC(dom, str, ctx string, vars ...interface{}) string {
}
}
return Printf(str, vars...)
return FormatString(str, vars...)
}
// GetNDC retrieves the (N)th plural form of Translation in the given domain for the given string in the given context.
@@ -335,9 +335,9 @@ func (l *Locale) GetNDC(dom, str, plural string, n int, ctx string, vars ...inte
// Use western default rule (plural > 1) to handle missing domain default result.
if n == 1 {
return Printf(str, vars...)
return FormatString(str, vars...)
}
return Printf(plural, vars...)
return FormatString(plural, vars...)
}
// GetTranslations returns a copy of all translations in all domains of this locale. It does not support contexts.

View File

@@ -70,60 +70,82 @@ func NewMoFS(filesystem fs.FS) *Mo {
return mo
}
// GetDomain returns the domain object
func (mo *Mo) GetDomain() *Domain {
return mo.domain
}
// all of the Get functions are for convenience and aid in backwards compatibility
// Get returns the translation for the given string
func (mo *Mo) Get(str string, vars ...interface{}) string {
return mo.domain.Get(str, vars...)
}
// Append a translation string into the domain
func (mo *Mo) Append(b []byte, str string, vars ...interface{}) []byte {
return mo.domain.Append(b, str, vars...)
}
// GetN returns the translation for the given string and plural form
func (mo *Mo) GetN(str, plural string, n int, vars ...interface{}) string {
return mo.domain.GetN(str, plural, n, vars...)
}
// AppendN appends a translation string for the given plural form into the domain
func (mo *Mo) AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte {
return mo.domain.AppendN(b, str, plural, n, vars...)
}
// GetC returns the translation for the given string and context
func (mo *Mo) GetC(str, ctx string, vars ...interface{}) string {
return mo.domain.GetC(str, ctx, vars...)
}
// AppendC appends a translation string for the given context into the domain
func (mo *Mo) AppendC(b []byte, str, ctx string, vars ...interface{}) []byte {
return mo.domain.AppendC(b, str, ctx, vars...)
}
// GetNC returns the translation for the given string, plural form and context
func (mo *Mo) GetNC(str, plural string, n int, ctx string, vars ...interface{}) string {
return mo.domain.GetNC(str, plural, n, ctx, vars...)
}
// AppendNC appends a translation string for the given plural form and context into the domain
func (mo *Mo) AppendNC(b []byte, str, plural string, n int, ctx string, vars ...interface{}) []byte {
return mo.domain.AppendNC(b, str, plural, n, ctx, vars...)
}
// IsTranslated checks if the given string is translated
func (mo *Mo) IsTranslated(str string) bool {
return mo.domain.IsTranslated(str)
}
// IsTranslatedN checks if the given string is translated with plural form
func (mo *Mo) IsTranslatedN(str string, n int) bool {
return mo.domain.IsTranslatedN(str, n)
}
// IsTranslatedC checks if the given string is translated with context
func (mo *Mo) IsTranslatedC(str, ctx string) bool {
return mo.domain.IsTranslatedC(str, ctx)
}
// IsTranslatedNC checks if the given string is translated with plural form and context
func (mo *Mo) IsTranslatedNC(str string, n int, ctx string) bool {
return mo.domain.IsTranslatedNC(str, n, ctx)
}
// MarshalBinary marshals the Mo object into a binary format
func (mo *Mo) MarshalBinary() ([]byte, error) {
return mo.domain.MarshalBinary()
}
// UnmarshalBinary unmarshals the Mo object from a binary format
func (mo *Mo) UnmarshalBinary(data []byte) error {
return mo.domain.UnmarshalBinary(data)
}
// ParseFile loads the translations specified in the provided file, in the GNU gettext .mo format
func (mo *Mo) ParseFile(f string) {
data, err := getFileData(f, mo.fs)
if err != nil {

View File

@@ -125,10 +125,10 @@ func compileMod(tokens []string) (math math, err error) {
return math, err
}
if len(split.Left) != 1 || split.Left[0] != "n" {
return math, errors.New("Modulus operation requires 'n' as left operand")
return math, errors.New("modulus operation requires 'n' as left operand")
}
if len(split.Right) != 1 {
return math, errors.New("Modulus operation requires simple integer as right operand")
return math, errors.New("modulus operation requires simple integer as right operand")
}
i, err := parseUint32(split.Right[0])
if err != nil {
@@ -329,7 +329,7 @@ func scan(s string) <-chan match {
func split(s string) <-chan string {
ch := make(chan string)
go func() {
s = strings.Replace(s, " ", "", -1)
s = strings.ReplaceAll(s, " ", "")
if !strings.Contains(s, "(") {
ch <- s
} else {

View File

@@ -30,9 +30,9 @@ type gt struct {
func (e gt) test(n uint32) bool {
if e.flipped {
return e.value > n
} else {
return n > e.value
}
return n > e.value
}
type lt struct {

View File

@@ -69,91 +69,130 @@ func NewPoFS(filesystem fs.FS) *Po {
return po
}
// GetDomain returns the domain object
func (po *Po) GetDomain() *Domain {
return po.domain
}
// Convenience interfaces
// ---------------------------------------------------------------
// DropStaleTranslations removes all translations that are not referenced in the current domain
func (po *Po) DropStaleTranslations() {
po.domain.DropStaleTranslations()
}
// SetRefs sets the references for a given translation
func (po *Po) SetRefs(str string, refs []string) {
po.domain.SetRefs(str, refs)
}
// GetRefs returns the references for a given translation
func (po *Po) GetRefs(str string) []string {
return po.domain.GetRefs(str)
}
// SetPluralResolver sets the plural resolver function
func (po *Po) SetPluralResolver(f func(int) int) {
po.domain.customPluralResolver = f
}
// Set translation
func (po *Po) Set(id, str string) {
po.domain.Set(id, str)
}
// Get translation
func (po *Po) Get(str string, vars ...interface{}) string {
return po.domain.Get(str, vars...)
}
// Append translation
func (po *Po) Append(b []byte, str string, vars ...interface{}) []byte {
return po.domain.Append(b, str, vars...)
}
// SetN sets the plural translation
func (po *Po) SetN(id, plural string, n int, str string) {
po.domain.SetN(id, plural, n, str)
}
// GetN gets the plural translation
func (po *Po) GetN(str, plural string, n int, vars ...interface{}) string {
return po.domain.GetN(str, plural, n, vars...)
}
// AppendN appends the plural translation
func (po *Po) AppendN(b []byte, str, plural string, n int, vars ...interface{}) []byte {
return po.domain.AppendN(b, str, plural, n, vars...)
}
// SetC sets the translation for a given context
func (po *Po) SetC(id, ctx, str string) {
po.domain.SetC(id, ctx, str)
}
// GetC gets the translation for a given context
func (po *Po) GetC(str, ctx string, vars ...interface{}) string {
return po.domain.GetC(str, ctx, vars...)
}
// AppendC appends the translation for a given context
func (po *Po) AppendC(b []byte, str, ctx string, vars ...interface{}) []byte {
return po.domain.AppendC(b, str, ctx, vars...)
}
// SetNC sets the plural translation for a given context
func (po *Po) SetNC(id, plural, ctx string, n int, str string) {
po.domain.SetNC(id, plural, ctx, n, str)
}
// GetNC gets the plural translation for a given context
func (po *Po) GetNC(str, plural string, n int, ctx string, vars ...interface{}) string {
return po.domain.GetNC(str, plural, n, ctx, vars...)
}
// AppendNC appends the plural translation for a given context
func (po *Po) AppendNC(b []byte, str, plural string, n int, ctx string, vars ...interface{}) []byte {
return po.domain.AppendNC(b, str, plural, n, ctx, vars...)
}
// IsTranslated checks if the given string is translated
func (po *Po) IsTranslated(str string) bool {
return po.domain.IsTranslated(str)
}
// IsTranslatedN checks if the given string is translated with plural form
func (po *Po) IsTranslatedN(str string, n int) bool {
return po.domain.IsTranslatedN(str, n)
}
// IsTranslatedC checks if the given string is translated with context
func (po *Po) IsTranslatedC(str, ctx string) bool {
return po.domain.IsTranslatedC(str, ctx)
}
// IsTranslatedNC checks if the given string is translated with plural form and context
func (po *Po) IsTranslatedNC(str string, n int, ctx string) bool {
return po.domain.IsTranslatedNC(str, n, ctx)
}
// MarshalText marshals the Po object to text
func (po *Po) MarshalText() ([]byte, error) {
return po.domain.MarshalText()
}
// MarshalBinary marshals the Po object to binary
func (po *Po) MarshalBinary() ([]byte, error) {
return po.domain.MarshalBinary()
}
// UnmarshalBinary unmarshals the Po object from binary
func (po *Po) UnmarshalBinary(data []byte) error {
return po.domain.UnmarshalBinary(data)
}
// ParseFile loads the translations from a file
func (po *Po) ParseFile(f string) {
data, err := getFileData(f, po.fs)
if err != nil {

View File

@@ -22,6 +22,7 @@ func NewTranslation() *Translation {
}
}
// NewTranslationWithRefs returns the Translation object and initialized it with references.
func NewTranslationWithRefs(refs []string) *Translation {
return &Translation{
Trs: make(map[int]string),
@@ -29,15 +30,18 @@ func NewTranslationWithRefs(refs []string) *Translation {
}
}
// IsStale returns whether the translation is stale or not
func (t *Translation) IsStale() bool {
return t.dirty == false
return !t.dirty
}
// SetRefs sets the references of the translation
func (t *Translation) SetRefs(refs []string) {
t.Refs = refs
t.dirty = true
}
// Set sets the string of the translation
func (t *Translation) Set(str string) {
t.Trs[0] = str
t.dirty = true
@@ -56,6 +60,7 @@ func (t *Translation) Get() string {
return t.ID
}
// SetN sets the string of the plural translation
func (t *Translation) SetN(n int, str string) {
t.Trs[n] = str
t.dirty = true

View File

@@ -8,7 +8,6 @@ package gotext
import (
"errors"
"io/fs"
"io/ioutil"
"os"
)
@@ -27,6 +26,9 @@ type Translator interface {
UnmarshalBinary([]byte) error
GetDomain() *Domain
}
// AppendTranslator interface is used by Locale and Po objects.
// It contains all methods needed to parse translation sources and to append entries to the object.
type AppendTranslator interface {
Translator
Append(b []byte, str string, vars ...interface{}) []byte
@@ -90,5 +92,5 @@ func getFileData(f string, filesystem fs.FS) ([]byte, error) {
return nil, errors.New("cannot parse a directory")
}
return ioutil.ReadFile(f)
return os.ReadFile(f)
}

2
vendor/modules.txt vendored
View File

@@ -854,7 +854,7 @@ github.com/kovidgoyal/imaging
## explicit; go 1.18
github.com/leodido/go-urn
github.com/leodido/go-urn/scim/schema
# github.com/leonelquinteros/gotext v1.7.1
# github.com/leonelquinteros/gotext v1.7.2
## explicit; go 1.23.5
github.com/leonelquinteros/gotext
github.com/leonelquinteros/gotext/plurals