Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for complex added #19

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Spreak ![Test status](https://github.com/vorlif/spreak/workflows/Test/badge.svg) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![PkgGoDev](https://pkg.go.dev/badge/github.com/vorlif/spreak)](https://pkg.go.dev/github.com/vorlif/spreak) [![Go Report Card](https://goreportcard.com/badge/github.com/vorlif/spreak)](https://goreportcard.com/report/github.com/vorlif/spreak) [![codecov](https://codecov.io/gh/vorlif/spreak/branch/main/graph/badge.svg?token=N1O0ZE1OFW)](https://codecov.io/gh/vorlif/spreak) ![MinVersion](https://img.shields.io/badge/Go-1.17+-blue)

Flexible translation and humanization library for Go, based on the concepts behind gettext. Requires Go 1.16+.
Flexible translation and humanization library for Go, based on the concepts behind gettext. Requires Go 1.17+.

### Why another library?

Expand All @@ -21,15 +21,15 @@ I wanted to solve these problems for myself, and so spreak was born.
(with **support for templates**)
* [Support](https://pkg.go.dev/github.com/vorlif/spreak#hdr-Plurals)
for [gettext](https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html)
and [CLDR v41](https://cldr.unicode.org/index/cldr-spec/plural-rules) plural rules.
and [CLDR v42](https://cldr.unicode.org/index/cldr-spec/plural-rules) plural rules.
* Support of bilingual and monolingual formats

### Usage

Using spreak is easy. First, use go get to install the latest version of the library.

```shell
go get -u github.com/vorlif/spreak@latest
go get -u github.com/vorlif/spreak
```

After that, spreak offers you a comprehensive interface to load and query your translations.
Expand All @@ -50,6 +50,7 @@ func main() {
// Create a bundle that loads the translations for the required languages.
// Typically, you only need one bundle in an application.
bundle, err := spreak.NewBundle(
// Set the language used in the program code/templates
spreak.WithSourceLanguage(language.English),
// Set the path from which the translations should be loaded
spreak.WithDomainPath(spreak.NoDomain, "./locale"),
Expand All @@ -60,7 +61,7 @@ func main() {
panic(err)
}

// Create a Localiser to select the language to translate.
// Create a Localizer to select the language to translate.
t := spreak.NewLocalizer(bundle, language.Spanish)

// Translate
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module example.com/spreak

go 1.16
go 1.17

require (
github.com/Xuanwo/go-locale v1.1.0
Expand Down
4 changes: 4 additions & 0 deletions internal/util/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func ToNumber(n interface{}) (float64, error) {
return float64(nt), nil
case float64:
return nt, nil
case complex64:
return float64(real(nt)), nil
case complex128:
return real(nt), nil
case string:
res, err := strconv.ParseFloat(nt, 64)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
// A Localizer holds the catalogs of all domains for a language and provides an interface for their use.
// It has a default domain, which can differ from the bundle default domain and is used
// if no domain is specified for translations.
// A number of supported languages can be specified at creation time
// A number of supported languages can be specified at creation time,
// where the language matcher of the bundle decides which language fits best.
// For this language the Localizer then offers the possibility to translate.
// If no language fits, the fallback language is used.
// If no fallback language is specified, the source language is used.
// For web applications, a Localizer can be created for each request, which can be disposed of at the end of the request.
type Localizer struct {
bundle *Bundle
locale *locale
Expand Down