yelp-fusion icon indicating copy to clipboard operation
yelp-fusion copied to clipboard

Internationalization Support

Open raysarebest opened this issue 6 years ago • 6 comments

Nearly all of Yelp's endpoints support passing a ISO-639 string as a parameter called locale. That way, you can get data that is specific to the country/area that the user is in, in the language that they speak. How would I pass this flag to the Yelp API with this library?

raysarebest avatar Sep 15 '19 05:09 raysarebest

Same as all the other query string parameters. For example:

'use strict';

const yelp = require('yelp-fusion');
const client = yelp.client('YOUR_API_KEY');

client.search({
  term: 'Four Barrel Coffee',
  location: 'san francisco, ca',
  locale:'en_US'
}).then(response => {
  console.log(response.jsonBody.businesses[0].name);
}).catch(e => {
  console.log(e);
});

tonybadguy avatar Sep 16 '19 04:09 tonybadguy

That seems to work for some endpoints and not others. For example, when I run this code:

async (request, response) => {
    const {body: data} = await yelp.allCategories({locale: "sv_SE"});
    console.log(data);
    response.send(data);
};

all the returned data seems to be localized to en_US (English, United States), which is Yelp's default, despite me explicitly specifying sv_SE (Swedish, Sweden). How would I do this for things like allCategories and categoryDetails?

raysarebest avatar Sep 17 '19 02:09 raysarebest

It looks like the full list of functions that the API officially supports it but I wouldn't be sure how to do this would be:

For my particular use case, however, I'm most interested in All Categories and Category Details

raysarebest avatar Sep 17 '19 02:09 raysarebest

oh I see. Some of those functions are missing the parameters object.

tonybadguy avatar Sep 17 '19 03:09 tonybadguy

Try out this branch. Let me know if it works for you: https://github.com/tonybadguy/yelp-fusion/tree/queryparams

Changes: https://github.com/tonybadguy/yelp-fusion/pull/17/files

tonybadguy avatar Sep 17 '19 03:09 tonybadguy

Everything there works for me! I think that's all the endpoints I need for my app, so I'd love to see this released on NPM. I'm gonna leave this issue open so you can close it when that code is merged in, but everything should be good with it now. Thanks so much!

raysarebest avatar Sep 17 '19 05:09 raysarebest