flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

Explicitly providing locale with content.add() doesn't have any effect. #145

Closed ribalnasr closed 3 years ago

ribalnasr commented 3 years ago

hello,

here's my case: sometimes you want the global locale for the sdk to be 'en-US' but you may need to add (or update) a document in a different locale without having to switch between locals before and after.

the add() method does take a local property but it doesn't do the trick, the new document is still created under the global locale.

dewetvdm commented 3 years ago

Hi @ribalnasr 👋

I will have a look at this asap.

gitdubz commented 3 years ago

@ribalnasr you can update to flamelink@1.0.0-alpha.33

Please let me know if the issue is not resolved.

// create an entry for a different locale
// this will create a placeholder entry in your default locale
const nl_entry = await fl.content.add({
  schemaKey: "sdkTest",
  data: { text: 'entry text' },
  locale: "nl"
});

// create an entry for your default locale 
const entry = await fl.content.add({
  schemaKey: "sdkTest",
  data: { text: 'entry text' },
});

// add an entry in a different locale for the original entry
// you can use content.update here too - it will then just create the entry if it does not exist
const entry2 = await fl.content.add({ 
  schemaKey: "sdkTest",
  entryId: entry._fl_meta_.fl_id,
  data: { text: 'entry text' },
  locale: "nl",
});

// update an entry for a different locale without switching
const entry3 = await fl.content.update({
  schemaKey: "sdkTest",
  entryId: 'someEntryIdHere', 
  data: { text: 'entry text' },
  locale: "nl",
});