Skip to content

Commit

Permalink
Basic support for complex added (#19)
Browse files Browse the repository at this point in the history
* Add complex support

* Update readme
  • Loading branch information
vorlif committed Feb 19, 2023
1 parent c65a6fb commit 85040f3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
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

0 comments on commit 85040f3

Please sign in to comment.