GithubHelp home page GithubHelp logo

gobuffalo / mw-i18n Goto Github PK

View Code? Open in Web Editor NEW
6.0 8.0 3.0 353 KB

Buffalo i18n Middleware

License: MIT License

Go 97.71% HTML 2.29%
go golang gobuffalo middleware i18n internationalization translation

mw-i18n's Introduction

i18n middleware

NOTE: v2.0.3 will be the last version of this module and it will be deprecated. Use https://github.com/gobuffalo/middleware instead.

This Buffalo middleware enables i18n features in your app:

  • User language detection from configurable sources
  • Translation helper using locales bundles from github.com/nicksnyder/go-i18n
  • Localized views

Installation

This middleware is setup by default on a new Buffalo app:

actions/app.go

var app *buffalo.App

// T is used to provide translations
var T *i18n.Translator

// App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
// application.
func App() *buffalo.App {
    if app == nil {
        // [...]

        // Setup and use translations:
        var err error
        if T, err = i18n.New(os.DirFS("locales"), "en"); err != nil {
            app.Stop(err)
        }
        
        app.Use(T.Middleware())
    }
    return app
}

Use i18n.New to create a new instance of the translation module, then add the middleware (T.Middleware()) to the app to enable its features.

See https://gobuffalo.io/docs/localization for further info about Buffalo translation features and configuration.

mw-i18n's People

Contributors

dependabot[bot] avatar fasmat avatar kteb avatar markbates avatar paganotoni avatar sio4 avatar stanislas-m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mw-i18n's Issues

bug: Unit test failure using Go 1.21.0

Description

Description

When running go test with Go 1.21.0, there's a unit test failure.

Expected Behavior

PASS
ok  	github.com/gobuffalo/mw-i18n/v2	0.281s

Actual Behavior

--- FAIL: Test_i18n_Localized_View (0.00s)
    i18n_test.go:165: 
        	Error Trace:	/Users/meta/Go/src/github.com/gobuffalo/mw-i18n/i18n_test.go:165
        	Error:      	Not equal: 
        	            	expected: "Default"
        	            	actual  : "Hello!"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-Default
        	            	+Hello!
        	Test:       	Test_i18n_Localized_View

To Reproduce

Installed via rtx:

rtx install [email protected]
rtx install [email protected]

Test:

rtx use [email protected]
go test # succeeds
rtx use [email protected]
go test # fails

Additional Context

macOS on Apple M2 Max.

vendored go-i18n

why was go-i18n vendored / what changes were made to the package? also, a newly created project using the buffalo setup guide creates a version that does not have go-i18n vendored. When will this be released?

DateTime and currency ?

This looks pretty good.

I guess adding DateTime and Currency would be good.
What is a translated message has DataTime and Currency in it ?
I would expect these are just variables on the call in to standard translation ?

Running `go get -u` breaks

cannot load github.com/nicksnyder/go-i18n/i18n: module github.com/nicksnyder/go-i18n@latest found (v2.0.3+incompatible), but does not contain package github.com/nicksnyder/go-i18n/i18n

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.