Giter Club home page Giter Club logo

Comments (5)

tricoder42 avatar tricoder42 commented on May 11, 2024 2

Closing for now, as I'm still not convinced about exposing t besides i18n.

I would rather make const { t } = this.props.i18n work, but that requires a bit of design change.

Thank you anyway for suggesting b)!

from js-lingui.

tricoder42 avatar tricoder42 commented on May 11, 2024

Hello,
thank you for your valuable feedback and spending some time with jsLingui.

a) From i18n object you can get a lot more stuff than just t method - active language, info about language (:warning: planned feature) and all formatting methods: t, plural, select, selectOrdinal, number and date. In future the lib should also support custom formatters (e.g. range, relative, etc).

I felt that namespacing all i18n-relevant attributes and methods is better than polluting component namespace. Also, if you're using i18n.t too often, you can always add const { t } = this.props.i18n at the top of your render method.

b) That's actually pretty good idea. I saw few libs with capitalized letters, but looking and some examples (react-router, react-redux) it's clear, that lower cased first letter is more common. It also makes sense - upper case for components, lower case for functions. HOC is basically just factory for component. Would you like to add PR with withI18n while updating WithI18n to log deprecation warning?

from js-lingui.

benbender avatar benbender commented on May 11, 2024

Hey,

I was talking about exposing t() as a shortcut, not about replacing the i18n-object ;)
I'll try to find time for a PR today.

Thanks for your work! 👍

from js-lingui.

tricoder42 avatar tricoder42 commented on May 11, 2024

Hi @benbender,
just the follow up: This problem is a bit more complex.

Babel plugin is looking for t (plural, select, etc.) method bounded to i18n object. It doesn't even check if the i18n object comes from lingui or it's your own variable. I solved similar problem with Trans component in React by checking the imports at the top of file.

In this case I need to figure out, how to check that i18n object actually comes either from WithI18n HOC or react-i18n. Problem is, that Trans component can access context implicitly thanks to React, while in plain JS there's no such thing as context and I have to bind translating methods to i18n object.

TL;DR: My suggested workaround const { t } = this.props.i18n won't work...

from js-lingui.

tricoder42 avatar tricoder42 commented on May 11, 2024

Also, b) is fixed in latest [email protected] release.

from js-lingui.

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.