Skip to content
Compare
Choose a tag to compare
@jcguarinpenaranda jcguarinpenaranda released this 15 Apr 16:43
· 46 commits to master since this release

Prefjs fromObject now accepts an object with extra parameters to configure a custom locale.

Example:

const object2 = {
  description: 'I am a product',
  description_es: 'Yo soy un producto',
  title: 'T-shirt - XL',
  title_es: 'Camiseta - XL'
};

pref.getFromObject(object2, 'title'); // T-shirt - XL
pref.getFromObject(object2, 'description'); // I am a product

// And in spanish
pref.setCurrentLocale('es'); // change to spanish
pref.getFromObject(object2, 'title'); // Camiseta - XL
pref.getFromObject(object2, 'description'); // Yo soy un producto

// Get data in other locale although pref main
// locale is currently set to 'es'
pref.getFromObject(object2, 'description', { customLocale: 'en' }); // I am a product