Giter Club home page Giter Club logo

i18n's Introduction

i18n's People

Contributors

dependabot[bot] avatar kataras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

i18n's Issues

[BUG] can't read yaml

Describe the bug

a:
  b:
    - 1
    - 2

Tr("en","a") -> ""
expect

b: 
  - 1
  - 2

To Reproduce
Steps to reproduce the behavior:

  1. [...]

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. ubuntu, windows]

Additional context
Add any other context about the problem here.

[BUG] Inconsistent language matching when loaded as a map

Describe the bug

(*I18n) Tr() is not consistent when producing translated templates. It seems the index of selecting/searching the language is not correct. I use custom language tags e.g. ka-KE (Kamba language).

To Reproduce

Steps to reproduce the behavior:

https://goplay.tools/snippet/55lBTIz199v

Running it multiple times shows that it randomly displays either fr-FR or ka-KE.

Expected behavior

Should only display ka-KE consistently.

Screenshots
N/A

Desktop (please complete the following information):

  • go version go1.20.4 linux/amd64

Upgrade dependencies

It would be nice to upgrade dependencies of the project, because I think it is starting to pull some old versions of other packages.

Example of upgraded code is in my fork commit: 080c239

[BUG] Can't use i18n.SetDefaultLanguage("en-US")

Describe the bug
When using i18n.SetDefaultLanguage("en-US") in the init() function, an error is threw at runtime:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x8d204e]

goroutine 1 [running]:
github.com/kataras/i18n.(*I18n).SetDefault(0x0, {0xa9b1d5?, 0x587?})
	/home/titi/go/pkg/mod/github.com/kataras/[email protected]/i18n.go:173 +0x4e
github.com/kataras/i18n.SetDefaultLanguage(...)
	/home/titi/go/pkg/mod/github.com/kataras/[email protected]/i18n.go:43
main.init.0()
	/home/titi/Dev/api/telegram/friendly-brocolli/main.go:44 +0xa6
exit status 2

To Reproduce
Steps to reproduce the behavior:

  1. Make an init() function
  2. Put i18n.SetDefaultLanguage("en-US") inside

Expected behavior
Shouldn't throw an error but continue the code

Screenshots
image

Desktop (please complete the following information):

  • OS: Debian 12
  • Go: go1.19.8 linux/amd64

Additional context
Add any other context about the problem here.

Issue when using string in translated text

Describe the bug
I'm trying a basic implementation using english and spanish translations files but when trying to do this:

func main() {
	enText := i18n.Tr("en", "textWithLink", "A123456") 

	fmt.Println(enText)
}

and in my locales/en-US I have my example json like:

{ "textWithLink": "Lorem ipsum [This is my link](https://domain.example.com/form/%s/create)" }

Then I'm getting on my result translation: Lorem ipsum [This is my link](https://domain.example.com/form/[A123456]/create)

string passed as parameter is printing between [ ]

Why is happening this?

[BUG] Language chosen as "ga" when AcceptLang only has English

Describe the bug

Automatic language detection recently got broken in my project.

To Reproduce
Steps to reproduce the behavior:

  1. Browser sends Accept-Language: en-GB,en;q=0.5
  2. i18n chooses to display ga

Expected behavior
Since both en-GB and en are supplied, and en is available as a folder (and not missing any translations), en should be chosen in my eyes.
ga is missing some strings, so English is used for them instead.

Desktop (please complete the following information):

  • OS: Debian GNU/Linux 11
  • Go version: go1.19.3

Additional context
Add any other context about the problem here.

file structure of locales
locales/
locales/nl
locales/nl/base.yaml
locales/da
locales/da/base.yaml
locales/en
locales/en/other-component.yaml
locales/en/base.yaml
locales/ga
locales/ga/base.yaml
locales/pl
locales/pl/base.yaml
locales/fr
locales/fr/base.yaml
locales/de
locales/de/other-component.yaml
locales/de/base.yaml
Further notes
  • I cannot find any other indicators for languages. There is no "lang" cookie. There is no request GET parameter. Hostname is "localhost".
  • code excerpt (registering API method, I did no further interaction with your library AFAICS)
    locale := i18n.GetLocale(r)
    templateData["tr"] = locale.GetMessage

It works in another browser where I send Accept-Language: de,en-US;q=0.7,en;q=0.3 (de is chosen / displayed).

Appreciate your help :) Thank you!

Example using Go Embed.FS

Thanks for this great library, I put together an example of how to use it with Go 1.16 embed.FS:

package locales

import (
	"embed"
)

//go:embed */*.yml
var translations embed.FS

func I18n() (*i18n.I18n, error) {
	// assuming embedded files at ./en/*.yml
	return i18n.New(i18n.Assets(translationNames, translations.ReadFile), "en")
}

func translationNames() (filenames []string) {
	fs.WalkDir(translations, ".", func(path string, d fs.DirEntry, err error) error {
		if err != nil {
			return err
		}

		if d.IsDir() {
			return nil
		}

		filenames = append(filenames, path)
		return nil
	})

	return filenames
}

[BUG] es-ES: unexpected type of []interface {} as value

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. [...]

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. ubuntu, windows]

Additional context
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.