Code Monkey home page Code Monkey logo

Comments (7)

nicksnyder avatar nicksnyder commented on May 29, 2024

You are the second person to bring this up so I will think about it some more.

In the meantime, you should be able to just wrap your Tfunc in another function to make the fallback behavior explicit.

Something like this (pseudocode, not tested)

func MyTfunc(pref string, prefs ...string) TranslateFunc {
    t := i18n.MustTfunc(pref, prefs...)
    return func(translationID string, args ...interface{}) string {
        if translated := t(translationID, args...); translated != translationID {
            return translated
        }
        return i18n.MustTfunc("en-US", args...) // assuming en-US is your "default" locale
    }
}

from go-i18n.

krishicks avatar krishicks commented on May 29, 2024

Thanks, I'll give that a shot. I'll report back on any performance penalty I see with that approach.

from go-i18n.

coreyhulen avatar coreyhulen commented on May 29, 2024

We ran into the same problem. A global fallback would be great since something is better than nothing.

from go-i18n.

krishicks avatar krishicks commented on May 29, 2024

@coreyhulen You can see our implementation of @nicksnyder's suggestion above here: https://github.com/cloudfoundry/cli/blob/master/cf/i18n/i18n.go#L59

from go-i18n.

coreyhulen avatar coreyhulen commented on May 29, 2024

thanks @krishicks

from go-i18n.

nicksnyder avatar nicksnyder commented on May 29, 2024

v2 includes a proposal to perform fallbacks on a per-message basis. See #92

from go-i18n.

nicksnyder avatar nicksnyder commented on May 29, 2024

I just tagged 2.0.0.beta.1. Please start using it and report any issues that you have.

from go-i18n.

Related Issues (20)

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.