Git Product home page Git Product logo

Comments (9)

ryandrewjohnson avatar ryandrewjohnson commented on May 13, 2024 3

I'm considering this closed with the release of v3.0.0.

See Handle missing translations in the new docs for details.

from react-localize-redux.

ryandrewjohnson avatar ryandrewjohnson commented on May 13, 2024 1

@MaiGhoneim the missingTranslationCallback is just a function that will trigger when a translation is missing. It does not actually change the value of the missing translation message. You can set showMissingTranslationMsg to false to hide the missing translation message, but there isn’t currently a way to define a custom missing message.

If you want open a new issue and label it feature request, and explain the feature and use case clearly and I'll have a look.

from react-localize-redux.

ryandrewjohnson avatar ryandrewjohnson commented on May 13, 2024

@cranetm I have a few questions to better understand the feature request.

So the way things currently work is as follows:

Let's say you have translation data that doesn't contain a key:

// this key doesn't exist
<h1>{translate('title')}</h1>

// so it will render the following
<h1>Missing localized key: title for language: en</h1>

Now this would occur for one of two reasons:

  1. The translation data for title doesn't exist at all.
  2. The translation data for title exists, but is missing for the current language.

I could add an initialize option that would allow you to set a custom string for missing translation. For example maybe you might want to use an empty string for production, so you'd never get the Missing localized key: message in prod.

Would this cover your use case or are your requirements different?

from react-localize-redux.

cranetm avatar cranetm commented on May 13, 2024

Ok, i will describe detailed.
We do not have title in translation:

<h1>{translate('title')}</h1>

now it renders "Missing localized key..." message if showMissingTranslationMsg is true.
I propose to render result of missingTranslationCallback if its defined. And I can manipulate with it in any way I want:

const missingTranslationCallback = (key: string, languageCode: string) => {
  InternalLog.warn('Missing key "' + key + '" for "' + languageCode '".');
  return key;
  // or transform to more user friendly
  return key.charAt(0).toUpperCase() + key.slice(1);
};

And second is about fallback to default language.
For example, all development doing in english and with a high probability all english translations present. Application has 3 more languages, which will be added in some future by technical writers.
To prevent empty strings or unnecessary messages, even in development stage, it can render translation from english.

Actually you can combine both. Add third params to missingTranslationCallback, called like defaultTranslation: string and this value could be returned and rendered if translation is missing.

Is is clear enough?

from react-localize-redux.

ryandrewjohnson avatar ryandrewjohnson commented on May 13, 2024

@cranetm first off thanks for the suggestions. I've included my feedback below.

The requested changes for missingTranslationCallback seem very specific to your use case. In addition it would introduce breaking changes to the API, which I wouldn't want to make for a change this small.

In terms of the fallback to default language, this is something I'll take a look at. My initial thought is to add a new option to initialize to allow user to opt in to this feature. I will update this issue as things progress on the work, or if you'd like to contribute feel free to submit a PR.

from react-localize-redux.

MaiGhoneim avatar MaiGhoneim commented on May 13, 2024

hi,
missingTranslationCallback did not change missing localization message, i need to change this message how i can do it?

from react-localize-redux.

vevmesteren avatar vevmesteren commented on May 13, 2024

Can one language be set as fall-back. When a translation missing I would want to display the English translation.

from react-localize-redux.

ryandrewjohnson avatar ryandrewjohnson commented on May 13, 2024

@vevmesteren I'm most likely going to table this feature until the next major version release. The reason being that there are already three options dedicated handling missing translations:

  • showMissingTranslationMsg
  • missingTranslationMsg
  • missingTranslationCallback

These options are already the result of squeezing in features, and as much as I'd like to rethink the whole missing translations implementation it would result in breaking changes - hence the waiting for a major version release. I'm targeting a major version release for in and around when React releases their new context API, as there are changes I want to make that are dependent on that.

from react-localize-redux.

vevmesteren avatar vevmesteren commented on May 13, 2024

That'll do I'll figure something out with those.
Thanks

from react-localize-redux.

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.