question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible to turn off localization?

See original GitHub issue

When I receive data in gatsby-source-contentful the fields are normal…

{
  title: "Example"
}

But when I use rich-text, the fields are nested, like so…

{
  fields {
    title: {
      "en-US": "Example"
    }
  }
}

I have localization turned off, so why am I receiving localized data?

Is there any way to prevent this in rich-text?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
zolkcommented, Apr 2, 2020

This is now a feature in gatsby-source-contentful. You can pass in the following option and the locale nodes will no longer be present in rich text fields.

richText: {
  resolveFieldLocales: true
}
2reactions
vandelay87commented, Feb 4, 2020

Yeah, having the option to turn off location would be ideal. It also wraps props in a ‘fields’ object which isn’t great when rendering components dynamically and spreading the props.

I had to go through the fields recursively and remove them. I could improve this so that instead of cloning the object and then reassigning function parameters it builds the clean fields dynamically, but I’m yet to get round to it.

For anyone looking for a quick solution:

First I destructure the props:

const { fields } = node.data.target;

Then I clean the object by passing the fields to the following function:

const cleanProperties = (dirtyObj) => {
    const cleanObj = JSON.parse(JSON.stringify(dirtyObj));
    const locale = 'en-GB';
  
    const deepObjectLoop = (obj) => {
      Object.keys(obj).forEach(key => {
        if (obj[key] && typeof obj[key][locale] !== 'undefined') {
          const localeValue = obj[key][locale];
  
          delete obj[key][locale];
          obj[key] = localeValue;
        }
  
        if (obj[key] && typeof obj[key].sys !== 'undefined' 
        && typeof obj[key].sys.id !== 'undefined') {
          const idValue = obj[key].sys.id;
  
          delete obj[key].sys;
          obj[key].id = idValue;
        }
  
        if (obj[key] && typeof obj[key].fields !== 'undefined') {
          const localeValue = obj[key].fields;
          const idValue = obj[key].id;
  
          delete obj[key].fields;
          obj[key] = localeValue;
  
          if (idValue !== 'undefined') {
            obj[key].id = idValue;
          }
        }
  
        if (typeof obj[key] === 'object') {
          deepObjectLoop(obj[key]);
        }
      });
    }

    deepObjectLoop(cleanObj);
    return cleanObj;
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn Location Services and GPS on or off on your iPhone ...
How to turn Location Services on or off for specific apps. Go to Settings > Privacy > Location Services. Make sure that Location...
Read more >
How to Disable Location Services on iOS and Android
In your Location settings, tap on App permissions. · Select the app you'd like to exempt from having location access. · Make sure...
Read more >
How to Turn Off Location Services and Stop Your iPhone Apps ...
To turn off location services completely, navigate to Settings > Privacy > Location Services and toggle off Location Services at the top of...
Read more >
How to Limit Location Tracking on Your Phone
In short, go to Settings > Privacy > Location Services. At the top of the screen, there's a toggle switch to turn the...
Read more >
How to turn off Google's location tracking - The Guardian
How to turn off Google's location tracking · Head to settings. · Tap on Google then Google Account · Tap on the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found